voice.agents.attach
plus the turn-detection knobs. TypeScript primary; Python shown where it differs.
Attach a speech-to-speech agent to a call
The one-liner: bind a registered agent to a live call sid.Originate and attach in one call
Passagent to originate so the model is bridged the moment the callee answers.
Attach with an inline agent spec
Skip the registry — select the model leg and turn-detection policy inline.Pick the codec the model wants
Most speech-to-speech models ingest raw PCM16. Set the model codec; the caller leg is transcoded at the bridge.A PSTN caller leg may be
g711_ulaw / g711_alaw; a browser leg is opus.
You never set the caller codec here — only what the model expects.Tighten end-of-turn for snappier replies
Lower the trailing-silence threshold so the agent answers sooner after the caller stops.Stop backchannels from triggering a reply
Continuers like “mhm” / “ok” / “right” shouldn’t make the model answer. Raise the minimum speech length that counts as a turn.Make barge-in forgiving (hold-and-confirm)
Require speech to be sustained before cancelling the agent, so a muttered continuer mid-reply doesn’t kill the turn.Make barge-in instant (browser / AEC legs)
When the caller leg has client-side echo cancellation, cut the agent on the first speech frame.Stop the agent self-triggering on a no-AEC SIP/PSTN leg
When there’s no echo cancellation, the agent’s own audio bleeds into the mic. Raise the post-audio mic guard so it doesn’t read its own voice as barge-in.Inject a pre-roll prompt before the model speaks
Attach the audio bridge and push a downlink clip before the first model turn.Record the caller leg while the agent runs
Tap the uplink without disturbing the agent bridge.- TypeScript
- Python
Watch turn boundaries and barge events
Subscribe to call status to see when the agent commits a turn or gets interrupted.Detach the agent but keep the call up
Hand the call back to a human (or another app) by attaching a bare bridge and not re-attaching the agent.Attach a speech-to-speech agent in Python
The same flow, snake_case.Related
- Inference — Recipes — full worked examples
- Inference — SDK Methods — every method and the full knob table
- Turn Detection & Barge-In — the policy these knobs drive

