boundless-author-7811
03/06/2026, 12:46 PMtall-airline-16756
03/06/2026, 12:46 PMtall-airline-16756
03/06/2026, 12:47 PMdelete_room_on_close=True in room_io.RoomOptions. The room will be deleted automatically when the session ends.
from livekit.agents import room_io
await session.start(
agent=my_agent,
room=ctx.room,
room_options=room_io.RoomOptions(
delete_room_on_close=True
),
)
Using the prebuilt EndCallTool (Python, Beta)
• The EndCallTool can be configured with delete_room=True. When it runs, it sends the final message, shuts down the session, deletes the room, and stops the job.
from livekit.agents.beta.tools import EndCallTool
end_call_tool = EndCallTool(delete_room=True)
# trigger the tool as part of your end-call flow
Manual deletion (Server API)
• Call the LiveKit room delete API to remove the room and disconnect all participants. This works from server-side code (Python or Node).
Python example:
from livekit import api
await ctx.api.room.delete_room(
api.DeleteRoomRequest(room=ctx.job.room.name)
)
Node.js example:
const roomServiceClient = new RoomServiceClient(
process.env.LIVEKIT_URL,
process.env.LIVEKIT_API_KEY,
process.env.LIVEKIT_API_SECRET,
);
await roomServiceClient.deleteRoom(ctx.job.room.name);
Important notes
• Deleting the room ends the call for all participants (including SIP).
• If you don’t delete the room, the call may remain active even after the agent leaves — deleting ensures a clean teardown and stops any ongoing egress/recording.
If you’d like, tell me:
• Which SDK/language you’re using (Python, Node, other).
• Whether you prefer an automatic option or need to trigger deletion from your own end-call event handler.
I’ll give the exact code/snippet and where to hook it into your end-call flow.
Sources: Agent session | LiveKit Documentation | Agents telephony integration | LiveKit Documentation | EndCallTool | LiveKit Documentation | Python Agents: Handling exceptions in your entrypoint | LiveKit | Why is there extra audio at the end of my recordings of an agent session? |...boundless-author-7811
03/06/2026, 12:49 PMtall-airline-16756
03/06/2026, 12:50 PMcontext.session.metadata will persist after you delete a LiveKit room (Python).
Short answer: No — metadata stored on the session/room is ephemeral and will not persist after the room is deleted.
Why:
• Room and participant metadata are tied to the room’s lifetime. Deleting a room via the delete_room API (or via delete_room_on_close / EndCallTool) removes the room and its associated state, which includes session/room/participant metadata and active connections.
• That means any data you keep only in context.session.metadata will be lost when the room is removed.
What you can do instead (recommended):
• Save the data to an external persistent store (database, object store, Redis, etc.) before you delete the room.
• Hook into your shutdown/end-call flow to persist metadata. For example:
a. On end-call event, read context.session.metadata.
b. Write that data to your database or an external API.
c. Then call the room deletion (or allow the automatic delete to proceed).
If you want, tell me:
• What data you’re storing in context.session.metadata and when you want it available after the call.
• Which database or storage you prefer (Postgres, Redis, S3, etc.).
I’ll provide a short Python snippet showing how to persist the metadata to your chosen store and where to call the room deletion.
Sources: Job lifecycle | LiveKit Documentation | Handling asynchronous metadata updates in LiveKit | LiveKit | External data and RAG | LiveKit Documentationboundless-author-7811
03/06/2026, 12:59 PMtall-airline-16756
03/06/2026, 12:59 PMroom.on(...) or session.on(...)), tell me whether you’re using the low-level client SDK or the Agents framework and I’ll return exact names/snippets.
Would you like:
• A Python snippet showing how to listen for room and track events in the client SDK, or
• A Python example for Agent-session event handlers (e.g., user_state_changed, conversation_item_added)?
Tell me which one and I’ll provide the exact code you can drop into your project.
Sources: Rust SDKs | livekit/livekit_composite | DeepWiki | client-sdk-js | livekit/livekit_composite | DeepWiki | Client SDKs | livekit/livekit_composite | DeepWiki | client-sdk-flutter | livekit/livekit_composite | DeepWiki | client-sdk-unity | livekit/livekit_composite | DeepWikiboundless-author-7811
03/06/2026, 1:32 PMtall-airline-16756
03/06/2026, 1:32 PM"reason": "CLIENT_INITIATED" means.
Short answer:
• "CLIENT_INITIATED" is a disconnect reason that indicates the client (the user’s app or browser) intentionally initiated leaving the room. It means the participant called a leave/disconnect action (for example, room.disconnect() or closing the app/tab), not that the server or network forced the disconnect.
When you’ll see it:
• In client callbacks or server webhooks for events like participant/room left, you may see a payload that includes reason: "CLIENT_INITIATED".
• It’s used to distinguish intentional, user-driven disconnects from other causes such as network timeouts, server-side closes, or state mismatch errors.
How it differs from other reasons:
• CLIENT_INITIATED: user/app intentionally left.
• CONNECTION_TIMEOUT: client lost connectivity and timed out.
• STATE_MISMATCH (or server-forced reasons): indicates protocol/state issues or a server-driven disconnect.
If you want, tell me where you saw this field (client logs, webhook, or API response) and I can show an example of the payload and recommend any follow-up handling (e.g., whether to attempt automatic reconnect, persist session data, or show a UX message).
Sources: Server-side | livekit/livekit_composite | DeepWiki | Understanding the STATE_MISMATCH Disconnect Reason | LiveKit