# Design a Voice Agent

> How to design a voice agent: the call loop, the wait before the first word, letting callers interrupt, and safe tools, explained simply for your AI interview.

**In short:** A voice agent is an AI that talks with a caller in real time. It needs a sound link, a turn detector that spots when the caller stops, a model with tools, and speech out, with a code check before any action. The hard parts are the wait before the first word and letting callers interrupt.

AI and LLM interview question Q361, LLM system design. Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/design-a-voice-agent

## Say it in 30 seconds

A voice agent is an AI that talks on a phone line or in an app. I build it as a loop: a link that carries the sound, a turn detector that spots when the caller has finished, a model that asks my systems for facts, and speech back out. The hard part is timing. I budget the wait before the first word, let callers cut in, and check every money action in code before it runs.

## Say it in 2 minutes

Think of a bank's call-centre agent on the card line at two in the morning. They listen, check the account on screen, and speak back. A voice agent does the same loop, but it has to keep up with a real person. If the reply takes three seconds to start, the caller says hello again, and trust drops.

I would build it as a loop of five parts. A phone link or an app link carries the sound. A turn detector decides when the caller has stopped. A model decides what to say, and its tools ask the bank's systems for facts. Speech goes back out, and the caller can cut in at any point. Every money or account change passes a check in my code before it runs, and a person takes over when the case is unclear.

Latency is the number I watch most. I add up the silence rule, speech to text, the model's first words, the lookup and speech out. I start the lookup beside the model when the first words do not need its result. Then I test with scripted callers who interrupt, pause and mumble, and I track the slow calls (the 95th percentile), not only the average.

I also say where it is hard. A short silence rule answers fast but cuts people off mid-thought, and a model can still get facts wrong. So I keep the limits in code, log every call, and measure task success along with speed.

## What is a voice agent, in plain words?

A voice agent is an AI that talks with a person on a phone line or in an app, while the conversation happens. It hears, decides what to do, and speaks back. Getting the words right is the simple part. Timing is where it gets hard, because a pause that feels normal to a person can feel broken to a caller.

Picture a bank's call-centre agent on the card line at two in the morning. They listen, check the account on screen, and answer. A voice agent runs the same loop, but it has to keep pace with the caller.

A real case: a customer reports a lost card late at night. The agent must check who they are, freeze the card, read back the last four digits, and hand any fraud claim to a person.

- **Turn:** One thing the caller says, then the agent's reply.
- **Turn detector:** The part that decides the caller has finished speaking.
- **Barge-in:** The caller talks over the agent, and the agent should stop.
- **Time to first word:** How long the caller sits in silence before the agent starts talking.
- **Latency:** The delay the caller feels between their last word and the agent's first word.

## How does one caller turn flow through the system?

Five parts work as a loop: a link, a turn detector, a model, its tools, and speech out. The link carries the sound. Phone calls can come in through a SIP trunk (a phone connection that runs over the internet), as OpenAI's phone guide describes. An app uses a browser connection. The turn detector watches for the end of speech. The model decides what to say, and its tools fetch facts. Speech out turns the reply into sound.

> "The key design choice is how speech connects to reasoning and tools: a continuous conversation with a separate backend, a single voice model, or a pipeline you control stage by stage." (OpenAI)

The first choice is how the sound reaches the model. A speech-to-speech model hears sound and speaks sound back in one step. A pipeline chains separate steps: speech to text, a text model, then text to speech. Either way the loop stays the same: the model asks for facts and proposes actions, and your code runs them after its checks.

*Diagram, One caller turn, end to end: One caller turn. The link carries the sound in, a turn detector decides the caller has finished, and the model asks your systems for facts. The result loops back to the model before the reply is spoken.*
1. The caller speaks into the phone line or the app.
2. The link passes the sound on to a turn detector.
3. When the caller stops, the model takes the turn.
4. The model asks your system for the facts it needs.
5. The result comes back, and the model uses it.
6. The reply goes to speech, which starts playing.
7. The caller hears it, and can cut in at any time.

On a phone line, the telephone provider carries the call audio, and your backend handles the session settings, the call controls and the business logic. OpenAI's guide for phone calls describes the same split.

## Where does the wait before the first word come from?

Callers feel silence on a call, so the wait before the first word matters. Four things add up before the first word plays: the turn detector waiting for quiet, speech to text, the model's first words, and speech out. The bank's own lookup adds time too.

OpenAI's latency guide calls the model's start-up time "time to first token", and says it "measures how long an API request takes to start returning content". Each step in a row adds its own wait. The guide is blunt: "Each sequential model or tool call adds another wait." The fix is to run independent work at the same time: "Run independent work concurrently."

A read-only lookup (one that reads data and changes nothing) can start earlier still, as soon as the words so far point to it. The guide's advice for an uncertain branch is to "consider starting a read-only lookup early and discarding it if it's unnecessary".

*Diagram, Where the first word comes from: Where the first word comes from, with made-up timings. The silence rule waits for quiet (500 ms here, cut to 250 ms later). The model and the card lookup start together, but a reply that needs the lookup still waits for it.*
1. The clock starts when the caller stops talking.
2. The silence rule waits for quiet, then speech to text runs.
3. The model starts its first words as soon as the text is ready.
4. A read-only lookup can start from the words, in your system.
5. Speech out begins once the model's words arrive.
6. Speech out also waits for the lookup, if that is slower.
7. The caller hears the first word after 1450 ms, made-up timings.

Here is the budget as a simple program. It is a simplified sum, not a measurement. In a real system I time each stage on real calls.

```python
# One caller turn on a bank's card line (simulated, made-up timings in milliseconds).
BUDGET_MS = 1200  # target: the caller hears the first word within 1.2 seconds

def first_word_ms(silence, speech_to_text, model_first, lookup, speak, network, parallel):
    # Parallel only when the first words do not need the lookup result.
    wait = max(model_first, lookup) if parallel else model_first + lookup
    return silence + speech_to_text + wait + speak + network

def barge_in(agent_talking, caller_ms):
    # The caller talking over the agent for 200 ms or more counts as a cut-in.
    if agent_talking and caller_ms >= 200:
        return "stop audio, keep what was already said"
    return "keep talking"

for parallel in (False, True):
    total = first_word_ms(500, 250, 300, 350, 200, 150, parallel)
    label = "parallel" if parallel else "one after another"
    print(label + ": first word at " + str(total) + " ms")
    print("  over budget by " + str(total - BUDGET_MS) + " ms" if total > BUDGET_MS else "  within budget")
total = first_word_ms(250, 250, 300, 350, 200, 150, True)
print("parallel, 250 ms silence rule: first word at " + str(total) + " ms")
print("  within budget" if total <= BUDGET_MS else "  over budget")
print("Caller cuts in:", barge_in(True, 260))
print("Caller only breathes:", barge_in(True, 80))
```

Output:

```text
one after another: first word at 1750 ms
  over budget by 550 ms
parallel: first word at 1450 ms
  over budget by 250 ms
parallel, 250 ms silence rule: first word at 1200 ms
  within budget
Caller cuts in: stop audio, keep what was already said
Caller only breathes: keep talking
```

With the made-up timings, the 250 ms silence rule brings the wait to the 1200 ms target. It has a cost: callers who pause to think get cut off. Test it with real pauses before you ship it, and check the cut-offs too.

## How do you let the caller interrupt the agent?

A caller who talks over the agent is normal. People cut in when they hear the answer they need, or when they hear a wrong one. The system has to notice the caller's voice while the agent is still speaking, stop the audio at once, and listen.

1. **Keep listening while the agent speaks:** Keep the turn detector running during speech, so a cut-in can be heard.
2. **Stop the audio at once:** Cut the playing audio, so the caller does not hear the agent repeat itself.
3. **Log what was actually heard:** Keep the part of the reply the caller heard, so the next turn starts from the right place.
4. **Treat the new words as the next turn:** The caller's cut-in is simply the next thing to answer.

Two settings matter most. OpenAI's guide says: "A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments." That helps on a busy street, but it can miss a quiet cut-in. The guide also says: "With shorter values turns will be detected more quickly." That is the silence rule again.

A newer mode, semantic detection, decides the caller has finished from the words they have said, with a timeout behind it. OpenAI's guide says: "With this mode, the model is less likely to interrupt the user during a speech-to-speech conversation, or chunk a transcript before the user is done speaking." It suits callers who pause mid-thought, but it is a setting to test on your own calls.

> **Tip:** Watch for the agent hearing itself. Its own voice can come back into the microphone and look like a cut-in. Use echo cancellation (the part that removes the agent's own voice from the microphone) on the audio link, and test with the speaker on.

## What must the agent never get wrong, and how do you test it?

Voice makes mistakes feel personal. The agent must not read out an account to someone who has not proved who they are, and it must not freeze or move money on a guess.

- **Identity: Check before facts.** Verify the caller in code before any balance or card detail is read out.
- **Money or card: Code says yes.** A freeze, transfer or refund runs only after code checks the card and the caller, and the caller confirms it aloud.
- **Unclear case: Hand to a person.** When the request is outside the rules, or the model is unsure, the call moves to a human with a short summary.

> "Route privileged calls through a deterministic policy engine that re-validates intent and arguments at execution time." (OWASP 2026)
>
> "Wait for required checks before displaying a result or taking an action such as issuing a refund." (OpenAI)

The checks in code are the part that holds. Treat the model as one layer, with code checks behind it. OpenAI's voice agents guide says its session "handles audio turns, tools, interruptions, and handoffs", so the design must decide in advance what the session may do alone and what it must pass to a person.

Testing needs scripted callers, because each live call is a new conversation. OpenAI's guide puts it plainly: "Repeat scenarios and compare task completion, audible response latency, interruptions, and unwanted silence." So I write callers who pause for two seconds, cut in mid-sentence, mumble a card number, or come through a bad line.

- **Task done:** Did the card get frozen once, and only once, after the check?
- **Speed:** The typical wait (the median), and the 95th percentile: the wait that 19 calls in 20 beat. Measure both on the scripted calls and on representative traffic.
- **Cut-ins:** Did the agent stop quickly, and did the log match what the caller heard?
- **Silence:** How often did the caller sit in silence for too long?

> **Tip:** Run each scenario many times, with a few voices and noise levels. The 95th percentile shows the slow calls that the average hides.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A loop with its parts named: link, turn detector, model, tools, speech out.
- [ ] A first-word budget, with the slowest stage named.
- [ ] The lookup runs beside the model when the reply does not need it, and a read-only lookup can start early.
- [ ] Interruptions handled: listen during speech, stop the audio, log what was heard.
- [ ] Every money or account action checked in code, with a person for unclear cases.
- [ ] Testing with scripted callers and percentiles, not one good demo call.

**Common traps**

- Trap: "The model is the whole system." Better: The model is one part. The link, turn detector, code checks, logs and human handoff carry much of the risk.
- Trap: "We make the silence rule as short as possible." Better: A short rule cuts people off. Choose it with real pauses, then measure the cut-offs too.
- Trap: "One good demo call proves it works." Better: One call proves little. Run the scenario set many times and track the wait at the 95th percentile.

## Can you spot the problem?

**Spot the cut-in bug:** A caller on the card line talks over the agent. Which snippet lets them cut in?

A. play_audio(reply)  # the caller waits until the agent finishes
B. if caller_ms >= 200: stop_audio()  # stop when the caller talks over it
C. time.sleep(3)  # wait for the reply before listening again
D. log(reply)  # logged after the caller hears it

**Answer:** B. Only the second one watches for the caller while the agent talks, and stops the audio. The others make the caller wait, or log the wrong moment.

**Quick check:** A bank's voice agent answers in about 2.4 seconds, mostly while the silence rule waits. What is the first change to try?

A. A bigger model
B. Shorten the silence rule, then test cut-offs with real pauses
C. Remove the turn detector
D. Read the whole reply before speaking

**Answer:** B. The silence rule is the biggest wait here, and shortening it is the quickest fix. Testing cut-offs stops the fix from cutting callers off. A bigger model does not touch that wait, and removing the detector or reading the whole reply makes things worse.

## Can you answer these from memory?

**Flash cards**

- **What is a voice agent?** An AI that talks with a caller in real time, with tools and checks behind it.
- **What is a turn detector?** The part that decides the caller has finished speaking.
- **What is barge-in?** The caller talks over the agent, and the agent stops speaking at once.
- **What adds to the wait before the first word?** Silence rule, speech to text, the slower of model or lookup, and speech out.
- **How do you run the model and the lookup?** Side by side, if the first words do not need the lookup. Otherwise the reply waits for it.
- **Who checks a money action?** Your code, after the caller confirms. The model only asks for it.

## Likely follow-up questions

- Q445 ASR + LLM + TTS pipeline vs speech-to-speech models? https://designervenkat.online/interview/ai/asr-llm-tts-pipeline-vs-speech-to-speech-models
- Q369 How do you design for low latency? https://designervenkat.online/interview/ai/how-do-you-design-for-low-latency
- Q366 Design human approval for risky agent actions. https://designervenkat.online/interview/ai/design-human-approval-for-risky-agent-actions
- Q344 What is a p95/p99 latency budget? https://designervenkat.online/interview/ai/what-is-a-p95-p99-latency-budget
- Q172 When and how do you add a human in the loop? https://designervenkat.online/interview/ai/human-in-the-loop-for-ai-agents

## Learn it in depth

- [Watching cost and speed](https://designervenkat.online/learn/ai-engineering/cost-latency-monitoring)
