Voice agent: a spoken conversation with a streaming pipeline
A voice agent listens, thinks, and speaks back in a few hundred milliseconds by streaming every stage. Use it for phone support, in-car help, and hands-free tasks where typing is a poor fit.
Voice agent in 60 seconds
- What: an agent you talk to, built from speech to text, an LLM with tools, and text to speech.
- Key idea: stream every stage, so each one starts working on partial output instead of waiting for the one before to finish.
- Best for: phone support, drive-time assistants, accessibility, and any setting where hands and eyes are busy.
- Weak spots: latency, noisy audio, mishearing names and numbers, and people interrupting mid-sentence.
- Design rule: keep spoken answers short, and let the user cut in at any time.
Where this type fits
In the hub, the voice agent sits in the family defined by the kind you build, next to the tool-using, coding, browser, and long-running agents. Its reasoning can be anything from a simple scripted flow to a full tool-using agent. What defines it is the medium: live speech, which brings strict timing demands. The multimodal and real-time page covers the wider topic of models that handle audio.
The problem it solves
Many people still prefer to talk. They call a helpline, they ask a question while driving, or they cannot use a screen at all. Old phone menus ('press 1 for billing') frustrate callers, because the menu decides what is possible, not the caller. Chat bots are better at understanding, but they need a screen and typing.
A naive way to add voice is to run the stages in order. Record the whole sentence, transcribe it, send it to the model, wait for the full reply, convert the full reply to audio, then play it. Each stage waits for the last. The delays add up, and the caller hears silence for several seconds. People read that silence as a dropped call, and they start talking again, which makes things worse.
A voice agent solves this by streaming. The transcriber emits words as they are heard. The model starts as soon as the speaker finishes. The speech engine starts speaking the first sentence while the model is still writing the second. The caller hears a reply within a fraction of a second. The same design also handles the other hard part of speech: people interrupt, and the agent must stop talking and listen.
How it works
- Capture: the microphone sends small audio frames, about twenty milliseconds each, over a live connection.
- Detect speech: a small model called voice activity detection marks when the caller starts and stops talking. A short silence, often around half a second, ends the turn.
- Speech to text: a transcriber turns audio into words, sending partial text while the person is still speaking and a final text at the end of the turn.
- Think: the LLM receives the text and recent history. It may call tools, such as a booking lookup. It streams its reply token by token.
- Text to speech: a speech engine receives the reply in sentence-sized pieces and produces audio for each one as soon as it arrives.
- Play and listen: the speaker plays audio while the microphone keeps listening. If the caller speaks, playback stops, the unplayed audio is dropped, and the agent returns to listening.
Read the diagram left to right as a relay, not a queue. Each stage hands over a small piece as soon as it has one, so the later stages are busy while the earlier ones are still working. The delay the caller feels is roughly the end-of-speech wait, plus the time to the model's first sentence, plus the speech engine's time to first audio.
The interrupt path matters as much as the main path. Without it, the agent talks over the person, which feels rude and wastes their time. When voice detection hears the caller during playback, the agent must stop audio at once, cancel the model's remaining output, and record only what was actually spoken in the history. Otherwise the model thinks the caller heard words they never did.
A worked example
A caller rings Acme Dental to move an appointment. Here is one turn with made-up timings.
- 0 ms. The caller finishes saying: 'Hi, I need to move my appointment from Tuesday to Thursday.'
- 500 ms. Voice detection sees half a second of silence and closes the turn. The transcriber has been sending partial text all along, so the final text is ready: 'Hi, I need to move my appointment from Tuesday to Thursday.'
- 550 ms. The LLM receives the text and decides it needs a tool. It calls
find_appointments(phone='caller id'). The tool returns one booking: Tuesday 14 April, 10:00, with Dr Rao. - 800 ms. The tool result is back. The LLM streams its reply and writes the first sentence: 'Sure, I can see your Tuesday appointment at ten.'
- 900 ms. The speech engine has that sentence and starts producing audio. The caller hears the voice begin.
- 1,000 ms to 2,500 ms. While the first sentence plays, the LLM writes the second: 'Would Thursday at ten, or Thursday at two, suit you better?' It is spoken straight after.
Partway through the second sentence the caller says 'Ten is fine'. Voice detection fires, playback stops, and the remaining unspoken words are dropped. The next turn starts with the history showing that the caller heard the offer of Thursday at ten, and chose it.
If the agent had waited for the full reply before speaking, the first audio would have come after about two seconds instead of under one.
Building it
The sketch below shows the core loop with an interrupt. The stt, llm, tts, and speaker objects are placeholders for whichever components you use, and no network calls are made here. The pattern to copy is the sentence-by-sentence hand-off, the cancel path, and the hard limits.
import time
END_OF_TURN_SILENCE_MS = 500 # shorter feels quick but cuts people off
MAX_TURN_SECONDS = 30 # stop a model or tool that hangs
MAX_REPLY_SENTENCES = 4 # spoken answers must stay short
# Placeholders: stt, llm, tts, speaker, and tools stand in for your own parts.
def handle_turn(audio_stream, history, stt, llm, tts, speaker, tools):
# 1. Collect words until the caller stops speaking.
text = stt.listen_until_silence(audio_stream, END_OF_TURN_SILENCE_MS)
if not text.strip():
return history # nothing heard, keep listening
history.append({'role': 'user', 'text': text})
started = time.time()
spoken = [] # only what the caller actually heard
sentences = 0
# 2. Stream the reply one sentence at a time.
for sentence in llm.stream_sentences(history, tools=tools):
if time.time() - started > MAX_TURN_SECONDS:
break # a hung tool must not hold the line
if sentences >= MAX_REPLY_SENTENCES:
break
# 3. Convert and play right away, without waiting for the full reply.
speaker.play(tts.synthesise(sentence))
sentences += 1
# 4. If the caller speaks while we play, stop at once.
if audio_stream.caller_is_speaking():
speaker.stop() # drop audio not yet played
llm.cancel() # stop paying for unused tokens
break
spoken.append(sentence)
# Why: record what was heard, so the model does not assume the rest was said.
history.append({'role': 'assistant', 'text': ' '.join(spoken)})
return historydef confirm_before_acting(action, speaker, tts, stt, audio_stream):
# Why: speech to text often mishears dates, names, and digits.
prompt = 'Just to check, you want ' + action['summary'] + '. Is that right?'
speaker.play(tts.synthesise(prompt))
answer = stt.listen_until_silence(audio_stream, 500)
return answer.strip().lower() in ('yes', 'yeah', 'correct', 'that is right')Design decisions
- Pipeline or one speech model: start with the three-stage pipeline. You can swap each part, log the text between them, and test each one. A single model that handles audio end to end can feel more natural, but is harder to inspect and control.
- Transport: use a live, low-delay connection such as a streaming socket or real-time media channel, not repeated web requests. Keep servers close to callers to cut network delay.
- End-of-turn timing: default to about half a second of silence, then tune on real calls. Too short cuts callers off mid-thought. Too long makes every reply feel slow.
- Answer length: instruct the model to speak in short sentences and give one idea at a time. Long answers are hard to follow by ear and cost time before the caller can respond.
- Tool latency: tools sit inside the spoken turn. Give each a strict timeout, run lookups in parallel where possible, and have the agent say a short filler such as 'one moment' if a lookup will exceed a second.
- Safety and privacy: voice calls carry personal data. Mask card numbers in transcripts, set retention limits, and tell callers when they are talking to an automated agent and when calls are recorded.
- Fallback: always offer a route to a person, and hand over the transcript so the caller does not repeat themselves.
Measuring it
- Response latency: the time from the caller's last word to the first audio played. Report the median and the 95th percentile, because slow outliers are what callers remember.
- Word error rate: compare transcripts with a human-made transcript for a sample of calls. Count substitutions, deletions, and insertions, and divide by the number of words in the reference.
- Task completion rate: the share of calls where the goal was met, such as the appointment being moved, checked against the booking system.
- Interruption handling: the share of interruptions where playback stopped within a set time, such as 300 milliseconds, measured from logs.
- Handover rate: the share of calls passed to a person, with reasons. A rise often points to a transcription or tool problem.
- Cost per minute: speech to text, LLM tokens, and speech output, added together and divided by call minutes.
When to use it, and when not to
| Situation | Use this type? | Why |
|---|---|---|
| Phone support for booking and status questions | Yes | Calls are short and structured, and callers like not waiting in a queue. |
| Hands-free help while driving or cooking | Yes | Speech is the only practical input. |
| Reading long documents or tables to a user | No | Dense information is easier to take in on a screen. |
| Taking card numbers or passwords by voice | Careful | Mishearing and eavesdropping risks are high, so use secure entry or a handover. |
| Very noisy places or heavy accents with no tuning | Test first | Transcription errors can wreck the experience unless you measure and adapt. |
| Emotional or high-stakes calls such as bereavement or fraud | Hand over | A person should take over early. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Quality | Natural to use, but mishearing names and numbers causes real errors. | Read key details back, and use confirmations before any change. |
| Latency | Every extra second feels like a long pause on a call. | Stream every stage, keep replies short, and set tool timeouts. |
| Cost | Three paid stages run for the whole call, including silence. | Cut idle listening, use smaller models for easy turns, and cap call length. |
| Complexity | Real-time audio, interruption, and telephony add hard engineering. | Start with a small set of call types and a clear handover path. |
| Failure modes | Talking over the caller, hanging tools, dropped audio, and bad transcripts. | Support barge-in, set timeouts, log transcripts, and review sampled calls. |
Compared with related types
A voice agent usually wraps a tool-using agent. The tool-using core decides what to look up or change. The voice layer adds timing, turn-taking, and interruption. The same reasoning that works in chat may need rewriting for speech, because spoken replies must be shorter and cannot rely on tables or links.
For the model side of real-time audio, see multimodal and real-time AI. For why first-token speed is hard, see inference and serving.
What this means for your role
Common mistakes
Further reading
- Types of AI agents: the hub that compares all agent types.
- Multimodal and real-time AI: how models handle audio and live streams.
- Inference and serving: why time to first token matters and how to improve it.
- Guardrails and safety: controls for personal data and risky actions.
A good voice agent is mostly a timing problem. Stream every stage, keep answers short, let people interrupt, and measure latency from the caller's point of view.