Turn detection & interruption
Endpointing modes, barge-in, and false-interruption handling.
Two questions decide the rhythm of a voice conversation: when has the user
finished their turn? (endpointing) and what happens when they talk over the
agent? (interruption). Getting these right is most of what makes an agent feel
responsive rather than laggy or rude — commit too early and you cut the user off,
too late and it feels slow; ignore barge-in and it talks over the caller. The
runtime gives you explicit control over both, with safe defaults, via
Config.Turn (TurnOptions).
Endpointing: when the user's turn ends
Endpointing decides the moment the user turn is committed and generation
starts. Set the mode on Config.Turn.Mode:
- VAD — end-of-speech from the voice-activity detector, plus an endpointing delay. The delay can be dynamic (longer after a short utterance, shorter after a long one) when enabled.
- STT — final transcripts plus the delay; no VAD required.
- Manual — the runtime never auto-commits; you call
GenerateReplyyourself. Right for push-to-talk or text. - Auto (default) — VAD if a VAD is configured, else STT, else manual.
The endpointing delay is the pause the agent waits out before deciding the user
really stopped (vs. taking a breath). Shorter = snappier but more likely to
interrupt; longer = more patient (MinEndpointingDelay defaults to 500ms).
Barge-in: interrupting the agent
While the agent is speaking, incoming user speech can barge in. If the active
SpeechHandle allows interruptions and the speech clears the configured
thresholds (InterruptionMinDuration, InterruptionMinWords), the reply is
cancelled, the audio buffer is cleared, and the session returns to listening.
A handle can opt out — a critical disclaimer can set itself uninterruptible so it
always completes. A tool can do the same for its step with
RunContext.DisallowInterruptions.
False interruptions
Not every sound is a turn. A cough, background speech, or a backchannel "mm-hm" can trip VAD without being a real interruption. The runtime treats these as a false interruption: rather than discard the reply, it pauses and resumes it after a short timeout if no real turn materialises — so a throat clear doesn't kill the agent's sentence.
False-interruption resume is a recovery path, not a substitute for good thresholds. Tune the interruption thresholds first; resume handles the residual noise.
Model-assisted end-of-turn (optional)
Beyond VAD/STT timing, you can plug in a model-assisted end-of-turn detector
that predicts whether the user has really finished. It runs in an external
Python sidecar over HTTP — the Go binary stays free of ML — and is entirely
opt-in. inference.TurnDetector() builds one from the environment
(INFERENCE_URL), returning nil (so endpointing falls back to plain VAD/STT) when
unset:
session, _ := agents.NewSession(agents.Config{
LLM: "openai/gpt-4o",
Turn: agents.TurnOptions{Detector: inference.TurnDetector()},
})The moving parts
Next
- Speech & the turn — the generation half.
- Full API: Reference → TurnOptions.