Can an agent get interrupted while making a tool c...
# ask-ai
w
Can an agent get interrupted while making a tool call?
t
Thanks for reaching out, Drew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, an agent can be interrupted while making a tool call in LiveKit, and the system is thoughtfully designed to handle these interruptions smoothly. Here’s how it works: • Long-running tool calls are able to detect if an interruption happens and can cancel tasks if needed, so nothing gets stuck. • The system has a default interruption behavior—for instance, if the user starts speaking, the agent’s speech will pause automatically. • You can also trigger interruptions explicitly using the
interrupt()
method whenever you need to. Whenever an interruption takes place, the agent moves through the right states to keep everything running smoothly and responsively. If you have any more questions about this, feel free to ask—I’m here to help! Sources: tests/test_agent_session.py | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | Bringing AI avatars to voice agents
w
how do I make an agent uninterruptible
t
I'm happy to guide you through making an agent uninterruptible in LiveKit. You can achieve this by setting the
allow_interruptions
parameter to
False
. Let’s walk through the steps together: • In Python: You simply set
allow_interruptions=False
when creating the agent. Here’s a quick example:
Copy code
class UninterruptableAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are not interruptable.",
            stt=deepgram.STT(),
            llm=openai.LLM(model="gpt-4o"),
            tts=openai.TTS(),
            allow_interruptions=False  # This disables interruptions
        )
In Node.js: You do something similar by setting
allowInterruptions: false
in the agent options, like this:
Copy code
const agent = new pipeline.VoicePipelineAgent(
  vad,
  stt,
  llm,
  tts,
  {
    chatCtx: initialContext,
    allowInterruptions: false  // This disables interruptions
  }
);
Additionally, if you want to control interruptions dynamically for specific speech outputs, you can use
SpeechHandle
. For instance, in Python:
Copy code
async def on_function_call(self, ctx, function_call):
    ctx.disallow_interruptions()  # This disables interruptions for this specific call
If you’d like to explore further, I recommend checking out the Uninterruptable Agent example in the LiveKit examples repository. It’s a great resource to deepen your understanding. Sources: packages/basics/package.json | livekit-agents/livekit/agents/voice/agent.py | agents/src/voice/speech_handle.ts | LiveKit Docs | basics/interrupts_user.py