How do you debug a bad voice agent call with traces and recordings?
- Authors
- Name
- Amit Shekhar
- Published on
We debug a bad voice agent call by first listening to its recording to hear what went wrong, and then opening its trace at the same moment to see which step inside the agent caused it.
In this blog, we will learn about how to debug a bad voice agent call with traces and recordings. We will also see what makes a call bad, what a recording and a trace are, what we must save at each step and how to add it in code, how to line up the recording with the trace, how to find the real cause of common bad calls, and how to turn a bad call into a test so that it does not happen again.
We will cover the following:
- What is a bad voice agent call?
- Why is debugging a voice agent hard?
- What is a call recording?
- What is a trace?
- What must we save in each step?
- How do we add tracing in code?
- How do we line up the recording with the trace?
- Step-by-step debugging of a bad call
- Common bad calls and what the trace shows
- Turning a bad call into a test
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
What is a bad voice agent call?
A voice agent is a system built around an LLM that listens to what a person says and speaks back a reply, over a phone call or an app.
Many voice agents work as a pipeline of steps. Every time the user speaks, the audio passes through these steps one after another:
- Speech-to-Text (STT): It converts the user's voice into text. This text is called the transcript.
- Turn detection: It decides when the user has finished speaking, so that the agent knows when to reply.
- LLM (Large Language Model): It reads the transcript and decides what to say back. It can also recommend a tool call, such as looking up an order in a database, and our code runs that tool.
- Text-to-Speech (TTS): It converts the reply text back into voice.
A bad call is any call where the user had a poor experience. For example:
- The agent took too long to reply, and the user said "Hello? Are you there?"
- The agent gave a wrong answer.
- The agent started talking while the user was still speaking.
- The agent did not stop when the user interrupted it.
- The agent said a name or a number in a strange way.
- The call ended suddenly.
A complaint tells us only the symptom, like "the agent did not understand me." Our job is to find the real cause.
Why is debugging a voice agent hard?
Let's say a user complains: "I told the agent my order number, and it told me about some other order."
Now, the question is: which step went wrong?
- The STT heard the number wrongly.
- The STT was right, but the LLM mixed up the digits.
- The LLM was right, but the tool returned the wrong order.
- Everything was right, but the TTS spoke the number in a confusing way.
Any of these four can be the cause, and all four give the same symptom.
There is one more problem. In a conversation, a delay of two seconds feels very long. If we only read the final chat log, we cannot see these delays, we cannot hear the background noise, and we cannot see who was talking over whom.
So, we need two things:
- Something that tells us what the user actually experienced. This is the recording.
- Something that tells us what happened inside the agent, step by step, with time. This is the trace.
Here comes the combination of recordings and traces into the picture. Let's understand each of them.
What is a call recording?
A call recording is the saved audio of the full call, from the first second to the last. It is exactly what the user heard and said.
The best way is to record the call in two channels, which means the user's voice is saved on one channel and the agent's voice is saved on the other channel, like the left and right sides of a stereo file.
Two channels help us in three ways:
- We can see when both the user and the agent were talking at the same time.
- We can listen to only the user's side to check background noise or an unclear word.
- We can measure the silence gap between the user stopping and the agent starting.
In an audio tool, a two-channel recording shows one waveform for each speaker, like below:
Time (seconds) 0 1 2 3 4 5
|---------|---------|---------|---------|---------|
User channel |||||||||||||| ||||||
Agent channel ||||||||||||||||||
Here, we can see two problems just by looking at the diagram. First, the user stops at 1.4 seconds, but the agent starts only at 2.8 seconds, so the user waits in silence for 1.4 seconds. Second, the user starts speaking again at 3.6 seconds while the agent is still talking, and the agent keeps talking till 4.6 seconds.
But, the recording only tells us what happened. It does not tell us why it happened. For that, we need the trace.
What is a trace?
A trace is a timeline of every step the agent performed during the call, with the start time, end time, input, and output of each step.
Each step inside the trace is called a span. For example, one STT step is a span, one LLM request is a span, and one TTS step is a span.
A trace is like the tracking page of a parcel: picked up at 10:02, reached the hub at 11:40, out for delivery at 14:15. If the parcel is late, the tracking page tells us exactly which stop took too long.
Usually, we organize it like below:
- One call = one trace. Every trace gets a unique ID. We store the same ID with the recording.
- One user turn = one parent span. A turn is one round of "user speaks, agent replies".
- Each step in the turn = one child span inside that turn.
Let's see what one turn looks like inside a trace:
Trace: call_8f2a (one call)
|
+-- Turn 3 12.40s -> 15.90s
|
+-- stt 12.40s -> 13.10s "where is order 4512"
|
+-- turn_detection 13.10s -> 13.60s user finished = yes
|
+-- llm 13.60s -> 15.20s first token at 14.90s
| |
| +-- tool: get_order 13.95s -> 14.70s order_id = 4512
|
+-- tts 15.20s -> 15.90s first audio at 15.45s
Here, we can notice a few things:
- The LLM span contains the tool span inside it, because our code ran the tool while the LLM request was in progress.
- From the moment the user stopped speaking (around 13.10s) to the first audio of the reply (15.45s), the user waited about 2.35 seconds.
- The biggest part of that wait is the LLM and the tool call.
This is how a trace shows us where the time went. We have a detailed blog on AI Agent Observability that explains traces and spans in depth.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
What must we save in each step?
A trace is useful only if we save the right details in each span. Every span must save any error that happened in it. Let's see what else we must save for each step.
STT span:
- The final transcript text.
- The confidence score, if the STT provides one. A low score means the STT was not sure about the words.
- The start and end time of the user's speech.
Turn detection span:
- When the agent decided that the user had finished speaking.
- How long the silence was before it decided.
LLM span:
- The full input sent to the LLM, which includes the system prompt and the conversation history.
- The full output text.
- The time to first token, which means how long the LLM took to produce the first piece of the reply.
- The number of input and output tokens.
Tool span:
- The tool name and the input it received.
- The output it returned, or the error.
TTS span:
- The exact text sent to the TTS.
- The time to first audio, which means how long it took before the first sound came out.
Interruption events:
- When the user started speaking while the agent was talking.
- Whether the agent stopped, and how quickly.
With these details, every span tells us both "what went in" and "what came out", and we will use this in the debugging steps.
How do we add tracing in code?
A common choice is OpenTelemetry, which is an open standard for creating traces and spans. Many tracing tools can read it.
Let's see the code for adding spans around the steps of one turn in Python:
from opentelemetry import trace
tracer = trace.get_tracer("voice-agent")
def handle_turn(call_id, audio):
with tracer.start_as_current_span("turn") as turn_span:
turn_span.set_attribute("call.id", call_id)
with tracer.start_as_current_span("stt") as span:
transcript, confidence = speech_to_text(audio)
span.set_attribute("stt.transcript", transcript)
span.set_attribute("stt.confidence", confidence)
with tracer.start_as_current_span("llm") as span:
reply = run_llm(transcript)
span.set_attribute("llm.output", reply)
with tracer.start_as_current_span("tts") as span:
span.set_attribute("tts.input_text", reply)
speak(reply)
Here, we have:
- Created a
tracerwith the namevoice-agent. - Opened one
turnspan for the full turn, and saved thecall.idin it, so that we can find this trace from the recording later. - Opened a child span for each step:
stt,llm, andtts. Because they are opened inside theturnspan, they become its children automatically. - Saved the input and output of each step using
set_attribute.
The start time and end time of each span are recorded automatically when the with block starts and ends.
Here, I have kept only the important lines of the code and removed other lines for brevity. In a real agent, the steps are streamed, which means the TTS starts speaking before the LLM has finished the full reply, but the idea of spans stays the same.
To learn Monitoring and Logging, along with how to Design a Real-Time Voice AI Agent from the ground up, check out our AI and Machine Learning Program at Outcome School.
How do we line up the recording with the trace?
Now that we have learned about recordings and traces, it's time to learn how to use them together.
The recording and the trace are linked by two things:
- The same call ID. When we find the bad call, we can open both its recording and its trace.
- The same clock. The recording starts at second zero, but spans store the real clock time, like 10:15:32.40. So, we save the exact clock time when the recording started, and subtract it from every span time. Then, the second 12.40 in the recording is the same moment as the second 12.40 in the trace.
If the two clocks do not match, we will look at the wrong part of the trace and blame the wrong step.
Some voice observability tools show the waveform of the recording on top and the spans of the trace below it, on the same timeline, like below:
Time (s) 12 13 14 15 16
|---------|---------|---------|---------|
User audio |||||||
Agent audio ||||||
stt [=====]
turn_detection [===]
llm [==============]
tool: get_order [======]
tts [=====]
Here, we can see that the user stopped speaking at around 13.1 seconds, and the agent started speaking at around 15.5 seconds. The longest bar in between is the LLM span, and about half of it is the tool call.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
Step-by-step debugging of a bad call
The best way to learn this is by taking an example.
Let's say a user complains: "I said cancel order 4512, and the agent cancelled order 4521."
Step 1: We find the call. We search for the call using the user's phone number or the time of the complaint, and we get the call ID.
Step 2: We listen to the recording at the bad moment. We jump to the part where the user says the order number and listen to the user channel. The user says "four five one two". So, the user did not make the mistake.
Step 3: We open the trace at the same timestamp. We search the tracing tool with the call ID, and go to the turn that starts at the same second where the user said the number.
Step 4: We check each span in order and compare the input with the output. We start from the first step and move forward, like below:
- STT span: the transcript is "cancel order 4521". The user said 4512, but the STT wrote 4521. The confidence score is also low, which means the STT itself was not sure.
- LLM span: the input is "cancel order 4521", and the LLM correctly recommended the cancel tool with
order_id = 4521. Our code ran that tool. - Tool span: the tool cancelled order 4521, exactly as asked.
Step 5: We find the first span where the output is wrong. Here, it is the STT span. Every step after it worked correctly with the wrong input.
The rule of debugging a pipeline is: we must find the first step where a correct input became a wrong output. The steps after it only carried the mistake forward.
Step 6: We fix the real cause. Now, we know it is an STT problem with digits. Possible fixes are:
- Use an STT model or STT setting that handles spoken digits better.
- Make the agent read back the order number and ask the user to confirm before cancelling.
If we had only looked at the final chat log, we would have seen the LLM say "4521" and blamed the LLM. We would have changed the prompt, and the problem would still be there.
Common bad calls and what the trace shows
Now, let's see the most common bad calls, and where we must look in the recording and the trace.
| Symptom the user felt | What we check in the recording | What the trace usually shows |
|---|---|---|
| The agent was slow to reply | A long silence after the user stops | A long LLM time to first token, a slow tool, or slow TTS |
| The agent gave a wrong answer | What the user really said | A wrong STT transcript, or a right transcript and a wrong LLM reply |
| The agent cut the user off | The agent starts while the user still talks | Turn detection decided too early, often in a short pause |
| The agent did not stop when interrupted | Both channels have voice at the same time | No interruption event, or TTS kept playing after it |
| The agent said a word strangely | How the agent pronounced it | The exact text sent to TTS, such as "Dr." or a raw number |
| The agent forgot something said earlier | The user said it clearly earlier | The LLM input history does not contain that earlier part |
| The call ended suddenly | Where the audio stops | An error in a span, or a call-ending tool that ran |
Here, we can see that the recording is always our first check, because it is what the user heard. Then, the trace tells us which step is responsible.
One more thing to notice is the slow reply case. We must not guess which step is slow, we must read the span durations in the trace. For example, we suspect the LLM, but the trace shows that a database tool took 1.5 seconds.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
Turning a bad call into a test
Once we know the cause, we save the bad call as a test case. The recording and the trace give us everything we need:
- From the recording, we cut the user's audio for that turn, for example the clip where the user says "cancel order 4512".
- From the trace, we take the conversation history that the LLM received at that moment.
- We write the correct expected result, for example "the STT must write 4512" or "the agent must read back the number before cancelling".
For our example, the test feeds the saved audio clip into the STT and checks that the transcript contains "4512". A second test gives the saved history to the LLM and checks that it reads the number back to the user before recommending the cancel tool.
Now, every time we change the STT model, the prompt, or the turn detection settings, we run all these saved test cases again. If an old bug comes back, the test fails before the change reaches our users.
Now we must have understood how to debug a bad voice agent call with traces and recordings, how to line them up on the same timeline, how to find the first step that went wrong, and how to turn every bad call into a test.
Frequently Asked Questions
Should we check the recording or the trace first?
We check the recording first. The recording is exactly what the user heard and said, so it tells us what went wrong. Then, we open the trace at the same moment, because the trace shows which step inside the agent caused it.
Why should a voice agent call be recorded in two channels?
Because two channels save the user's voice and the agent's voice separately. This lets us see when both were talking at the same time, listen to only the user's side to check background noise or an unclear word, and measure the silence gap between the user stopping and the agent starting.
Can we debug a voice agent using only the chat log?
No. A chat log does not show the delays, we cannot hear the background noise, and we cannot see who was talking over whom. It can also make us blame the wrong step. For example, if the STT wrote the wrong number, the log shows the LLM saying it, and we would wrongly change the prompt.
What happens if the recording and the trace clocks do not match?
We look at the wrong part of the trace and blame the wrong step. The recording starts at second zero, but spans store the real clock time. So, we save the exact clock time when the recording started and subtract it from every span time, so that both use the same timeline.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
