How can i interrupt agent's current thinking or sp...
# ask-ai
n
How can i interrupt agent's current thinking or speaking state?
t
Thanks for reaching out, Darshak. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you understand how to interrupt an agent's current thinking or speaking state. There are two simple ways to do this: • Automatic Interruption: LiveKit is designed to be really intuitive—it automatically pauses the agent's speech whenever it detects user speech in the input audio stream. This happens through Voice Activity Detection (VAD), smoothly transitioning the agent to listening mode. • Programmatic Interruption: If you prefer to take control manually, you can use the
interrupt()
method on the agent session. This lets you cancel current and queued speech, and even interrupt background speeches if you want. Here's a quick example:
Copy code
# Interrupt current and queued speech
future = session.interrupt(force=False)
await future  # Wait for interruption to complete
Just a quick note: the
force
parameter decides if interruptions follow the
allow_interruptions
setting. If you set
force=True
, it will interrupt no matter what. Please don’t hesitate to reach out if you want me to walk you through this further or if you have any other questions. I’m here to help! Sources: Events and error handling | LiveKit Docs | How to Handle Speech Interruptions More Naturally | Turn detection and interruptions | LiveKit Docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Web and mobile frontends | LiveKit Docs