wonderful-account-72949
11/06/2025, 6:11 AM{
"message": "closing agent session due to participant disconnect (disable via `RoomInputOptions.close_on_disconnect=False`)",
"level": "INFO",
"name": "livekit.agents",
"participant": "ai-agent",
"reason": "CLIENT_INITIATED",
"pid": 86444,
"job_id": "AJ_s3NypnBwUvgP",
"timestamp": "2025-11-06T06:08:55.989738+00:00"
}
What should i do to prevent this behaviour?
PS:- I'm using python AI Agent, let me know if you need any code snippettall-airline-16756
11/06/2025, 6:11 AMtall-airline-16756
11/06/2025, 6:12 AMclose_on_disconnect=False in the RoomInputOptions when you start the agent session. Here’s a simple example to guide you:
from livekit.agents import AgentSession, RoomInputOptions
# Create and start the agent session
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(),
tts=cartesia.TTS(),
vad=silero.VAD.load(),
)
await session.start(
agent=MyAgent(),
room=ctx.room,
room_input_options=RoomInputOptions(
close_on_disconnect=False, # This keeps the session open even if a participant disconnects
delete_room_on_close=False # Optional: decide if the room should be deleted when the session closes
),
)
That said, it’s still important to manage the session lifecycle carefully. When it’s time, you can manually close the session using await session.aclose(). Also, listening for session closure events can be really helpful for any cleanup or logging you want to do afterward:
@session.on("close")
def on_close(ev: CloseEvent):
logger.info(f"Agent session closed, reason: {ev.reason}")
# Here’s a great spot to handle cleanup or add logging
If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/agent_session.py | Events and error handling | LiveKit docs | Job lifecycle | LiveKit Docswonderful-account-72949
11/06/2025, 6:17 AMtall-airline-16756
11/06/2025, 6:17 AM