Is there a way to set a room to be instantly destr...
# agents
i
Is there a way to set a room to be instantly destroyed when empty (not wait 30 seconds or whatever)? For example, when generating the token for joining a room? @refined-appointment-81829 @lively-winter-88668 or anyone?
l
You can set the
departure_timeout
for the room: https://docs.livekit.io/reference/python/v1/livekit/rtc/index.html#livekit.rtc.Room.departure_timeout during room creation
i
Thank you @lively-winter-88668. The issue is that I'm using the LiveKit Agents Framework mainly as a backend for application logic for a chat room application. I'm not explicitly setting AgentSession but an agent is dispatched upon room creation, and of course that agent needs to stay connected to the room or much of the functionality will be lost. The agent is dispatched upon room creation (which happens when first user joins a room), and then when the room becomes empty, the agent will automatically disconnect (and will do so before the room is automatically destroyed). I know I could try to set the agent to stay connected for a long period (and hence the room would not be destroyed) but since we have dynamically created (user-created) rooms perhaps the better way is instant room destruction when room is empty (so agent is dispatched again upon next room join/creation). So, do you think this will be the right approach (setting departure_timeout=0)? And I assume I can do that in the token generator as well as in the livekit api for creating a room. @lively-winter-88668
l
Sorry, I'm not quite following why you need to destroy the room immediately, what is your use case? I would expect a new room to be created, with a new ID, for each dispatch.
i
Sorry if it wasn't clear. We have static rooms (being used as group chat rooms); room name/id is always the same, for example, we have a "Lobby" room. When a user logs in to our app, a token is generated for room Lobby. (Likewise when a user changes to another static room in the rooms list, a token will be generated for that room name.) There can be many users in one room, entering and exiting at any time. If ever a room becomes empty, then the agent will disconnect very soon, and then soon after that the room is destroyed. The problem is that short window of time between the agent leaving the room, and the room being automatically destroyed. During that short window of time, if another user joins the now empty room that the agent already disconnected from, the agent will not be dispatched again to that room, and all the backend functionality is lost. Hope that makes sense. So I thought if the room gets destroyed immediately when the room is empty, then we eliminate that window of time for that edge case where the agent leaves the room before room destruction. Make sense now @lively-winter-88668? Your input welcome.
l
Thanks, is clear, but I'm not sure of the right answer. @refined-appointment-81829 was dealing with a similar lobby use case the other day and I hope can provide some insight to the right approach.
👍 1