How do you advise “resetting” an agent on a call?
# ask-ai
m
How do you advise “resetting” an agent on a call?
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you reset an agent on a call in LiveKit! You can do this using the
update_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:
Copy code
@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