if the participant leaving the session (triggered ...
# ask-ai
a
if the participant leaving the session (triggered from client/server sdk), what event triggered on agent side?
t
Thanks for reaching out, affandy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
When someone leaves a session in LiveKit, the event that pops up on the agent side is participant_left. This lets the agent know that a participant has disconnected from the room, whether they left from their side or the server did. Feel free to ask if you'd like me to explain more or help with anything else! Sources: agent/game_host.py | Connecting to LiveKit | LiveKit Docs | agent-console/lib/event-types.ts | events/event_emitters.py | pkg/telemetry/events.go
a
how to trigger agent session close when the participant left?
t
When a participant leaves, you can have the agent session close automatically by using the default setting where
close_on_disconnect
is enabled. If that’s turned off, no worries—you can just close the session yourself with
session.aclose()
. Here’s a quick rundown: • Automatic Closure: Make sure
close_on_disconnect=True
(which is the default). This way, the session wraps up as soon as the participant leaves. • Manual Closure: Keep an eye out for the
participant_disconnected
event, then call
session.aclose()
in your agent code. • Room-Level Termination: If you want to end everything—including agents and recordings—just use
ctx.delete_room()
. If you want a hand setting any of this up, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/voice/room_io/room_io.py | Inside a session | LiveKit Docs
a
if I trigger
session.aclose()
what event will be triggered? does the agent session on close event will be triggered?
t
When you call
session.aclose()
, it kicks off the agent session's
on close
event. This event happens when the session closes, and you can catch it by using the
.on("close")
handler on your
AgentSession
instance. Feel free to ask if you'd like me to explain more or share some examples! Sources: Events and error handling | LiveKit Docs | Events and error handling | LiveKit Docs | examples/voice_agents/error_callback.py | basics/exit_message.py