hallowed-mouse-36162
12/08/2025, 3:57 AMtall-airline-16756
12/08/2025, 3:57 AMtall-airline-16756
12/08/2025, 3:57 AMhallowed-mouse-36162
12/08/2025, 4:02 AMtall-airline-16756
12/08/2025, 4:03 AMroom_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