I have a livekit agent in python that I got from t...
# ask-ai
s
I have a livekit agent in python that I got from the livekit github start kit. Sometimes when I kill and start my agent again, and I fire an SIP call, it looks like my agent is not joining the call because livekit seems to be dispatching it to my previous dead agent. Not sure, but what can I do about it?
t
Thanks for reaching out, aric. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like you're running into an issue where LiveKit might be sending SIP calls to an agent instance that’s no longer active. Let’s work through some steps together to help smooth things out: 1. Set an explicit agent name: Make sure your agent has a unique
agent_name
set within the
WorkerOptions
. This helps avoid any automatic dispatch mix-ups. For example:
Copy code
worker = WorkerOptions(
    worker_name="my-sip-agent",
    agent_name="outbound-caller",
    entrypoint_fnc=entrypoint,
)
2. Match agent name in dispatch rules: Double-check that the
agent_name
in your dispatch rules exactly matches what you’ve defined in your agent code. You can easily manage this via the CLI or API. 3. Run multiple agent instances: To keep things running smoothly during restarts, it’s a great idea to run several instances of your agent all using the same
agent_name
. 4. Implement error handling: Adding error callbacks in your agent will help you catch and respond to any dispatch or connection hiccups quickly. 5. Verify dispatch rules: Before handling calls, use the LiveKit API to confirm that your dispatch rules are set up correctly and active. Following these steps should really help keep your SIP call handling reliable, even when you restart your agent. If you want, I’m here to guide you through any of these steps or answer any questions you might have! Sources: livekit-protocol/livekit/protocol/sip.py | Creating SIP Inbound Trunks and Dispatch Rules with Python SDK | Agents telephony integration | LiveKit Docs | SIP troubleshooting guide | LiveKit Docs | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWiki