how to know when the agent is interrupted in livek...
# ask-ai
b
how to know when the agent is interrupted in livekit agents 1.x version
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
In LiveKit Agents 1.x, you can detect when an agent is interrupted in the following ways: • Using event listeners: Listen for the
AGENT_SPEECH_INTERRUPTED
event (event type 6 in the VPAEvent enumeration) in your application. • Manual interruption handling: Use the
session.interrupt()
method to manually interrupt the agent session. This will immediately end any active agent speech and truncate the context to include only the speech heard before the interruption. For example, you can implement this in custom event handlers, such as when a new participant joins a room:
Copy code
# Interrupt the agent's current response whenever someone joins the room
@ctx.room.on("participant_connected")
def on_participant_connected(participant: rtc.RemoteParticipant):
    session.interrupt()
When an interruption occurs, the agent stops speaking and switches to listening mode, storing the position of the speech played so far in its
ChatContext
. Sources: VPAEvent | LiveKit Agents | Turn detection and interruptions | LiveKit Docs