Does the event participant disconnected include an...
# ask-ai
c
Does the event participant disconnected include any participant, remote or local? So the if the agent is disconnected, the event is triggered?
✅ 1
t
Thanks for reaching out, Yousri. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — good question. You're asking whether the "participant disconnected" event includes both remote and local participants, and specifically whether it fires when an agent disconnects. Short answer: • The
participant_disconnected
event refers to remote participants (i.e., other participants in the room), not the local participant. • If an agent is a remote participant and they leave, other participants will receive
participant_disconnected
. • If the agent is the local participant (the client process that’s running in your app) and it disconnects,
participant_disconnected
will not fire for itself — use
room_disconnected
or the connection state changes to detect the local disconnect. If you'd like, tell me which SDK (web, iOS, Android, or server) you’re using and whether the agent runs as a remote participant or as the local client in your flow — I can give the exact event names and a short code snippet to listen for the appropriate events. Sources: server-sdk-ruby | livekit/livekit_composite | DeepWiki | Server-side | livekit/livekit_composite | DeepWiki | Client SDKs | livekit/livekit_composite | DeepWiki | livekit/livekit_composite | DeepWiki, with interactive elements
c
Can i call session.current_agent inside a shutdown_hook? Is the session still alive?
t
Thanks — good question. You're asking whether
session.current_agent
is safe to access inside a
shutdown_hook
and if the session is still alive during that hook. Short answer: • Yes — the session is still alive while shutdown hooks run, and you can safely access
session.current_agent
inside a
shutdown_hook
. • Shutdown hooks are executed after
session.shutdown()
or
ctx.shutdown()
begins but before the session is fully closed, so session state (including
current_agent
,
userdata
, and
tts
) is preserved until the hook completes. A couple of practical notes: • Keep shutdown hooks short: by default the framework waits 10 seconds before forcefully terminating the process. If you need more time, adjust
shutdown_process_timeout
in your agent server options. • Use the hook for quick cleanup, logging, or saving state. Long-running work should be avoided unless you increase the timeout. If you want, tell me which SDK or language you’re using and I’ll share a brief code snippet showing a safe
shutdown_hook
that reads
session.current_agent
. Sources: Job lifecycle | LiveKit Documentation | Agents and handoffs | LiveKit Documentation | Agent session | LiveKit Documentation, with interactive elements
c
Is there a shutdown_hook defined on Agent class,
t
You're asking whether the Agent class defines a
shutdown_hook
. Short answer: • No — the
Agent
class does not define a
shutdown_hook
method. What to use instead: • Register shutdown callbacks on the job context using `ctx.add_shutdown_callback(my_hook)`; those callbacks run during session shutdown while the session (and
session.current_agent
) is still available. • The
Agent
class does provide lifecycle hooks like
on_enter
and
on_exit
, but those are not the same as session-level shutdown hooks. If you'd like, tell me which language/SDK you're using and I can show a short example of registering a
ctx.add_shutdown_callback
that safely accesses
session.current_agent
. Sources: Job lifecycle | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation, with interactive elements