Hi, I’m running into an issue I can’t explain. I h...
# ask-ai
h
Hi, I’m running into an issue I can’t explain. I have a LiveKit room that includes an AI agent. After the agent joins, other participants enter the room. Later, I remove the agent, but a second or two after that, the entire room is deleted automatically — even though I never call
DELETE_ROOM
. Does anyone know why the room might be deleted right after the agent disconnects, especially while other participants are still in it?
t
Thanks for reaching out, Ivan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like the issue you're facing might be because the AI agent is set up with the
delete_room_on_close=True
option. When this is turned on, the room gets automatically deleted through the
deleteRoom
API as soon as the agent session ends, even if there are still other participants in the room. To help avoid this, you can make sure that
delete_room_on_close
is set to
False
in the
RoomInputOptions
when you start the agent session. This way, the agent can disconnect without deleting the room, so it stays available for everyone else who’s still there. Sources: livekit-agents/livekit/agents/job.py | Managing rooms | LiveKit docs | Connecting to LiveKit | LiveKit docs
h
Why this happens on rooms with a duration of around 1-3 minutes, but not with more longer rooms?
t
I'd love to understand more about what you're experiencing with the shorter rooms (1-3 minutes) compared to the longer ones. Could you share a bit more about: • Are these rooms managed by LiveKit Agents? • Is the behavior you're seeing related to things like automated teardown, room recreation, or webhook emission? • Are you reusing room names quickly one after another? Getting these details will really help us pinpoint any timing-related factors or patterns that might be causing the difference. I'm here to help you through this! Sources: livekit-agents/livekit/agents/voice/room_io/room_io.py | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name
h
The rooms are created using dispatch rules, and later the agent joins the room. The deletion of the rooms are not clear, not request is made on our systems to delete the room, however its deleted after the agent drop and the other participants are kicked out.
t
It sounds like the behavior you're seeing is connected to how dispatch rules work alongside the
delete_room_on_close
setting. When rooms are created through dispatch rules, agents might be deployed with certain configurations. If an agent has
delete_room_on_close=True
, the room will be deleted as soon as that agent disconnects, even if others are still in the room. To help avoid this, you can make sure the agent’s
RoomInputOptions
explicitly sets
delete_room_on_close=False
. This way, the room will stay open after the agent leaves, so other participants won’t be affected. If you’re still experiencing issues after this, could you please let me know whether the dispatch rules are creating a new room for each session or if they’re reusing a shared room? That info will really help us dig deeper and find the best solution for you. Sources: livekit-api/livekit/api/agent_dispatch_service.py | pkg/service/agent_dispatch_service.go | examples/voice_agents/session_close_callback.py | SIP Integration & Telephony | livekit/livekit_composite | DeepWiki | SIP dispatch rule | LiveKit Docs
h
How I can configure the delete_room_on_close on the dispatch rule?
t
Thanks for reaching out! I noticed that the knowledge base doesn’t clearly explain how to configure
delete_room_on_close
directly within dispatch rules. To help you better, could you please clarify a few things for me? • Are you working with LiveKit Cloud or a self-hosted setup? • Would you like to control room deletion when a SIP participant leaves, or only when all participants have left? • Is this setting something you want to include as part of a room preset or a room configuration linked to the dispatch rule? Getting these details will really help me guide you to the best solution for your setup. Looking forward to your reply! Sources: SIP dispatch rule | LiveKit Docs | livekit-protocol/src/livekit.rs | packages/livekit-server-sdk/src/SipClient.ts | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name | Development Tools & Resources | livekit/livekit_composite | DeepWiki
h
I'm working with LiveKit Cloud. I want to delete the room only if all the participants left.
t
Hi there! To make sure LiveKit Cloud deletes a room only after all participants have left, you can use the
departure_timeout
parameter. Just set
departure_timeout
to
0
when you're creating or updating the room configuration. This way, the room will be deleted right after the last participant leaves—pretty handy, right? For example, if you're using the
CreateRoom
API, you can do it like this:
Copy code
CreateRoomRequest {
  name: "my-room"
  departure_timeout: 0
}
And if you’re working with a configuration file or SDK, just set
departureTimeout
to
0
in the room configuration. If you have any questions or want me to walk you through it, just let me know—I’m here to help! Sources: livekit/livekit_room.pb.go | cmd/lk/room.go | Sources/LiveKit/Types/RoomConfiguration.swift | Core Platform Architecture & Authentication | livekit/livekit_composite | D... | examples/voice_agents/session_close_callback.py
h
How I can configure this config on the room if I'm using the AgentDispatch method of the Golang SDK?
t
To help you configure the
departure_timeout
when using the AgentDispatch method with the Golang SDK, you’ll want to set this parameter in the room configuration right when you create the room. The
departure_timeout
is really useful because it makes sure the room only gets deleted after everyone has left and the timeout period has passed. Here’s a simple example to guide you:
Copy code
client, err := livekit.NewRoomServiceClient("wss://your-server-url", "api-key", "api-secret")
if err != nil {
    log.Fatal(err)
}

room, err := client.CreateRoom(context.Background(), &livekit.CreateRoomRequest{
    Name:             "example-room",
    DepartureTimeout: 120, // 2 minutes
})
if err != nil {
    log.Fatal(err)
}
Just be sure to replace
"wss://your-server-url"
,
"api-key"
, and
"api-secret"
with your own LiveKit Cloud credentials. You can also adjust the
DepartureTimeout
value to fit your needs—for example, use
0
if you want the room to be deleted immediately. If you have any questions or need a hand with anything else, please don’t hesitate to ask. I’m here to help! Sources: livekit/src/room/mod.rs | pkg/service/utils.go | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | livekit-rtc/livekit/rtc/_proto/room_pb2.pyi | Sources/LiveKit/Types/RoomConfiguration.swift
h
This could be related somehow to the
ctx.shoutdown()
hook?
t
Hi there! I’d love to help clarify how the
ctx.shutdown()
function works in LiveKit. This function is designed to gracefully disconnect an agent from a room without disturbing other participants or the room itself. When you call it, the agent leaves the room, but everyone else can keep enjoying their session without any interruptions. Plus, it takes care of running the agent's shutdown hooks for any cleanup or post-processing tasks. It’s important to know that
ctx.shutdown()
doesn’t delete the room or affect other participants in any way. If you’ve noticed the room getting deleted after the agent disconnects, it’s probably because the
delete_room_on_close
option is set to
True
in your agent's
RoomInputOptions
. This setting is what tells the system to delete the room once the agent’s session ends. So, if you want the room to stay active even after the agent leaves, just double-check that
delete_room_on_close
is set to
False
. Feel free to reach out if you’d like me to walk you through this or if you have any other questions—I’m here to help! Sources: examples/voice_agents/realtime_joke_teller.py | agent.py | Job lifecycle | LiveKit Docs | Managing rooms | LiveKit docs
👍 1