Unexpected Call End
The unexpected call end metric checks whether your voice agent's call ended properly, not with the agent hanging up mid-conversation or with an error or timeout. It returns 1 when the call ended normally and 0 when it did not.
Required Arguments
To use the UnexpectedCallEndMetric, you'll have to provide a ConversationalTestCase with:
contenton each turn, to tell whether the call wrapped upmetadatasaying how the call ended, as theConversationSimulatorrecords it under"Stop reason", or as your platform records it under"end_reason"audioon at least one turn, or on the test case as a stereo recording of the whole call*, so it is a voice call
The audio is only used to place where the call ended.
* Full call audio has to be a 16-bit stereo WAV, with the caller and agent on separate channels, and is only used when no turn has audio. The call's end is then placed at the end of the recording.
Usage
The UnexpectedCallEndMetric() 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 UnexpectedCallEndMetric
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 = UnexpectedCallEndMetric(threshold=1.0)
evaluate(test_cases=test_cases, metrics=[metric])The UnexpectedCallEndMetric takes only the common voice metric parameters.
As a standalone
You can also run the UnexpectedCallEndMetric 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
A call that ended badly shows up in score_breakdown as one event. Here is what the example call returns:
{
"eligible_turns": 1,
"turns_with_events": 1,
"events": [
{
"type": "unexpected_end",
"turn": 3,
"duration_seconds": 0.0,
"start_time": 11.0,
"mark": "moment",
"timing_source": "turn_timestamps",
"description": "Call ended unexpectedly (agent_ended_call)",
"end_reason": "agent_ended_call",
}
],
"skipped": [],
}| Field | What it means |
|---|---|
end_reason | agent_ended_call when the simulator recorded the agent hanging up. Otherwise the test case's own end_reason, such as ERROR |
turn | The call's last turn, counting from 0. Missing with full call audio only |
reply_start | Full call audio only, in place of turn. Where the agent's last reply on the recording starts, in seconds into the call |
start_time | Where the call's last timed audio ends, in seconds into the call. With full call audio only, the end of the recording. Missing when no turn has an Audio.start_time |
duration_seconds | Always 0: the end is a single moment |
Every event also has the fields all voice events share, such as mark and description.
eligible_turns is always 1, the call, and turns_with_events is 1 when it ended badly.
How Is It Calculated?
The UnexpectedCallEndMetric score is calculated according to the following equation:
Counting calls
Each test case is one call, so there is one thing to judge: how it ended.
Ending criteria
The agent hanging up is only a problem if the call hadn't wrapped up. Above, a hang-up right after the question is unexpected, while one after the caller's goodbye is normal. The checks run in this order:
| Check | Rule |
|---|---|
| Error or timeout | The metadata end_reason (or endReason) is ERROR or IDLE_TIMEOUT, in any letter case. Always unexpected, however the call went |
| Wrapped up | The caller's last line ends in "bye", "goodbye", "thank you", "thanks", "that's all" or "that is all", ignoring trailing periods and exclamation marks, or the agent's last line contains the word "bye" or "goodbye". Then the end is normal |
| Agent hung up | The metadata "Stop reason" is "The agent ended the call", or end_reason is AGENT_HANGUP. Unexpected |
A call with none of these, such as a simulation that ran its full number of turns, ended normally. If neither the turns nor the test case have audio, the metric is skipped.
Example call
The caller asks a question and the agent hangs up instead of answering. Each row is one check and how this call fares on it.
| Check | This call | Result |
|---|---|---|
| Error or timeout | No end_reason | No |
| Wrapped up | Caller's last line is "Can I change the address?", agent's is "It ships tomorrow." | No |
| Agent hung up | "Stop reason" is "The agent ended the call" | Yes |
| 1 call | Ended unexpectedly → 0 |