creamy-window-79763
03/21/2026, 4:37 PMtall-airline-16756
03/21/2026, 4:37 PMtall-airline-16756
03/21/2026, 4:38 PMparticipant_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 elementscreamy-window-79763
03/21/2026, 4:39 PMtall-airline-16756
03/21/2026, 4:39 PMsession.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 elementscreamy-window-79763
03/21/2026, 4:53 PMtall-airline-16756
03/21/2026, 4:53 PMshutdown_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