how to properly end call from agent?
# ask-ai
b
how to properly end call from agent?
t
Thanks for reaching out, Delivery. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you properly end a call from an agent in LiveKit! Depending on what you'd like to achieve, here are a couple of approaches you can try: • End the Call for Everyone: You can use the
delete_room
API to close the session for all participants. This way, no one will remain in the room. Just a quick tip: before calling this, use
ctx.wait_for_playout()
to let the agent finish speaking smoothly. • Disconnect Only the Agent: If you'd prefer the agent to leave but keep the other participants connected, simply use
ctx.shutdown()
. This will disconnect the agent while the session stays active for everyone else. Please feel free to reach out if you'd like more details or need any help with the implementation. I'm here to support you! Sources: Inside a session | LiveKit Docs | Agent speech and audio | LiveKit Docs | basics/exit_message.py | Agents telephony integration | LiveKit Docs | Job lifecycle | LiveKit Docs
b
how to know if from job context that the room has been closed?
t
To help you determine if a room has been closed from the job context in LiveKit, here are some helpful methods you can try: • Monitor Disconnection Events: You can listen for the
disconnected
event on
ctx.room
. This event includes a
reason
field, such as
ROOM_CLOSED
(when all participants have left) or
ROOM_DELETED
(when the room has been explicitly deleted). • Use Shutdown Callbacks: Another approach is to register a shutdown callback using
ctx.add_shutdown_callback()
. This callback is triggered when the room closes, and you can check the
reason
parameter to understand why. • Programmatically Close the Room: If you decide to close the room using the
deleteRoom
API, please note that all participants, including the agent, will be disconnected with a
ROOM_DELETED
reason. If you'd like, I’m here to provide more details or examples to make this easier for you. Just let me know! Sources: Job lifecycle | LiveKit Docs | pkg/agent/worker.go | Inside a session | LiveKit Docs | protobufs/rpc/agent.proto | Connecting to LiveKit | LiveKit Docs