many-forest-60185
11/04/2025, 12:54 AMtall-airline-16756
11/04/2025, 12:54 AMtall-airline-16756
11/04/2025, 12:54 AMupdate_agent method from the AgentSession class. This handy method lets you reinitialize the current agent or assign a new one, which effectively resets its state during a call.
Here’s a simple way to implement it:
• Using `update_agent`: Just call session.update_agent(session.current_agent) within your agent logic whenever you want to reset the agent. This comes in really handy if you’re dealing with issues like a persistent STT (Speech-to-Text) stream failure.
• Error Recovery Example: If the agent runs into an error it can’t recover from, you can reset it inside an error handler like this: @session.on("error")
def on_error(ev: ErrorEvent):
if isinstance(ev.source, stt.STT):
session.update_agent(session.current_agent) # Reset the agent
ev.error.recoverable = True
• Restart via CLI: If you ever need to restart the agent worker process itself, you can use the LiveKit CLI command: lk agent restart [working-dir] --id <agent-id>
These approaches work great for voice agents managing real-time calls, especially if you’re integrating telephony with SIP. If you have any questions or need further help, feel free to reach out—I’m here to support you every step of the way!
Sources: Workflows | LiveKit Docs | livekit-agents/livekit/agents/voice/agent.py | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki