Skip to content

LIVE BIDI streaming, Agent's instructions are not getting updated even if I do dynamic update via hot-reload #4450

@ravi-incred

Description

@ravi-incred

Describe the Bug:
When I update my system instructions dynamically at run time via hot-reload functionality I implemented. Agent is not responding with the new instructions. Seems like it have cached the previous instructions.

So when I start a new agent session, I expect that Agent will respond me with that updated instructions. But it is not doing that. Once or twice I saw that it responded correctly. But again when I asked something which was not mentioned in current instructions, but was from the previous, Agent clearly remembered those steps from previous instructions.

If this is caching problem then is there way to clear the cache? whenever I start new Agent session ?
Has anyone faced this kind of issue?
My goal is simple - I want to update the instructions from my dashboard so that I don't have to restart the application every time I make a single change in my prompt

def create_voice_agent() -> Agent:
    """
    Factory function to create agent instance with dynamic configuration.
    
    This function is called each time a new chat session starts, ensuring
    that the agent uses the latest configuration from Config Manager.
    """
    master_prompt = config_manager.get(
        "config.vbConfig.masterPrompt",
        DEFAULT_INSTRUCTION
    )
    model_name = config_manager.get(
        "config.vbConfig.model",
        DEFAULT_MODEL
    )
    tools = get_tools_from_config()
    
    # Create and return Agent with dynamic config
    return Agent(
        name="voice_agent",
        model=model_name,
        description="Agent to assist with Incred Quries.",
        instruction=master_prompt,
        tools=tools,
    )

on conversation end and socket disconnection I am also deleting the sessions from session_service.

session_service = InMemorySessionService()
...
...
async def delete_agent_session(user_id: str):
    session_list = await session_service.list_sessions(app_name=APP_NAME, user_id=user_id)
    for session in session_list.sessions:
        await session_service.delete_session(app_name=APP_NAME, user_id=user_id, session_id=session.id)
    print(f"Deleted Agent Session: {session.id}")

And this is code for starting agent session

...
...
    adk_session = await session_service.create_session(
        app_name=APP_NAME,
        user_id=psid,
        session_id=chat_session.get('_id'),
        state=initial_state
    )

    dynamic_incred_agent = create_voice_agent()

    runner = Runner(
        app_name=APP_NAME,
        agent=dynamic_incred_agent,
        session_service=session_service,
    )
  ...
  ...
    speech_config = types.SpeechConfig(
        voice_config=types.VoiceConfig(
            prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name=VOICE_NAME)
        ),
        # language_code=LANGUAGE_CODE,
    )

    config = {
        "response_modalities": [modality],
        "speech_config": speech_config,
    }

    if is_audio:
        config["output_audio_transcription"] = {}
        config["input_audio_transcription"] = {}

    run_config = RunConfig(**config)
    live_request_queue = LiveRequestQueue()

    live_events = runner.run_live(
        session=adk_session,
        live_request_queue=live_request_queue,
        run_config=run_config,
    )
....

Metadata

Metadata

Assignees

No one assigned

    Labels

    live[Component] This issue is related to live, voice and video chat

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions