what is the recommended approach for shutting down...
# ask-ai
i
what is the recommended approach for shutting down a call in a hangup tool
t
Thanks for reaching out, Ed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m glad you asked about the best way to shut down a call using the hangup tool! The recommended approach is to use the
delete_room
API. This helps make sure the call ends cleanly for everyone involved, so no one is left in the call hearing silence. Here’s a quick overview of the steps to follow: • Use
await job_ctx.api.room.delete_room(api.DeleteRoomRequest(room=job_ctx.room.name))
inside your hangup function to delete the room and end the call. • Set up a shutdown callback by registering
ctx.add_shutdown_callback(on_shutdown)
to take care of any cleanup when the session finishes. • To wrap things up smoothly, wait for the current speech to finish playing out with
await current_speech.wait_for_playout()
before hanging up. If you’d like, I’m here to help with any part of the implementation or answer any questions you might have. Just let me know! Sources: Agents telephony integration | LiveKit Docs | agent.py | complex-agents/drive-thru/frontend/components/livekit/agent-control-bar/age... | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | How to detect and handle silence during calls
i
what about the ctx.shutdown()?
t
Thanks for reaching out! Could you please help me understand a bit more about the context you're referring to with
ctx.shutdown()
? For instance, is it related to a
JobContext
,
AgentSession
, or something else? Knowing this will really help me guide you better. Sources: Job lifecycle | LiveKit Docs | How to detect and handle silence during calls | Agents telephony integration | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py
i
does the ctx.remote_participants list keep data on participants that disconnected?
t
I wanted to share a little insight about the
ctx.remote_participants
list. It doesn’t keep information on participants who have disconnected. So, when someone leaves, they’re removed from the
remote_participants
collection. This is actually how it works across all LiveKit SDKs — disconnected participants are taken out of the list to make sure it always shows only those who are currently connected. I hope this helps clarify things for you! Sources: src/room/Room.ts | stream_audio.py | livekit/src/room/mod.rs
i
what are the different ways that i can get a twilio_call_sid for a participant
t
To find the
twilio_call_sid
for a participant, you can easily access it through the participant's attributes when using Twilio SIP trunks. LiveKit thoughtfully includes Twilio-specific attributes like
sip.twilio.callSid
in the participant's
attributes
field whenever a call is made via a Twilio SIP trunk. Here’s a simple way to get it: • Check Participant Attributes: Take a look at the
attributes
field of the participant object. If the call is routed through Twilio, you’ll find the
sip.twilio.callSid
attribute there. • Use Server SDKs or APIs: You can also retrieve this value programmatically by listing participants in a room or by listening to participant events like
participant_joined
, then accessing their attributes. • Ensure Proper Trunk Configuration: Just a quick note—the
sip.twilio.callSid
attribute will only be available if you’re using a Twilio SIP trunk and have set it up to forward SIP headers that LiveKit maps into these attributes. If you’d like, I’m here to help with any further questions or even provide examples to make implementation smoother for you. Just let me know! Sources: SIP participant | LiveKit Docs | pkg/sip/participant.go
i
i would like to get twilio call sid for all participants, even ones that disconnected. is using the participant_joined event and getting this attribute at the time of the participant joining the only way to do this?
t
To help you get the
twilio_call_sid
for all participants, including those who have disconnected, a great approach is to capture it right when participant events happen, like
participant_joined
or
participant_disconnected
. When using Twilio SIP trunks, you’ll find the
sip.twilio.callSid
attribute included in the participant’s attributes. Here are some friendly options you can consider: • Capture During Events: Keep an eye on the
participant_joined
or
participant_disconnected
events to grab and save the
twilio_call_sid
for each participant as they come and go. • Server-Side Retrieval: You can also use LiveKit’s server SDKs to list participants in a room and access their attributes, including the
sip.twilio.callSid
. This method works well for participants who are still connected. • Webhook Handlers: Setting up webhook handlers to catch participant events is another solid way to store the
twilio_call_sid
in your database, so you have it handy even after participants disconnect. Using the
participant_joined
event is a really reliable way to make sure you capture the
twilio_call_sid
for everyone. Pairing this with server-side storage or webhooks can give you an even stronger setup for keeping track of disconnected participants. If you’d like, I’m here to help with more details or examples to get you started! Sources: SIP participant | LiveKit Docs | stream_audio.py | livekit/src/room/mod.rs | livekit-protocol/livekit/protocol/sip.pyi | test/lktest/livekit.go
i
does starting an agent egress somehow interfere with the agent "hearing" things? like will the STT be blocked while the agent egress starts?
t
Thank you for your question! I want to reassure you that starting an agent egress won’t affect the agent’s ability to hear or block Speech-to-Text (STT) transcription. The STT functionality works independently from the egress processes, which handle recording or streaming the room content. That said, while egress doesn’t block STT, you might notice some extra audio at the end of recordings if the egress participant stays in the room after the human participant leaves. This is just a recording artifact and doesn’t affect the real-time audio processing or transcription. If you’d like, I’m here to help with any further questions or to guide you through the egress setup. Just let me know! Sources: Speech-to-text (STT) models | LiveKit Docs | examples/src/basic_agent.ts | agent-examples/agent_examples/pipeline_agent.py | Egress examples | LiveKit Docs
i
what im noticing is that during a period of time where i am starting a room egress, a participant egress, and an agent egress (all separately) the agents STT does not transcribe anything
t
It looks like the issue could be connected to the order in which things happen during simultaneous egress processes. I’d be happy to help you with a code snippet or walk you through the steps to coordinate agent session draining, stopping egress, and deleting the room—this way, your STT transcription won’t get interrupted. Just let me know what would be most helpful for you! Sources: agents/src/voice/audio_recognition.ts | Text and transcriptions | LiveKit Docs | livekit-agents/livekit/agents/voice/audio_recognition.py