Response Latency
The response latency metric checks whether your voice agent answers without a long wait, rather than leaving the caller in silence after they finish speaking. It returns the share of agent replies that started in time, between 0 and 1.
Required Arguments
To use the ResponseLatencyMetric, you'll have to provide a ConversationalTestCase with at least one of:
audioon the test case, a 16-bit stereo WAV recording of the whole call*audioon the caller's and agent's turns, each with astart_time
Agent turns can also carry latency_ms, the response latency your connector recorded for that reply. It's only used with per-turn audio.
* Full call audio has to be a 16-bit stereo WAV, with the caller and agent on separate channels. Mono full call audio is ignored, because the two voices can't be told apart, and so is audio in any other format, such as MP3.
See How Is It Calculated for how each is used.
Usage
The ResponseLatencyMetric() can be used for end-to-end evaluation of voice calls, such as ones produced by the ConversationSimulator in voice mode:
from deepeval import evaluate
from deepeval.dataset import ConversationalGolden
from deepeval.metrics import ResponseLatencyMetric
from deepeval.simulator import ConversationSimulator
from deepeval.voice import ElevenLabsConnector, VoiceConfig
golden = ConversationalGolden(
scenario="The user asks the agent to look up an order by its number.",
expected_outcome="The agent reads back the order status.",
)
simulator = ConversationSimulator(
voice_config=VoiceConfig(
connector=ElevenLabsConnector(agent_id="your-agent-id"),
)
)
test_cases = simulator.simulate([golden])
metric = ResponseLatencyMetric(threshold=0.8, max_latency_seconds=4)
evaluate(test_cases=test_cases, metrics=[metric])There are TWO optional parameters specific to the ResponseLatencyMetric, on top of the common voice metric parameters:
- [Optional]
max_latency_seconds: an integer for the longest wait, in seconds, between the caller finishing and the agent starting to speak. Must be greater than 0. Defaulted to4. - [Optional]
use_speech_detection: a boolean which, when set toTrue, only counts the caller as talking when speech is detected, so background noise isn't mistaken for the caller and doesn't shorten or stretch a wait. With per-turn audio it's also used to find the agent's speech. Defaulted toTrue.
As a standalone
You can also run the ResponseLatencyMetric on a single test case as a standalone, one-off execution:
metric.measure(test_cases[0])
print(metric.score, metric.reason)
print(metric.score_breakdown)See Events for what score_breakdown contains.
Events
Each slow reply shows up in score_breakdown. Here is what the example call returns:
{
"eligible_turns": 3,
"turns_with_events": 1,
"events": [
{
"type": "slow_response",
"duration_seconds": 4.8,
"start_time": 10.0,
"mark": "range",
"timing_source": "call_recording",
"description": "Agent took 4.8s to reply",
"reply_start": 14.8,
"response_delay_seconds": 4.8,
}
],
"skipped": [
{"reply_start": 25.0, "error": "Agent started before the caller finished."}
],
"timing_source": "call_recording",
}| Field | What it means |
|---|---|
reply_start | When the slow reply started, in seconds into the call |
response_delay_seconds | How long the caller waited for it |
start_time | Where the wait begins: when the caller stopped talking |
duration_seconds | How long the wait lasted, the same as response_delay_seconds |
Every event also has the fields all voice events share, such as mark and description. Replies that couldn't be timed are listed under skipped with the reason. With per-turn audio, events and skipped entries carry turn, the index of the agent turn, instead of reply_start.
eligible_turns is how many agent replies were timed and turns_with_events how many were slow. The score is the share that weren't.
How Is It Calculated?
The ResponseLatencyMetric score is calculated according to the following equation:
With per-turn audio instead of full call audio, each agent clip that directly follows a caller clip is one reply, and the speech heard inside each clip is placed on the call's clock by its Audio.start_time. Events carry the agent turn's index, turn, instead of reply_start.
Counting agent replies
A reply is a timed reply that comes after the caller spoke. An opening line spoken before the caller makes any sound answers no one, so it isn't counted. Time to First Response times it instead.
Latency criteria
The wait runs from where the caller's speech ends to where the agent's speech starts.
With full call audio, that is the silence between the two channels, and latency_ms on the turns is ignored. With per-turn audio, an agent turn's latency_ms is the wait when it has one; otherwise the silence heard between the clips is used.
A reply is slow when:
| Check | Rule |
|---|---|
| Wait | More than max_latency_seconds, 4 seconds by default |
| Overlap | The agent starting up to 0.5 seconds before the caller finishes counts as no wait |
A reply isn't timed, and is listed under skipped, when:
- the agent started more than 0.5 seconds before the caller finished, which Agent Interruption judges instead,
- with per-turn audio, the caller's or the agent's clip can't be decoded, or
- with per-turn audio, the two clips touch with speech right up to where they meet, and there's no
latency_ms, so no silence can be heard.
If there's nothing to count, the metric is skipped.
Example call
A call where the agent is sometimes slow to answer. Each row is one agent reply and how long the caller waited for it.
| Agent reply | Wait | Slow? |
|---|---|---|
| 0.2 s | Greeting, before the caller spoke | Not counted |
| 5.4 s | 0.8 s | No |
| 14.8 s | 4.8 s | Yes |
| 20.6 s | 1.2 s | No |
| 25.0 s | Started 1.2 s before the caller finished | Skipped |
| 3 replies | 1 slow → 2/3 = 0.67 |
FAQs
Which wins, latency_ms or the audio?
latency_ms is ignored. With per-turn audio, latency_ms wins when the agent turn has one, and the silence heard between the clips is only used for turns without it.How is this different from turn-taking naturalness?
Does this metric call an LLM or an external speech model?
use_speech_detection on, it runs the small Silero VAD model locally.