Real-Time Voice & Multimodal AI Agents
Architect sub-500ms voice AI agents: WebRTC transport, cascaded streaming vs native speech-to-speech, semantic endpointing, and clean barge-in cancellation.
In this lesson (4 bite-sized sections)
Why sub-500ms voice breaks turn-based HTTP pipelines
Human conversation pauses sit between 200ms and 500ms. Cross roughly 700ms and callers assume the connection dropped, repeat themselves, and collide with the delayed reply. Classic request-response AI pipelines record an entire utterance, upload audio over HTTP, run batch transcription, wait for a full LLM completion, and synthesize a whole clip before playback starts. That serial path easily takes 3 to 5 seconds.
Production voice platforms such as OpenAI Realtime, LiveKit Agents, and Sierra hit sub-500ms turn latency by streaming every stage over WebRTC at the client edge. WebRTC carries Opus audio over UDP and SRTP with ICE NAT traversal and adaptive jitter buffers. Unlike TCP-backed WebSockets, a single dropped packet on congested cellular radio is masked with packet-loss concealment rather than stalling later audio frames behind retransmissions.
Two serving architectures dominate voice agents: cascaded streaming pipelines (WebRTC -> VAD -> Streaming ASR -> Streaming LLM -> Streaming TTS) and native speech-to-speech (S2S) models. Cascaded pipelines let teams mix best-in-class speech, LLM, and voice providers while auditing exact text transcripts and deterministic tool arguments. Native S2S models consume and emit audio tokens directly, cutting pipeline hops and preserving vocal tone or laughter, at the cost of tighter provider lock-in and less transparent intermediate transcripts.
Budgeting every millisecond from mouth to ear
Because cascaded stages stream concurrently, total mouth-to-ear turn latency is not the sum of full-utterance runtimes; it is the sum of each stage's first-usable-output delay. As soon as streaming ASR emits a final transcript and the endpointing detector fires, the LLM begins prefill, yields its first sentence chunk to streaming TTS, and TTS emits the first 20ms PCM audio frame to the WebRTC track. One slow link in that chain breaks the 500ms budget immediately.
Semantic endpointing and clean barge-in cancellation
Simple energy-based VAD (Voice Activity Detection) forces a bad tradeoff. A 200ms silence threshold interrupts callers who pause mid-sentence to recall an order number, whereas an 800ms threshold adds sluggish dead air to every turn. Production systems layer a lightweight semantic end-of-turn (EOT) model over partial ASR text and prosodic cues: incomplete clauses extend the wait window, while completed questions commit immediately.
Barge-in (interruption handling) is the sharpest engineering edge case. When VAD detects caller speech while the agent is talking, the orchestrator must cancel three things in lockstep: flush queued TTS frames and clear the client WebRTC playback buffer, abort the in-flight LLM stream, and roll back the stored assistant message to the exact word offset actually played to the caller's ear.
Speculative tool calls and latency masking
External CRM or database queries take 300ms to 1,500ms, blowing past conversational budgets if run synchronously after turn commit. Voice orchestrators mask tool latency using three techniques: streaming a brief natural filler phrase while executing the tool asynchronously, running speculative read-only prefetch from stable partial ASR hypotheses before final EOT (strictly limited to idempotent reads, never mutations), and co-locating the agent worker in the same region as the WebRTC SFU and model endpoint.
Assign each voice-agent mechanism to its primary architectural responsibility.
Sort 4 more items to check
Recap: hit sub-500ms voice turns by terminating client audio on WebRTC, streaming every stage concurrently, choosing cascaded vs native S2S based on auditability and prosody needs, guarding barge-in with playout-offset history truncation, and limiting speculative prefetches strictly to read-only lookups.
Sources: OpenAI Realtime API guide · LiveKit Agents architecture · RFC 8825, WebRTC overview
Apply
Your turn
The task this lesson builds to.
Architect a customer-support voice agent handling 5,000 concurrent phone and mobile calls that looks up live order status, holds median mouth-to-ear turn latency under 500ms, and handles mid-sentence caller interruptions cleanly.
Think about
- How does audio move from PSTN telephony and mobile clients into your streaming worker without TCP head-of-line stalls?
- Where does every millisecond of the 500ms turn budget go across ASR, LLM TTFT, TTS TTFB, and network RTT?
- What exact state must be flushed or truncated the instant VAD triggers barge-in during an agent sentence?
- How do you run a 400ms order-status database lookup without creating awkward dead air or executing unsafe speculative writes?
Draft your design answer here Save your draft, compare against the model answer, and track progress.
Practice
Make it stick
A second problem on the same idea, so it survives past today.
Specify the transport, interruption, and tool-safety architecture for a bilingual telehealth triage voice agent operating over congested cellular networks, where misheard dosages or duplicate prescription refills are unacceptable.
Think about
- How does congested cellular packet loss change your transport, codec, and ASR confidence strategy?
- Why does high-stakes dosage collection favor a cascaded pipeline with explicit read-back over pure native S2S?
- What stops a choppy barge-in or network retry from triggering two refill requests?
Draft your design answer here Save your draft, compare against the model answer, and track progress.