big-controller-60015
07/31/2025, 1:58 PMtall-airline-16756
07/31/2025, 1:58 PMtall-airline-16756
07/31/2025, 1:59 PMclose_on_disconnect parameter in RoomInputOptions when starting an agent session.
Here is an example implementation:
session = AgentSession(
llm=your_llm_model,
# other session configuration
)
await session.start(
room=ctx.room,
agent=your_agent,
room_input_options=RoomInputOptions(close_on_disconnect=False),
# other options
)
By setting close_on_disconnect=False, the session will not automatically close when a participant disconnects. However, note that the room itself will still close after a short delay if the last non-agent participant leaves. To handle this, you can implement custom logic to manage participant disconnections:
async def entrypoint(ctx: JobContext):
session = AgentSession(
llm=your_llm_model,
# other configuration
)
await session.start(
room=ctx.room,
agent=your_agent,
room_input_options=RoomInputOptions(close_on_disconnect=False),
)
# Handle participant disconnections manually
def on_participant_disconnected(participant):
if len(ctx.room.remote_participants) == 0:
# Decide whether to close session or wait for new participants
pass
ctx.room.on("participant_disconnected", on_participant_disconnected)
This approach gives you control over when the session closes, allowing you to implement custom logic for handling participant disconnections.
Sources: examples/voice_agents/realtime_joke_teller.py | Worker lifecycle | LiveKit Docs | Core API primitives | LiveKit Docs