Is there a way to get shutdown reason, i.e. SIP pa...
# ask-ai
b
Is there a way to get shutdown reason, i.e. SIP participant disconnected (user hang up) or agent hang up
t
Thanks for reaching out, Masayuki. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking whether you can tell why a call ended (for example, the SIP user hung up vs. the agent ending the call). Yes — you can determine that by inspecting the participant close/disconnect reason exposed by LiveKit. What to look for • User hang up (SIP participant disconnected): the participant will have a close reason of CLIENT_INITIATED. This is emitted when the client intentionally leaves the room. • Agent hang up (server-side action): when the agent or server ends the call, you’ll see server-originated reasons such as SERVICE_REQUEST_REMOVE_PARTICIPANT (participant removed via API) or SERVICE_REQUEST_DELETE_ROOM / ROOM_DELETED (room deleted by the server). How to observe these in practice • Webhooks: The
participant_left
webhook includes a
reason
field (e.g., "client_initiated"). Use this for downstream processing or logging outside your application. • SDK / server-side listeners: Listen for participant state changes or room events in your application and check the participant’s close/disconnect reason. Example pattern: 1. Attach a listener for participant left/disconnect events. 2. Inspect the participant close reason value. 3. Branch your logic by reason: treat
CLIENT_INITIATED
as user hang-up, and
PARTICIPANT_REMOVED
/
ROOM_DELETED
as agent/server hang-up. If you’d like, tell me: • Which SDK or webhook integration you’re using (JavaScript, Python, webhook consumer), and • Whether you want an example for event handling in code or the exact webhook payload layout. I can then give a short code sample or the exact fields to parse for your environment. Sources: Server-side | livekit/livekit_composite | DeepWiki
b
How can we get the close reason (e.g. CLIENT_INITIATED) in livekit agent?
t
Thanks — you're asking specifically how to get the participant close reason (for example,
CLIENT_INITIATED
) inside a LiveKit agent so you can tell user hang-up vs. agent hang-up. You can access that reason from the agent runtime via room/participant events or from the job context at session end. Can you tell me which environment/SDK you want the example for? (Python agent, JS, or Go agent?) Below are the common ways — pick the one you need and I’ll provide a concise code sample for that SDK. What to read/inspect • Use the agent session lifecycle:
ctx.disconnect_reason
is available when the session ends and holds the disconnect reason (for example,
CLIENT_INITIATED
). • Listen for participant disconnect events on the room: those event callbacks include the disconnect reason (e.g.,
participant_disconnected
/
participant_left
with reason like
CLIENT_INITIATED
,
PARTICIPANT_REMOVED
, or
ROOM_DELETED
). How to get it (summary) • From JobContext at shutdown: a. Wait for session end or participant leave inside your agent. b. Read
ctx.disconnect_reason
to get values such as
CLIENT_INITIATED
or
ROOM_DELETED
. • From room/participant event handler: a. Register a listener for participant disconnect/left events. b. Inspect the event payload or the participant object for the close reason field (e.g.,
participant.close_reason
or the
reason
argument passed to the handler). If you tell me which SDK (Python, JavaScript, or Go) I’ll send a short concrete example showing exactly where to read
ctx.disconnect_reason
or how to handle the participant disconnect event and parse the reason. Sources: server-sdk-go | livekit/livekit_composite | DeepWiki | Server-side | livekit/livekit_composite | DeepWiki
b
Do we get
on_participant_disconnected
event with
DisconnectReason.CLIENT_INITIATED
even for SIP/voice channel?
t
Yes — when a SIP caller hangs up, the agent receives the participant-disconnected event with reason set to DisconnectReason.CLIENT_INITIATED. What you can rely on • SIP/voice participants emit the same disconnect reason semantics as other participant types. When the caller ends the call, LiveKit treats it as a client-initiated disconnect and fires the
on_participant_disconnected
(or
participant_left
) event with
CLIENT_INITIATED
. • You can also observe the SIP-specific attribute
sip.callStatus
changing to
hangup
. Monitoring
on_participant_attributes_changed
for that attribute provides an additional confirmation that the SIP caller hung up. If you want, I can provide a short code example for your agent SDK (Python, JS, or Go) showing: 1) the disconnect event handler reading the disconnect reason, and 2) monitoring
sip.callStatus
as a backup signal. Which SDK should I use? Sources: SIP Lifecycle Management Agent | LiveKit Documentation