I'm using an inbound trunk to answer calls with an...
# ask-ai
f
I'm using an inbound trunk to answer calls with an agent. The delete_room function from the RoomService API is not ending the call for the user. How can I have an agent end the call?
t
Thanks for reaching out, Abdullah. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To gracefully end a call for everyone involved, including yourself, you’ll want to use the
delete_room
method from the RoomService API. Just make sure the agent has finished speaking by waiting for
wait_for_playout()
before you call
delete_room
. This way, the session will close smoothly for all participants. If your goal is to disconnect only the agent but keep the user connected, you can simply use
ctx.shutdown()
. And if you need to remove a specific participant, the
remove_participant
API is there for you—just provide the participant’s identity. Please feel free to reach out if you’d like me to walk you through any examples or provide more details on how to use these methods. I’m here to help! Sources: Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs | Agents telephony integration | LiveKit Docs | Agent speech and audio | LiveKit Docs | Job lifecycle | LiveKit Docs
f
It seems that the room gets deleted, but the call on the user's end is not disconnected.
t
When you delete a room, it should disconnect everyone, including yourself. To better assist you, could you please confirm a few things for me? • Are you using the exact room name when calling
delete_room
? • Do the clients receive a
Disconnected
event with the reason
ROOM_DELETED
? • How are you calling the
delete_room
method? For example, are you using the SDK, CLI, or a custom implementation? Knowing these details will really help us get to the bottom of this together. Thanks so much for your patience! Sources: Connecting to LiveKit | LiveKit Docs | Agents telephony integration | LiveKit Docs | livekit-android-test/src/test/java/io/livekit/android/room/RoomMockE2ETest.... | Managing rooms | LiveKit Docs | protobufs/livekit_room.proto
f
Copy code
async def hangup_call():
    """Helper function to delete the room and end the call for all participants"""
    ctx = get_job_context()
    if ctx is None:
        # Not running in a job context
        return
    
    await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
This is defined in my agent class definition and called as part of a tool call.
t
It looks like the
delete_room
function is implemented correctly, which is great! To help us figure out what might be going on, could we check a few things together? • Is the agent running in console mode? Sometimes in this mode,
delete_room
calls are ignored to keep things safe during testing. • Have you had a chance to look at the API response to see if the room deletion went through successfully? • Also, does the room actually exist when the API call is made? Getting a bit more info on these points will really help us pinpoint the root cause. I’m here to help you through this! Sources: Managing rooms | LiveKit Docs | Docs::Home | livekit-agents/livekit/agents/job.py | livekit/livekit_room.pb.go | Connecting to LiveKit | LiveKit Docs
f
What could cause an SIP connection to remain active after the delete room function is called?
t
When the
delete_room
function is called, LiveKit kindly sends internal signaling to disconnect all participants, including SIP connections. However, sometimes an SIP connection might still appear active because of a few reasons: • There could be slight delays in signaling propagation between LiveKit and the SIP trunk provider. • LiveKit uses asynchronous cleanup mechanisms, which might take a moment to complete. • The SIP trunk provider’s way of handling session termination, like sending the SIP BYE message, can also affect timing. LiveKit does update the SIP participant’s status (for example,
sip.callStatus
) to show that the call is disconnected, but external factors such as network latency or trunk configuration might cause a little delay before the SIP call fully ends. Please feel free to reach out if you’d like any more help troubleshooting this — I’m here to support you! Sources: CHANGELOG.md | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | mcp/server.py | agent.py | test/lktest/livekit.go