@ctx.room.on("participant_disconnected") Does this...
# ask-ai
f
@ctx.room.on("participant_disconnected") Does this keep track of when agent disconnect? or only local participants?
t
Thanks for reaching out, Mok. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! The
@ctx.room.on("participant_disconnected")
event is designed to track when any remote participant disconnects, which includes both local participants and agents—it doesn’t exclude agents by default. If you want to specifically keep an eye on when an agent disconnects, a helpful way is to check the participant's
kind
property. Here’s a little example to guide you:
Copy code
@ctx.room.on("participant_disconnected")
def _on_participant_disconnected(participant: rtc.RemoteParticipant):
    if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_AGENT:
        # Handle agent disconnection
        pass
Using this method, you can easily manage agent disconnections separately. Hope this helps! If you have any more questions, feel free to ask—we’re here for you. Sources: Handling events | LiveKit Docs | livekit-rtc/livekit/rtc/_proto/room_pb2.pyi | examples/warm-transfer/warm_transfer.py
f
what if i just want remote aprticipants that are not agents
t
To help you track only remote participants who are not agents using the
@ctx.room.on("participant_disconnected")
event, you can simply filter participants by checking their
kind
property. Here’s a friendly example to guide you:
Copy code
@ctx.room.on("participant_disconnected")
def on_participant_disconnected(participant: rtc.RemoteParticipant):
    if participant.kind != rtc.ParticipantKind.PARTICIPANT_KIND_AGENT:
        # Handle only non-agent participants
        print(f"Non-agent participant disconnected: {participant.identity}")
        # Feel free to add your custom logic here
This way, you’ll be sure that only the disconnections of participants who aren’t agents will trigger your logic. If you have any questions or want to explore this further, I’m here to help! Sources: agent-console/lib/event-types.ts