How to make sure that room is automatically closed...
# ask-ai
f
How to make sure that room is automatically closed/ deleted when only 1 SIP participant is left. 1. agent joins 2. participant 1 joins 3. agent add participant 2 4. agent leaves 5. participant 2 leaves 6. room should close / delete, but it stays with participant 1
t
Thanks for reaching out, Dmitry. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're right to expect the room to close — here's how to make that happen automatically. What I'm responding to: you want the room deleted when only one SIP participant remains after agents/other participants leave. What to do • Listen for participant leave events (e.g.,
participant_left
/
participantLeft
). • On each leave, fetch the current participant list. • If exactly one participant remains and their
kind
is
SIP
, call the Room Delete API (
delete_room
/
deleteRoom
). Implementation notes (concise examples) • Python: after connecting your agent, subscribe to
participant_left
, call
ctx.room.list_participants()
, check
len(participants) == 1
and
participant.kind == livekit.ParticipantInfo.Kind.KIND_SIP
, then call
api.LiveKitAPI(...).room.delete_room(...)
. • Node.js/TS: subscribe to
participantLeft
, call
ctx.room.listParticipants()
, check
participants.length === 1 && participants[0].kind === 'SIP'
, then call
RoomServiceClient.deleteRoom(roomName)
. Why this is needed • LiveKit does not automatically close rooms when a single SIP participant remains; SIP (and agent/service) participants are treated as long-lived. Explicitly deleting the room ensures it’s removed when your business logic requires it. If you want, I can: • Provide a ready-to-run code snippet for your stack (Node or Python). • Recommend where to place this logic (agent entrypoint / server-side webhook). Sources: Agent server | LiveKit docs | Managing rooms | LiveKit docs