in livevit agent python sdk, when updating the age...
# ask-ai
c
in livevit agent python sdk, when updating the agent with session.update_agent, is the conversation history maintained or wiped?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! I wanted to share some helpful info about the
session.update_agent()
method in the LiveKit Python SDK. It doesn’t automatically keep or clear the conversation history. By default, the session’s internal
chat_ctx
(which stores the conversation history) stays just as it is. However, the new agent won’t automatically get this context unless you set it up explicitly. If you’d like to keep the conversation history, you can pass the current context to the new agent when you create it, like this:
Copy code
current_ctx = session._chat_ctx
new_agent = MyAgent(chat_ctx=current_ctx)
session.update_agent(new_agent)
And if you want to start fresh and clear the history, just initialize the new agent with a clean context:
Copy code
new_agent = MyAgent(chat_ctx=ChatContext.empty())
session.update_agent(new_agent)
If anything feels unclear or you want me to walk you through this step-by-step, please don’t hesitate to ask. I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Agents v0.x migration guide - Python | LiveKit Docs | complex-agents/personal_shopper/README.md