Is there a particular event to subscribe for in ro...
# ask-ai
l
Is there a particular event to subscribe for in room / server sdk, when the agent ends the conversation.
t
Thanks for reaching out, Piyush. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To detect when an agent ends a conversation or leaves the room in the LiveKit Room or Server SDK, you can subscribe to the following events: • CloseEvent: This is the most specific event for agents. It is emitted when the AgentSession has closed and the agent is no longer running. This can happen if the agent ends the conversation, the session is closed programmatically, the room is deleted, or an unrecoverable error occurs. The event includes an
error
property if the closure was due to an error. • Disconnected Event: This event is emitted when any participant (including agents) is disconnected from the room. It provides a reason for the disconnection, such as participant removal or room deletion. • participant_disconnected Event: This handler is called when any participant, including agents, leaves the room. For agent-specific logic, subscribing to the CloseEvent is recommended. For general participant tracking, use the Disconnected or participant_disconnected events. Agents can also end their participation programmatically using
ctx.shutdown(reason="Session ended")
, which will trigger these events. Sources: Connecting to LiveKit | LiveKit Docs | agent/game_host.py | Inside a session | LiveKit Docs | Anatomy of an Agent | LiveKit Docs | Events and error handling | LiveKit Docs