witty-yak-62929
02/16/2026, 9:25 AMtall-airline-16756
02/16/2026, 9:25 AMtall-airline-16756
02/16/2026, 9:25 AMdelete_room API to end the session for all participants. Deleting the room also prevents lingering recordings or extra audio at the end.
Example approaches
1. Server-side call teardown (recommended)
◦ Call the delete_room API for the active room when the agent finishes the call.
◦ Example in Python:
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
1. Agent-initiated hangup
◦ If you want the agent UI/button to end the entire call, have the agent trigger a server endpoint that runs the delete_room call (example hangup_call function that deletes the room).
Quick questions to narrow this down
• Are you currently calling delete_room (or equivalent) when the agent disconnects?
• How is the agent currently disconnecting (clicking a UI hangup, network drop, programmatic disconnect)?
• Are you seeing any error logs when you attempt to delete the room or when the agent disconnects?
• Is your SIP integration using LiveKit’s telephony agent flow or a custom setup?
If you tell me how the agent is disconnecting and whether you already call delete_room, I’ll give the exact code pattern and placement recommendations for your setup.
Sources: Agents telephony integration | LiveKit Documentation | Why is there extra audio at the end of my recordings of an agent session? |...witty-yak-62929
02/16/2026, 4:18 PMtall-airline-16756
02/16/2026, 4:19 PMsession.shutdown(drain=False) — that’s exactly why the SIP session stays active.
Brief answer
• session.shutdown(drain=False) only disconnects the agent from the room; it does not end the room or send the SIP BYE. Because the room remains, the SIP participant (caller) stays connected and hears silence.
• To fully terminate the call for everyone, delete the room (use the delete_room API) or enable automatic room deletion on session close.
What you can do now
1. Server-side: after shutting down the agent session, call delete_room for that room.
◦ Python example:
await session.aclose() # or session.shutdown()
await api_client.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
• Node.js example:
await ctx.aclose(); // or ctx.shutdown()
await roomService.deleteRoom(ctx.job.room.name);
1. Agent-initiated hangup: have the agent UI call a server endpoint that runs the delete_room call so the agent can end the entire call from the UI.
2. Automatic option: set delete_room_on_close=True in your RoomOptions so closing the session will delete the room automatically.
Recommended approach
• Use delete_room as part of your normal call teardown (either triggered server-side when the agent ends or via an agent-triggered endpoint). This triggers the SIP BYE and removes all participants and any egress bots, preventing lingering recordings or extra audio.
A couple of quick questions to make the guidance specific to your setup
• Do you want the agent’s disconnect action to end the call for everyone, or do you need the call to persist for other participants in some cases?
• How is the agent currently disconnecting in production — a UI hangup button, a forced shutdown, or a network drop?
• Are you able to add the delete_room call to your current teardown flow, or would you prefer to use delete_room_on_close?
Tell me which option you prefer and how your agent currently disconnects, and I’ll give exact code placement and error-handling recommendations for your setup.
Sources: Job lifecycle | LiveKit Documentation | Agents telephony integration | LiveKit Documentation | Agent session | LiveKit Documentation | SIP Lifecycle Management Agent | LiveKit Documentation | Survey Calling Agent | LiveKit Documentationwitty-yak-62929
02/16/2026, 4:21 PMtall-airline-16756
02/16/2026, 4:21 PMsession.shutdown(drain=False) only disconnects the agent from the room; it does NOT end the SIP call for the caller.
• To make the agent hang up the call for everyone, delete the room (use the delete_room API) when the agent ends the session. That will trigger a SIP BYE and disconnect the caller.
Two ways to implement this
• Recommended (explicit delete on hangup)
a. Have the agent UI trigger a server endpoint when the agent clicks Hang Up.
b. That endpoint calls the RoomService delete_room API for the active room.
Example — Python:
await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
Example — Node.js:
await roomServiceClient.deleteRoom(ctx.job.room.name);
• Convenience (auto-delete on session close) — Python only
◦ Set delete_room_on_close=True on the agent session or RoomOptions. When the session closes, LiveKit will delete the room automatically.
Which to use
• If you want the agent’s Hang Up button to end the call immediately, use the explicit delete_room call from your server endpoint.
• If you prefer automatic behavior when the agent session ends, set delete_room_on_close=True (Python).
Quick follow-ups to finalize the exact code for your flow
• Do you want the Hang Up initiated from the agent UI (button) or should it happen automatically when the agent session closes?
• Are you using the Python agent SDK or Node.js for your server-side logic?
• Do you currently have any server-side teardown code that runs when an agent disconnects? If so, where would you add the delete_room call?
Tell me your preferred hangup flow and which language/sdk you’re using and I’ll provide the exact endpoint placement and error-handling pattern to use.
Sources: How to do call transfers with Five9 | LiveKit | Agent session | LiveKit Documentation | Agents telephony integration | LiveKit Documentationwitty-yak-62929
02/17/2026, 12:44 AMtall-airline-16756
02/17/2026, 12:44 AMdelete_room_on_close=True. When the session ends, LiveKit will delete the room and that triggers the SIP BYE to disconnect the caller.
• If you prefer an explicit server-side delete, call delete_room after closing the session.
Option A — Automatic (recommended for your request)
• Use delete_room_on_close=True when creating the AgentSession or RoomOptions. The room will be deleted automatically when the agent session is closed.
Example (AgentSession with automatic room deletion)
from livekit_agent import AgentSession
session = AgentSession(
# ... other required options ...
delete_room_on_close=True
)
# When you're done with the session
await session.aclose() # closing the session will delete the room automatically
Or if you configure RoomOptions:
from livekit_agent import RoomOptions, AgentSession
room_options = RoomOptions(delete_room_on_close=True)
session = AgentSession(room_options=room_options, ...)
await session.aclose() # room will be deleted on close
Option B — Explicit delete after session close
• If you want to be explicit in your teardown (good for logging or handling errors), first close the session, then call the RoomService delete_room API.
Example (explicit delete)
from livekit import api
import os
# 1) Close the agent session
await session.aclose() # or session.shutdown()
# 2) Call the RoomService delete_room API
api_client = api.LiveKitAPI(
os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET"),
)
await api_client.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
Notes and best practices
• Automatic deletion (delete_room_on_close=True) is simplest and ensures the SIP BYE is sent when the agent session ends.
• Use the explicit delete_room call if you want to:
◦ Perform custom logging or metrics around hangups.
◦ Retry the delete on failure or handle transient errors differently.
• Ensure your agent teardown always runs (for example, in finally blocks or cleanup handlers) so the room gets deleted even on unexpected errors.
• If you rely on session close from network drops, consider a short watchdog or timeout that deletes the room if the agent does not reconnect within your expected window.
Would you like:
• A full minimal runnable example with the AgentSession lifecycle and error handling?
• Guidance on where to place this in your existing code (e.g., in your hangup handler or cleanup routines)?