gifted-magazine-79240
10/23/2025, 8:12 AMtall-airline-16756
10/23/2025, 8:13 AMtall-airline-16756
10/23/2025, 8:14 AM# Create an empty chat context
empty_chat_ctx = llm.ChatContext.empty()
# Update the session's chat context directly
await session.update_chat_ctx(empty_chat_ctx)
• Session Replacement: For a more thorough reset, you might want to end the current session and start a new one with an empty context. Here's how you can do it:
# End the current session
async def end_session(self):
if self.current_agent is None or self.current_model is None:
return
await utils.aio.gracefully_cancel(self.current_model.sessions[0]._main_atask)
self.current_agent = None
self.current_model = None
# Replace with a new session
async def replace_session(self, ctx, participant, agent, model):
await self.end_session()
self.current_agent = agent
self.current_model = model
agent.start(ctx.room, participant)
• Agent Session Shutdown and Restart: Another way is to shut down the current session and start a new one with an empty context, like so:
# Shutdown the current session
session.shutdown()
# Create a new session with empty context
new_session = AgentSession()
empty_chat_ctx = llm.ChatContext.empty()
agent = Agent(instructions="Your instructions here", llm=your_llm_model, chat_ctx=empty_chat_ctx)
await new_session.start(agent=agent, room=ctx.room)
For the easiest and quickest option, I recommend trying the first method if your model supports it. And of course, feel free to reach out if you'd like me to walk you through any of these steps or if you have any other questions. I'm here to help!
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Workflows | LiveKit Docs | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | agent/main.py