important-judge-78504
09/30/2025, 6:57 PMtall-airline-16756
09/30/2025, 6:57 PMtall-airline-16756
09/30/2025, 6:58 PMcreate_sip_participant with wait_until_answered=True, especially if the request seems to hang without receiving a SIP response. This happens because the request is patiently waiting for the call to be answered, which is expected behavior. To help avoid waiting indefinitely, it's a good idea to set a timeout.
Here are some friendly tips to guide you through this:
• Try setting a ringing_timeout in your request to limit how long the system waits for the call to connect.
• Make sure to explicitly set a client timeout when making the API call to manage the total request time.
• Turning on debug logging can be really helpful—it lets you see detailed error messages and check SIP-specific info like sip_status_code and sip_status.
• Double-check your SIP trunk configuration and confirm that the target phone number is valid and reachable.
• You might also want to use play_dialtone=True to give users some feedback while the call is dialing.
If you'd like, I’m here to help you walk through any of these steps or answer any questions you have. Just let me know!
Sources: Docs::Telephony | agent.py | cmd/lk/sip.go | pkg/service/sip.go | livekit-api/livekit/api/sip_service.pyimportant-judge-78504
09/30/2025, 6:58 PMtall-airline-16756
09/30/2025, 6:59 PMsip_status_code and sip_status in the error metadata to pinpoint what’s causing the failure.
• Try enabling detailed logging to catch any SIP-specific errors and keep an eye on participant events like ringing and active.
• Double-check that your SIP trunk is set up correctly, including the authentication credentials and making sure it’s compatible with LiveKit’s SIP headers.
• Consider adjusting the client-side timeout to match what the server expects (around 80+ seconds) and set a ringingTimeout to control how long the system waits for an answer.
• It might also help to test without wait_until_answered so you can watch the call’s progress asynchronously and better isolate where things might be going wrong.
Please feel free to reach out if you’d like a hand with any of these steps or if anything needs more explanation—I’m here to help!
Sources: agent.py | livekit-rtc/livekit/rtc/participant.py | pkg/service/sip.go | cmd/lk/sip.go | Making outbound calls | LiveKit Docsimportant-judge-78504
09/30/2025, 8:49 PMtall-airline-16756
09/30/2025, 8:49 PMimportant-judge-78504
09/30/2025, 8:51 PMtall-airline-16756
09/30/2025, 8:51 PMctx.shutdown(reason="Session ended") to gently disconnect the agent while keeping the room open for other participants to continue.
• Ending the Session for All Participants: When it’s time to wrap up for everyone, the delete_room API is your go-to. Before doing so, consider using ctx.wait_for_playout() or session.drain() to make sure no audio cuts off abruptly. You might also want to send a warm goodbye message using session.say().
• Graceful Cleanup: It’s a great idea to implement the on_exit method in your agent class. This helps you perform those final touches, like saying goodbye or logging important session details.
• Handling Session Closure Events: Don’t forget to subscribe to the "close" event on AgentSession. This way, you can log or process session history smoothly once the session ends.
• For Egress Recordings: To avoid any unwanted silent audio at the end of your recordings, deleting the room right after the human participant leaves works best.
If you’d like, I’m here to help you implement any of these steps or answer any questions you might have. Just let me know!
Sources: Inside a session | LiveKit Docs | Agents telephony integration | LiveKit Docs | telephony/sip_lifecycle.py | livekit-agents/livekit/agents/voice/agent_activity.pyimportant-judge-78504
09/30/2025, 8:56 PMtall-airline-16756
09/30/2025, 8:57 PMdelete_room, it automatically takes care of triggering the necessary server-side events to clean up the agent session task. So, when a room is deleted, all participants—including agents—are removed from the room. This action triggers the participantLeft() method on the agent job, and the server sends a TerminateJob RPC to stop the agent task.
Also, if you have configurations like delete_room_on_close set to True, the room will be deleted automatically when the agent session closes. Please feel free to reach out if you'd like me to walk you through this process in more detail or if you have any other questions. I'm here to help!
Sources: Job lifecycle | LiveKit Docs | Inside a session | LiveKit Docs | pkg/service/roommanager.go | livekit-agents/livekit/agents/voice/agent_session.py | complex-agents/role-playing/agents/combat_agent.pyimportant-judge-78504
09/30/2025, 8:59 PMtall-airline-16756
09/30/2025, 9:00 PMctx.wait_for_playout() or session.drain() before delete_room isn’t absolutely mandatory, it’s definitely a great habit to get into. These steps help make sure the agent finishes speaking and all messages are fully sent before the room is deleted, so you avoid any sudden audio cutoffs or missed messages.
Here’s a simple way to wrap things up smoothly:
1. Start with await ctx.wait_for_playout() to let the agent finish its speech.
2. If you want, you can then call await session.drain() to make sure all pending actions are handled.
3. Finally, call delete_room to end the session.
If anything’s unclear or you’d like a hand putting this into practice, just let me know—I’m here to help!
Sources: Agents telephony integration | LiveKit Docs | agent.py | tracking_state/npc_character.py | agents/src/voice/agent_session.ts | Agent speech and audio | LiveKit Docsimportant-judge-78504
09/30/2025, 9:00 PMtall-airline-16756
09/30/2025, 9:00 PMctx.wait_for_playout() so the agent can finish speaking without any interruptions.
2. Next, call session.drain() to make sure all pending actions or messages are properly processed and sent.
3. Finally, call delete_room to close the session and clean up everything neatly.
Following these steps will help you wrap things up smoothly and professionally. If you have any questions or want me to walk you through it, just let me know—I’m here to help!important-judge-78504
09/30/2025, 9:01 PMtall-airline-16756
09/30/2025, 9:01 PM