cool-iron-91629
09/15/2025, 2:27 AMtall-airline-16756
09/15/2025, 2:27 AMtall-airline-16756
09/15/2025, 2:28 AMcool-iron-91629
09/15/2025, 2:28 AMtall-airline-16756
09/15/2025, 2:29 AMRunContext 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:
@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 Docscool-iron-91629
09/15/2025, 2:38 AMtall-airline-16756
09/15/2025, 2:39 AMallow_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:
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:
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:
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.pycool-iron-91629
09/15/2025, 2:53 AMtall-airline-16756
09/15/2025, 2:54 AMaudio_enabled=False in RoomInputOptions when creating your session. This way, the agent won’t hear anything right from the start:
# Python
session = AgentSession(
..., # Other options
room_input_options=RoomInputOptions(audio_enabled=False),
)
// 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:
# 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:
# 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