some-breakfast-27057
09/28/2025, 10:57 AMtall-airline-16756
09/28/2025, 10:57 AMtall-airline-16756
09/28/2025, 10:57 AMsome-breakfast-27057
09/28/2025, 10:59 AMtall-airline-16756
09/28/2025, 11:00 AMmax_session_duration parameter is a great tool to automatically reset the session by disconnecting and reconnecting the WebSocket connection after a set duration. This effectively clears the model's context and ensures isolation. For example:
from livekit.plugins.openai import realtime
model = realtime.RealtimeModel(
voice="alloy",
max_session_duration=1200 # Reset every 20 minutes
)
session = AgentSession(llm=model)
• If you need to reset the context immediately, the SDK doesn't offer a direct method to do this without creating a new connection. The best approach is to create a new AgentSession instance, like this:
# For immediate reset, create a new AgentSession
new_session = AgentSession(llm=new_model_instance)
I hope this clarifies how to manage session resets! Please feel free to reach out if you'd like me to walk you through any part of this or if you have more questions—I'm here to help.
Sources: examples/voice_agents/realtime_load_chat_history.pysome-breakfast-27057
09/28/2025, 11:04 AMtall-airline-16756
09/28/2025, 11:05 AM