livekit meet, is it possible to make the agent sta...
# ask-ai
h
livekit meet, is it possible to make the agent stay in the call for a duration even after the user disconnects so that there is a provision for the user to join back to the same call?
✅ 1
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about keeping an agent in a LiveKit Meet call after the user disconnects so the user can rejoin later. Short answer: Yes — you can keep the agent in the room after the user leaves by disabling automatic session closure on user disconnect. How to achieve this • Set the room/session option that controls automatic closure: use
close_on_disconnect = False
(in Python
RoomOptions
or in Node.js
RoomInputOptions
). This prevents the AgentSession from closing when the linked participant (the user) disconnects. • Be aware of the room lifecycle: rooms are closed automatically after a short grace period when no non-agent participants remain (the
departure_timeout
, default 20 seconds). If you need the room to stay available longer, you must manage that timeout or avoid deleting the room. • If you want explicit control, you can manually delete the room via the server API (
deleteRoom
) when you decide it should end. Practical notes • LiveKit Meet itself does not add special UI controls for this; this is handled by your backend/session configuration. • This approach lets the agent remain active and the user rejoin the same room later, as long as the room hasn’t been closed or deleted. If you’d like, tell me: • Which SDK/language you’re using (Node.js or Python), and • Whether you need the room to persist longer than the default timeout. I can then give a short example snippet and recommended next steps. Sources: Agent session | LiveKit Documentation | Job lifecycle | LiveKit Documentation | examples/other | livekit/livekit_composite | DeepWiki, with interactive elements
h
I want the room to persist longer than the default timeout
t
Thanks — I’m responding to your request about keeping the room available longer than the default timeout so the user can rejoin while the agent stays in the call. What you need to do • Increase the room’s departure/empty timeout (the setting that controls how long a room stays open after all non-agent participants leave). The default is 20 seconds; raise this to the number of seconds you want the room to persist. • Ensure the agent session option
close_on_disconnect
is disabled so the AgentSession does not automatically close when the user disconnects. • Do not set the room to be deleted immediately when the agent session ends (
delete_room_on_close
should be False) if you want explicit control over when the room is removed. Before I give code samples: which SDK/language are you using (Node.js or Python)? Also, roughly how long do you want the room to persist (e.g., 5 minutes, 30 minutes, longer)? With that I’ll provide a concise example showing the exact field names and a short snippet you can drop into your server code. , with interactive elements
h
how do i Increase the room’s departure?
t
Thanks — I’m responding to your question about how to increase the room’s departure (empty) timeout so the room persists longer after the user disconnects. Quick question before the snippet: which SDK/language are you using on the server — Node.js or Python? Tell me that and I’ll give a short copy-paste example. If you want the general steps now, here they are: 1. Increase the room’s departure/empty timeout at room creation. ◦ This is the
empty_timeout
(Python) or
emptyTimeout
(Node.js) /
departure_timeout
field on the Room creation request. ◦ Set the value in seconds to how long you want the room to remain open after all non-agent participants leave (e.g., 300 for 5 minutes). 1. Ensure agent/session options are set so the agent stays: ◦ Set
close_on_disconnect = False
for the AgentSession so the agent doesn’t auto-close when the user leaves. ◦ Ensure
delete_room_on_close = False
if you don’t want the room deleted immediately when the agent session ends. 1. Optionally, create the room server-side (recommended) so you control these settings explicitly. You can also embed room configuration into access tokens if you use auto-creation via tokens. Example fields to set • Python Room creation:
empty_timeout=<seconds>
• Node.js Room creation:
emptyTimeout: <seconds>
Once you tell me whether you want Node.js or Python, I’ll provide a concise example showing the exact API call and fields to change. , with interactive elements
h
So can I just do async def entrypoint(ctx: agents.JobContext): await ctx.connect() try: await ctx.api.room.create_room( api.CreateRoomRequest( name=ctx.room.name, departure_timeout=120, ) ) await session.start( room=ctx.room, agent=agent_instance, room_options=room_io.RoomOptions( video_input=True, audio_input=room_io.AudioInputOptions( noise_cancellation=noise_cancellation.BVC(), ), close_on_disconnect=False, delete_room_on_close=False, ), )
t
Thanks — I’m responding to your code snippet and confirming how to increase the room departure timeout and keep the agent in the room. Yes — your approach is correct in principle. A few small adjustments and clarifications to make it explicit and safe: 1) Use the room creation field name the server SDK expects • In the RoomService create call, set the timeout field the SDK uses. Your snippet uses
departure_timeout
which is correct if your SDK's request type uses that name; some SDKs use
empty_timeout
/
emptyTimeout
. Make sure you use the exact field name on
CreateRoomRequest
in your SDK version. 2) Keep the agent session options set to avoid automatic closure •
close_on_disconnect=False
prevents the AgentSession from closing when the linked participant disconnects. •
delete_room_on_close=False
prevents the room being deleted automatically when the agent session ends. 3) Example (refined) Python structure • This mirrors your flow and emphasizes the two pieces: create the room with an increased timeout, then start the agent session with the room options.
Copy code
async def entrypoint(ctx: agents.JobContext):
    await ctx.connect()

    try:
        # create room with longer empty/departure timeout (seconds)
        await ctx.api.room.create_room(
            api.CreateRoomRequest(
                name=ctx.room.name,
                departure_timeout=120,  # or empty_timeout if your SDK uses that name
            )
        )

        # start agent session and keep agent in room after user disconnects
        await session.start(
            room=ctx.room,
            agent=agent_instance,
            room_options=room_io.RoomOptions(
                video_input=True,
                audio_input=room_io.AudioInputOptions(
                    noise_cancellation=noise_cancellation.BVC(),
                ),
                close_on_disconnect=False,
                delete_room_on_close=False,
            ),
        )

    finally:
        # optional cleanup if needed
        await ctx.disconnect()
4) Practical tips • Confirm the exact field name on
CreateRoomRequest
in your installed SDK (search for
departure_timeout
,
empty_timeout
, or
emptyTimeout
). • If your system may create the same room name elsewhere, consider handling create-room errors (room already exists) or using an upsert pattern. • If you need longer persistence than a few minutes, raise the timeout accordingly (value is in seconds). • If you need explicit control to end the room earlier/later, call the server-side
deleteRoom
when desired. If you tell me which exact Python LiveKit package and version you’re using (or paste the
CreateRoomRequest
signature), I’ll confirm the exact field name and give any tiny adjustments needed. , with interactive elements