When running a Voice Agent with Livekit what happe...
# ask-ai
h
When running a Voice Agent with Livekit what happens when a call enters a room via SIP and there are not agents online however while the call is in the room an agent comes online - Will the Agent join the room and answer the call?
t
Thanks for reaching out, Cameron. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking what happens when a SIP caller enters a LiveKit room while no agents are online, and whether an agent who comes online later will join and answer that existing call. If no agent is online when the SIP call creates/enters the room, LiveKit will not retroactively dispatch or automatically add newly started agents to that existing room. Agent dispatch happens at the time of the event (room creation or explicit dispatch). A later-started agent will only join if an explicit mechanism triggers dispatch after they become available (for example, an external system re-triggers a dispatch or the agent server polls and accepts a job). Otherwise the caller remains in the room until they hang up or an agent is explicitly sent to that room. If you want callers to always be answered when agents come up, you can: • Keep at least one agent instance continuously registered, or • Use explicit dispatch logic in your infrastructure that retries or re-queues jobs when agents become available. Would you like guidance on implementing retry/re-queue dispatch logic or on configuring named/explicit dispatch rules? Sources: Agents telephony integration | LiveKit docs | Agent dispatch | LiveKit docs
h
Regarding "Use explicit dispatch logic in your infrastructure that retries or re-queues jobs when agents become available" How would this be configured so that in the event there was no agents online and then their access is restored to Live-Kit that any pending rooms would be attended too? Secondly, If no agents are free what configuration could be put in place so that Livekit terminates the room or does not create the room in the first place?
t
You're asking two things: (1) how to configure retry/re-queue dispatch so pending SIP rooms get attended when agents come back online, and (2) how to prevent or terminate rooms when no agents are free. Below are concise, actionable patterns you can implement in your infrastructure using LiveKit APIs/webhooks and agent status checks. 1) Retry / re-queue dispatch so pending rooms get attended • Capture failed dispatch attempts: ◦ When you attempt to dispatch an agent (AgentDispatch API) and no agent accepts, record the dispatch job (room id, caller identity, timestamp, desired agent or agent pool) in your own queue/store. • Detect agent availability: ◦ Poll agent status (CLI/API) or subscribe to agent lifecycle events in your infra. ◦ Optionally use webhooks you control to receive room events (e.g.,
room_started
,
participant_joined
) and agent-status events from your agent manager. • Retry logic: ◦ When an agent transitions to Running/Available, re-attempt dispatch from your queued jobs with exponential backoff and a retry limit. ◦ On successful dispatch, mark job complete; on persistent failure, escalate or run fallback (voicemail, callback). • Implementation tips: ◦ Use idempotent dispatch requests (include job id) so retries are safe. ◦ Limit total retry window (e.g., 5–15 minutes) to avoid holding callers indefinitely. ◦ Optionally notify caller (hold music/message) while waiting for agent. • Pattern summary: ◦ Attempt dispatch → if fail, enqueue job → monitor agent availability → on available, dequeue & retry dispatch. 2) Prevent room creation or terminate rooms when no agents are free Two approaches depending on whether you want to prevent or allow creation then close: A. Prevent room creation upstream (recommended to avoid callers entering unattended rooms) • Gate token/room creation on agent availability: ◦ Before creating/joining a room for an inbound SIP call, check agent pool status via your agent health API. ◦ Only issue the join token or initiate SIP bridge if an agent is available. • Behavior: If none available, return busy/queued flow to the caller (e.g., IVR message, retry menu). B. Allow creation but immediately remove/terminate when no agents available • On
room_started
or
participant_joined
webhook: ◦ Check agent availability. ◦ If no agents free, call RoomService APIs to remove the SIP participant or delete the room: ▪︎ remove participant (disconnect caller) or delete room entirely. ◦ Optionally return a SIP busy/voicemail flow before disconnecting. • Behavior: Room exists briefly but is closed programmatically if unattended. C. Auto-terminate on agent capacity exhaustion • If agents exist but are all busy, use the same webhook check and: ◦ Decide a policy: queue job in your infra, play hold music, or disconnect immediately. ◦ Use room deletion or participant removal APIs to enforce immediate termination when desired. 3) Practical recommendations & safeguards • Maintain at least one standby agent or multi-worker agents per
agent_name
to reduce missed calls. • Keep server-side job queue for pending dispatches and a clear retry/timeout policy. • Use webhooks for event-driven handling rather than only polling where possible. • Provide caller-side UX (hold message, estimated wait, voicemail) while retries occur. • Ensure your re-dispatch logic is idempotent and respects caller timeouts. If you’d like, I can: • Provide a short sample retry flow (pseudo-code) for your stack (Node/Python). • Outline exact API calls (RoomService / AgentDispatch) to use in each step. Which would help more? Sources: Agent dispatch | LiveKit docs | Agent deployment CLI reference | LiveKit docs | Server-side | livekit/livekit_composite | DeepWiki | Webhooks | LiveKit docs | Agents Framework | livekit/livekit_composite | DeepWiki