clean-dream-46909
11/21/2025, 4:08 AM.chat_ctx in Agent, and a ._chat_ctx in AgentSession , but they're not always in sync. Which one is the one that the AgentActivity actually uses?tall-airline-16756
11/21/2025, 4:08 AMtall-airline-16756
11/21/2025, 4:09 AM.chat_ctx — the agent's template: initial instructions and baseline conversation context used to configure new sessions.
• AgentSession ._chat_ctx — the active runtime context: initialized from the agent's chat_ctx when a session starts and then updated during the conversation.
AgentActivity uses the session's ._chat_ctx (the live context). AgentActivity adds user/assistant messages, handles tool calls, and mutates the session context as the conversation progresses, so it can diverge from the agent's original .chat_ctx.
If you want the session to start with updated agent instructions, do you intend to (a) update the agent's .chat_ctx before starting sessions, or (b) patch the session ._chat_ctx at runtime? Tell me which workflow you need and I’ll give exact steps.
Sources: Python Agents Core Architecture | livekit/livekit_composite | DeepWiki | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...clean-dream-46909
11/21/2025, 4:11 AMtask = self._create_speech_task(
self._pipeline_reply_task(
speech_handle=handle,
chat_ctx=chat_ctx or self._agent._chat_ctx,
https://github.com/livekit/agents/blob/4f2c531bf4eb62c30cdac05638104d6b2eaced5e/livekit-agents/livekit/agents/voice/agent_activity.py#L898C1-L901C64tall-airline-16756
11/21/2025, 4:12 AM.chat_ctx (aka self._agent._chat_ctx) is used by AgentActivity as the default runtime context when no explicit chat_ctx is passed (the chat_ctx or self._agent._chat_ctx branch you cited).
• AgentSession ._chat_ctx is a session-level copy/state that may diverge unless explicitly synchronized.
What you can do depending on your goal:
• If you need AgentActivity to use a different context for a reply, pass that chat_ctx explicitly into the pipeline call.
• If you want session and agent contexts kept in sync, update the agent’s chat_ctx (via update_chat_ctx() or the appropriate agent API) when session changes occur so AgentActivity picks up the updated state.
Do you want exact code pointers for (A) passing an explicit chat_ctx into the reply pipeline or (B) a recommended place to call update_chat_ctx() so agent and session stay synchronized?
Sources: Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...