from livekit.plugins.openai import realtime from o...
# ask-ai
b
from livekit.plugins.openai import realtime from openai.types.beta.realtime.session import TurnDetection session = AgentSession( llm=realtime.RealtimeModel( turn_detection=TurnDetection( type="server_vad", threshold=0.5, prefix_padding_ms=300, silence_duration_ms=500, create_response=True, interrupt_response=True, ) ), # ... vad, tts, stt, etc. ) explain these turn detection parameters
t
Thanks for reaching out, Bhavya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let me walk you through the turn detection parameters in your code to help you understand them better: • type="server_vad": This means the system uses Server VAD to detect when someone is speaking, based on the loudness of the audio. • threshold=0.5: This sets the level of audio loudness needed to recognize speech. A value of 0.5 is a nice balance between catching speech and filtering out background noise. • prefix_padding_ms=300: This adds 300 milliseconds of audio before the detected speech starts, so we don’t miss any important context. • create_response=True: With this, the system will automatically create a response as soon as the user finishes speaking. • interrupt_response=True: This lets the user jump in and interrupt the assistant’s response by starting to talk. If anything feels unclear or if you’d like me to explain more, please don’t hesitate to ask—I’m here to help! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py | OpenAI Realtime API plugin guide | LiveKit docs | Azure OpenAI Realtime API and LiveKit | LiveKit Docs | plugins/openai/src/realtime/realtime_model.ts
b
will it interrupt the tool calls?
t
Absolutely! The interrupt_response parameter is designed to let you interrupt tool calls. When you set it to true, it means your speech can gently pause the agent’s current output—whether that’s spoken responses or active tool calls. It’s actually enabled by default, so if you start speaking, the tool calls will automatically pause. If you have any more questions or need a bit more help, just let me know—I’m here for you! Sources: Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | plugins/openai/src/realtime/realtime_model.ts | Tool definition and use | LiveKit docs | Turn detection and interruptions | LiveKit Docs | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/...
b
pause or stop completely?
t
I’m glad you asked about the interrupt_response parameter! It’s designed to let users interrupt, which can stop tool calls, but it doesn’t automatically pause them. When someone speaks, the interruption sequence stops the agent’s response and cancels the tool call—if it’s set up to handle interruptions. To handle this smoothly, tools can check the
speech_handle.interrupted
flag. This helps them detect if an interruption happened and decide if they should stop what they’re doing. For instance, a tool can look at this flag and cancel its current task if needed. Please feel free to reach out if you’d like me to explain more or provide some examples—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Turn detection and interruptions | LiveKit Docs | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | Tool definition and use | LiveKit docs | Tool definition and use | LiveKit docs
b
so if I just interrupt to ask the status of tool call? it will be stopped?
t
I just wanted to share a quick heads-up: if you happen to interrupt while checking the status of a tool call, the system will treat that as an interruption and might stop the tool call altogether. Usually, any speech from you during a tool’s execution triggers this interruption, which cancels the tool call and removes it from the chat history. But don’t worry! If you want to make sure important tool calls aren’t interrupted, developers can actually disable interruptions for those specific tools using
run_ctx.disallow_interruptions()
. Please feel free to reach out if you’d like me to explain anything further or if there’s anything else I can help with! Sources: Tool definition and use | LiveKit docs | Tool definition and use | LiveKit docs