How do I toggle interruptable on and off?
# ask-ai
c
How do I toggle interruptable on and off?
t
Thanks for reaching out, Rithvik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you please help me understand what you mean by 'interruptable'? Are you talking about a particular feature, setting, or functionality in LiveKit? Any extra details you can share would really help me support you better.
c
Yea like I am calling an external tool and I don't want the user to interupt during the tool call
t
I completely understand how important it is to prevent user interruptions during external tool calls in LiveKit, and I’m here to help you with that! You can use the
RunContext
and
SpeechHandle
APIs to manage this smoothly. By default, LiveKit lets users interrupt the agent while it’s speaking, but you can easily disable this during those critical moments when your tool is running. Here’s a friendly example of how you might set this up:
Copy code
@function_tool
async def search_web(self, query: str, run_ctx: RunContext) -> str | None:
    run_ctx.disallow_interruptions()  # This line makes sure no interruptions happen during the call
    # Now, perform your external tool logic here
    result = await self._a_long_running_task(query)
    return result
Just a few helpful tips to keep in mind: • Start by calling
run_ctx.disallow_interruptions()
right at the beginning of your tool’s execution to block interruptions. • Be ready to handle a possible
RuntimeError
if the speech handle was interrupted earlier. • If you want, you can use
speech_handle.wait_if_not_interrupted()
to wait for completion only when there hasn’t been an interruption. Using these approaches will help your external tool calls run smoothly without unexpected user interruptions. If you have any questions or want to dive deeper, I’m here to support you every step of the way! Sources: livekit-agents/livekit/agents/voice/agent_session.py | Agent speech and audio | LiveKit Docs
c
I want to disable interruptions for the sesision
t
I'm happy to help you disable interruptions for the entire session in LiveKit! You can easily do this by setting the
allow_interruptions=False
parameter when creating your
AgentSession
or
Agent
. This way, the agent won’t be interrupted by the user during its speech output, making sure it runs smoothly throughout the session unless you decide to override it. Here’s a simple guide to get you started: Python Implementation 1. Using the
Agent
constructor:
Copy code
from livekit.agents.voice import Agent

agent = Agent(
    instructions="You are a helpful assistant.",
    stt=deepgram.STT(),
    llm=openai.LLM(model="gpt-4o"),
    tts=openai.TTS(),
    allow_interruptions=False  # This disables interruptions for the entire session
)
2. Using the
AgentSession
constructor:
Copy code
session = AgentSession(
    stt=deepgram.STT(),
    llm=openai.LLM(),
    tts=openai.TTS(),
    allow_interruptions=False  # This applies session-wide
)
Node.js Implementation Just use the
voiceOptions
parameter within
AgentSessionOptions
like this:
Copy code
import { AgentSession } from '@livekit/agents';

const session = new AgentSession({
  stt: new deepgram.STT(),
  llm: new openai.LLM(),
  tts: new openai.TTS(),
  voiceOptions: {
    allowInterruptions: false  // This disables interruptions globally
  }
});
Once you’ve set this up, the agent will complete its responses without being interrupted by user input, ensuring a smooth and uninterrupted experience. If you have any questions or need further assistance, feel free to ask—I’m here to help! Sources: packages/basics/src/uninterruptable.ts | livekit-agents/livekit/agents/voice/agent_session.py | basics/repeater.py
c
It there a way to have agent not hear
t
Hi there! To help you prevent a LiveKit agent from hearing audio input, here are a few friendly options you can try: 1. Permanently Disable Audio Input: You can set
audio_enabled=False
in
RoomInputOptions
when creating your session. This way, the agent won’t hear anything right from the start:
Copy code
# Python
session = AgentSession(
    ...,  # Other options
    room_input_options=RoomInputOptions(audio_enabled=False),
)
Copy code
// Node.js
const session = new voice.AgentSession({
    inputOptions: {
        audioEnabled: false,
    },
});
2. Temporarily Disable/Enable Audio Input: If you want to turn off the audio just for certain moments, you can do that dynamically during your tasks:
Copy code
# Python
session.input.set_audio_enabled(False)  # Pause the agent’s listening

try:
    await do_job()  # Do your non-verbal task here
finally:
    session.input.set_audio_enabled(True)  # Turn listening back on
3. Controlled Listening (Push-to-Talk): This method starts with audio off and lets you enable it only when you want the agent to listen:
Copy code
# Python
session = AgentSession(turn_detection="manual")
session.input.set_audio_enabled(False)  # Begin with audio disabled

# Turn it on whenever needed
session.input.set_audio_enabled(True)
Which of these sounds like it would work best for you? Whether you want to disable audio permanently, just for a bit, or only under certain conditions, I’m here to help you through it. Just let me know! Sources: Docs::Agents | Text and transcriptions | LiveKit Docs | Turn detection and interruptions | LiveKit Docs | Agent-assisted warm transfer | LiveKit Docs