A lot of the time when I deploy a new agent, previ...
# ask-ai
a
A lot of the time when I deploy a new agent, previous versions of that agent are the ones that join new rooms. Why is this, and how can I prevent it?
t
Thanks for reaching out, Liam. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand how important it is to have a smooth transition when deploying new agents. With LiveKit's rolling deployment strategy, previous versions of agents might still join new rooms because old agent instances stay active for up to 1 hour to finish their current sessions. However, they shouldn’t join new rooms unless automatic dispatch is turned on. To help you avoid this, here are a couple of friendly tips: • Disable Automatic Dispatch: By setting an
agent_name
in your
WorkerOptions
, you can make sure agents won’t be automatically assigned to rooms unless you specifically ask for it. • Use Explicit Dispatch: You can take control over which agent version joins a room by using the
AgentDispatchService
API or by including the agent configuration in participant access tokens. Following these steps will help ensure that only the latest agent version is assigned to new rooms. If you’d like, I’m here to provide more details or even some code examples to make this easier for you. Just let me know! Sources: examples/agent_dispatch.py | pkg/loadtester/agentloadtester.go | Agent dispatch | LiveKit Docs | Deploying to production | LiveKit Docs | examples/agent-dispatch/index.ts
a
I'm connecting via SIP, so I'm not sure I have explicit controls to do this
t
When working with SIP connections, you have the ability to control agent dispatch more precisely to make sure that only the right agent version joins the rooms. Let me walk you through the steps: 1. Enable Explicit Dispatch: By setting an
agent_name
in your
WorkerOptions
, you can turn off automatic dispatch. This way, agents will only be assigned to rooms when you specifically request it. 2. Configure SIP Dispatch Rules: You can set up SIP dispatch rules to decide how agents get assigned to rooms for inbound calls. For instance, you might create separate rooms for each caller or send all calls to a particular room. 3. Use Runtime Dispatch: With the
AgentDispatchService
API, you can dispatch agents to rooms programmatically, giving you flexible control depending on the call situation. If you’d like, I’m happy to provide detailed examples or help you further with setting these up. Just let me know! Sources: Agents telephony integration | LiveKit Docs | Agent dispatch | LiveKit Docs | SIP dispatch rule | LiveKit Docs | livekit-api/livekit/api/agent_dispatch_service.py | packages/livekit-server-sdk/src/AgentDispatchClient.ts
a
I only have one agent configured, so it's not an issue of configuring despatch rules to say which agent is. I would assume that for new calls, it just uses the newest version, so loading the old versions or do I have to wait a bit for that version to spin down, and then it will only use the new version?
t
When you deploy a new agent version, LiveKit uses a rolling deployment strategy. This means the old agent instances stay active for up to 1 hour to gracefully finish any ongoing sessions. During this period, both the old and new versions might handle new calls if automatic dispatch is turned on. If you'd like to make sure only the new version is used right away, here are a couple of helpful steps: • Disable Automatic Dispatch: Simply set an
agent_name
in your
WorkerOptions
. This will stop the old versions from being automatically assigned to new calls. • Explicitly Dispatch the New Version: You can use the
AgentDispatchService
API to directly assign the new version to rooms or calls. If you don’t disable automatic dispatch, you might need to wait until the old version spins down before only the new one is used. Please feel free to reach out if you want me to walk you through these steps or if you have any other questions—I’m here to help!
a
But won't the same agent's name be used despite the version? So, why would this fix the issue?
t
You're absolutely right that if the same
agent_name
is used across versions, both the old and new instances might still be dispatched during the rolling deployment period. To help you through this, the key is to make sure only the new version is explicitly dispatched for handling new calls. Here’s a friendly guide on how to tackle this: • Use Unique Agent Names for Each Version: Try assigning a unique
agent_name
to the new version (for example,
agent-v2
). This way, only the new version will be dispatched when you specifically request it. • Explicitly Dispatch the New Version: You can use the
AgentDispatchService
API or SIP dispatch rules to target the new version by its unique
agent_name
. • Wait for Old Instances to Spin Down: If unique names aren’t an option right now, just keep in mind that the old instances will take about an hour to shut down, after which only the new version will be active. Please feel free to reach out if you’d like any more help or guidance with implementing these changes—I’m here to support you!