wooden-librarian-60399
08/22/2025, 8:05 PMtall-airline-16756
08/22/2025, 8:05 PMtall-airline-16756
08/22/2025, 8:06 PMupdate_agent in an AgentSession, how the conversation context behaves really depends on how the new agent is set up:
• Default Behavior: Usually, the new agent starts fresh without any previous conversation history—unless you’ve set it up to do otherwise.
• Preserving Context: If you want to keep the conversation going smoothly, you can pass the current chat context to the new agent when you create it, like this:
# Pass the chat context during handoff
new_agent = HelpfulAssistant(chat_ctx=session.chat_ctx)
session.update_agent(new_agent)
About adding new agent instructions as system messages:
• These instructions get turned into system messages with a special ID and are placed right at the start of the chat context.
• If there’s already an instruction message, it gets updated; if not, a new one is added.
And don’t worry—the full session history is always stored in session.history, even if each agent only sees part of the context. If you want me to walk you through this or help with the setup, just let me know—I’m here to help!
Sources: Workflows | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py