can I dynamically change the turn detection model?...
# ask-ai
r
can I dynamically change the turn detection model? Specifically, I want to modify
min_endpointing_delay
during the call
t
Thanks for reaching out, Ivan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Regarding changing
min_endpointing_delay
during a call — yes. You can update turn-detection/endpointing settings at runtime by calling
update_options()
on the
AgentActivity
instance;
min_endpointing_delay
(and
max_endpointing_delay
) are runtime-configurable through that API. Do you want a short code example for your language (Python/JS) or details about safe value ranges to use? Sources: Agents (Python) | livekit/livekit_composite | DeepWiki
r
yes, please give me an example in python
t
You're asking for a Python example to change
min_endpointing_delay
during an active call. Below is a concise example showing how to call
update_options()
on the
AgentActivity
instance to change endpointing at runtime.
Copy code
from livekit.agents import AgentSession, JobContext
from livekit.plugins import silero, deepgram, openai
import asyncio

class MyAgent:
    async def on_turn(self, turn):
        # agent turn handling...
        pass

async def entrypoint(ctx: JobContext):
    stt = deepgram.STT()
    llm = openai.LLM()
    tts = openai.TTS()
    vad = silero.VAD()

    # Start session with initial endpointing config
    session = AgentSession(
        stt=stt,
        llm=llm,
        tts=tts,
        vad=vad,
        turn_detection="vad",
        min_endpointing_delay=0.5,
        max_endpointing_delay=6.0,
    )

    await session.start(ctx.room, agent=MyAgent())

    # Example: update min_endpointing_delay during the call
    # This can be triggered by any runtime condition (voice command, UI button, etc.)
    new_min_delay = 1.0
    session.agent.activity.update_options(min_endpointing_delay=new_min_delay)

    # You can update multiple options at once
    session.agent.activity.update_options(
        min_endpointing_delay=0.3,
        max_endpointing_delay=5.0,
        turn_detection="vad"
    )

# If running standalone for testing:
# asyncio.run(entrypoint(your_job_context))
If you want, I can: • Provide a shorter snippet showing only the
update_options()
call, • Show an example that updates the delay in response to a user event (e.g., noise detection or a button press). Which would you prefer? Sources: Agents (Python) | livekit/livekit_composite | DeepWiki