Blog · · 4 min read
Voice Bot Testing with Simulated Callers
Prompt tweaks can quietly break a voice agent. Build automated tests with simulated callers, covering scenario design, connecting, and judging outcomes instead of wording.
Key points
- Give a simulated caller facts, a goal and a speaking style, voice its lines with text-to-speech, and compare the call outcome and collected fields against expectations to test conversations automatically.
- Beyond the happy path, scenarios should cover what real callers do, such as saying everything at once, correcting a phone number, asking for a human, going silent and hanging up.
- LLM conversations vary from run to run, so run each scenario several times and judge on outcomes and fields, not on exact wording.
Change one line of a voice agent's prompt and it may start asking questions in a different order or handing off when it shouldn't. Dialling in by hand after every change doesn't scale, so the fix is a simulated caller: an AI with a script that talks to your agent, after which you compare the call's outcome and collected fields against what you expected. Run the same scenarios on every config change and you catch regressions before your users do.
Why manual test calls aren't enough
Calling the agent yourself is still essential for judging how natural it sounds. But manual calls fall short in three ways:
- They aren't repeatable. You phrase things differently every time, so before-and-after comparisons are fuzzy.
- They skip the awkward paths. Nobody remembers to test "caller corrects their phone number" every time.
- They miss variance. An agent that forgets to ask for the callback number one time in ten looks fine on a single call.
Writing scenarios
A scenario pairs a caller persona with an expected result.
{
"id": "correction",
"note": "Caller corrects the phone number during read-back",
"persona": {
"facts": "Name is Sam Rivera. Mobile is 080-9876-5432 (a Japanese mobile number). Wants to book a tire change.",
"goal": "Book a tire change",
"style": "Gives the number with one digit wrong at first, then corrects it when it's read back."
},
"expect": { "outcome": "completed", "fields": { "phone": "08098765432" } }
}facts is what the caller knows, goal is why they're calling and style is how they behave. A useful starter set:
| Scenario | What it checks |
|---|---|
| Answers one question at a time | The basic flow collects every field |
| Says everything in the first sentence | The agent moves on without re-asking |
| Corrects a phone number | Read-back catches and fixes errors |
| Asks for a human | Ends in handoff |
| Asks an FAQ and hangs up | Ends as answered |
| Goes silent mid-call | The agent re-prompts instead of stalling |
| Hangs up early | Recorded as hangup |
| Unusual name or industry jargon | Recognition and read-back hold up |
Building the simulated caller
A simulated caller has three parts:
- Something that decides what to say. Give an LLM the persona and the agent's last reply, and have it produce the caller's next line. A fixed list of lines is fine for basic tests.
- A voice. Synthesize each line with text-to-speech. Using a different voice from the agent makes recordings easier to review.
- Turn-taking. Wait until the agent's reply has finished before speaking. If the caller talks too early, you're accidentally testing barge-in (barge-in and turn-taking).
Two ways to connect
| Connection | Pros | Cons |
|---|---|---|
| WebRTC session | No phone line needed, runs in CI | Audio quality differs from a phone call (Twilio streams 8 kHz μ-law) |
| Real phone call | Tests telephone audio and network delay end to end | Costs per call, hard to run in volume |
A practical split: run regression suites over WebRTC on every change, and a handful of real phone calls before a release. For the WebRTC side, see adding voice AI to web and mobile apps.
Judging results
Agent wording changes every run, so string-matching replies makes for flaky tests. Judge on:
- Outcome. Did it end as completed, answered, handoff or hangup?
- Collected fields. Normalize phone numbers to digits before comparing; check that names contain the expected value.
- Handoff reason. When it hands off, is the reason the one you expected?
- Pass rate. Run each scenario several times and track the share that passes. Block the release if it drops compared with the previous version.
For things that are hard to score, like politeness, have a person read transcripts or have a separate LLM grade them, and plan on a human reviewing and adjusting the grading criteria.
Doing this with voicast
In voicast, work in the test environment (API keys starting vk_test_). Create the candidate config as its own agent, separate from what tenants use, and pass its agent_id when creating a session. With output: 'text', the agent's replies arrive as text (voicast.reply) on the data channel, so the simulated caller can read them without speech recognition. The trade-off is that you're no longer testing speech synthesis or barge-in. When the session ends, fetch the result by the session id.
import os, re, requests
API = "https://api.voicast.jp"
H = {"Authorization": f"Bearer {os.environ['VOICAST_API_KEY']}"} # vk_test_…
def new_session(tenant_id: str, agent_id: str) -> dict:
r = requests.post(f"{API}/v1/sessions", headers=H,
json={"tenant_id": tenant_id, "agent_id": agent_id, "output": "text"})
r.raise_for_status()
return r.json() # the caller connects with client_token (2 minutes, single use) and webrtc_url
def judge(session_id: str, expect: dict) -> list[str]:
call = requests.get(f"{API}/v1/calls/by-provider/{session_id}", headers=H).json()
errors = []
if call["outcome"] != expect["outcome"]:
errors.append(f"outcome: {call['outcome']} (expected {expect['outcome']})")
for key, want in expect.get("fields", {}).items():
got = (call["fields"] or {}).get(key, "")
if key == "phone":
got = re.sub(r"\D", "", got)
if want not in got:
errors.append(f"{key}: {got!r} (expected {want!r})")
return errorsEach conversation record includes the agent version (agent.version), so you can log which version passed. Once it does, point the tenant at it with PATCH /v1/tenants/{id} and a new agent_id. See versioning voice agent configs safely for the rollout side. Calls in the test environment are billed by call time just like live ones.
FAQ
Do I need to run every scenario on every change?
Scope it to what changed. Prompt or field changes warrant the full suite; a voice or speaking-rate tweak only needs the basic scenarios.
If the simulated caller is an LLM, won't it make mistakes too?
Sometimes. Log the caller's lines as well, and when a scenario fails, check whether the agent or the caller went off script before changing anything. Fixed scripted lines remove this variance.
Can I build scenarios from production calls?
Calls that went wrong in production make great scenarios. Replace real names and numbers with invented ones before writing them into facts.