Bottom Linear Gradient  Lines image

Article

6 min

read

Test and Monitor a Voice AI Agent in Production

Replay tests, a fake audience, and a second AI that grades every reply

Adam Kalsey

Adam Kalsey

EVP, Product

Test and Monitor a Voice AI Agent in Production

In this article

Share

Angular Gradient Image

Build it free.

Create a space and ship your first call flow in minutes.

Subscribe

Tags

Voice AI

AI Agents

Developer Tutorials

This post closes a nine-part tutorial on building a talking jack-o'-lantern, and if you're new to the series, start with part 1. In part 8 the pumpkin got an operator. In this part I test it without any visitors, and then I watch it while it runs for a whole night.

An agent like this needs more than one kind of test. Unit tests check the logic, and a replay of a recorded night checks the wiring between that logic and the platform. A real call with a fake audience checks everything together. Once the night starts, a second AI grades every reply while a live log shows me what's happening.

Test without a call

Most of the pumpkin's logic is plain code, so it gets plain tests. Node tests cover the stage detection from part 5, and Python tests cover the visit state and pacing from part 7. The stage tests run scripted scenes with timer jitter built in, because real browser timers wander.

The agent's own pieces can be tested without a call too, using swaig-test from our Python SDK. Part 2 used it to print the SWML, and part 3 used it to run a tool with chosen arguments and global_data.

uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --list-tools
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --raw \
  --exec notice_visitors --youngest young_child --anyone_scared false
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --list-tools
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --raw \
  --exec notice_visitors --youngest young_child --anyone_scared false
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --list-tools
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --raw \
  --exec notice_visitors --youngest young_child --anyone_scared false
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --list-tools
uvx --from signalwire-sdk --with requests swaig-test pumpkin_agent.py --raw \
  --exec notice_visitors --youngest young_child --anyone_scared false

Replay a recorded night

Unit tests check each piece alone, but the wiring between the pieces holds bugs of its own. To find those, I replay a recorded night through the real server code. The live log, which I describe below, records every event from a night: arrivals, what was said, every tool call, and every context change. The replay feeds those events back through the server's actual routes and tool handling.

The replay takes the model's tool calls from the recording, and they stand for what the model would have tried. A small model of the platform sits between the server and the recording. It applies each tool result's context and step changes, and it offers only the tools each step lists. A four-hour night replays in about 25 seconds and ends in a report.

Visits:        102, plus 27 hellos to passersby
Wrong mode:    9.4 minutes (the platform's context vs the server's choice)
Tool calls:    426 replayed; 105 not offered in that step; 168 assumed after a message asked for one
Corrections:   24; switches refused: 24
Messages:      232 said into the call by the server, 38 of them asking for a tool call after 8 seconds in the wrong mode
Restarts:      5
Alarms:        10
Conversation:  largest 4805 tokens of dialogue and injected text in one context
Visits:        102, plus 27 hellos to passersby
Wrong mode:    9.4 minutes (the platform's context vs the server's choice)
Tool calls:    426 replayed; 105 not offered in that step; 168 assumed after a message asked for one
Corrections:   24; switches refused: 24
Messages:      232 said into the call by the server, 38 of them asking for a tool call after 8 seconds in the wrong mode
Restarts:      5
Alarms:        10
Conversation:  largest 4805 tokens of dialogue and injected text in one context
Visits:        102, plus 27 hellos to passersby
Wrong mode:    9.4 minutes (the platform's context vs the server's choice)
Tool calls:    426 replayed; 105 not offered in that step; 168 assumed after a message asked for one
Corrections:   24; switches refused: 24
Messages:      232 said into the call by the server, 38 of them asking for a tool call after 8 seconds in the wrong mode
Restarts:      5
Alarms:        10
Conversation:  largest 4805 tokens of dialogue and injected text in one context
Visits:        102, plus 27 hellos to passersby
Wrong mode:    9.4 minutes (the platform's context vs the server's choice)
Tool calls:    426 replayed; 105 not offered in that step; 168 assumed after a message asked for one
Corrections:   24; switches refused: 24
Messages:      232 said into the call by the server, 38 of them asking for a tool call after 8 seconds in the wrong mode
Restarts:      5
Alarms:        10
Conversation:  largest 4805 tokens of dialogue and injected text in one context

"Wrong mode" is the number to watch. It counts the minutes when the platform's context disagreed with the server's choice, broken down by kind. Any change to the visit state shows up there as fewer minutes or more. "Not offered" lists the tools the model tried to call in a step that doesn't list them. Each of those points to a prompt that names the wrong tool or to a step that's missing one.

A real call with a fake audience

The replay can't test the call itself, meaning the voice, the vision, and the page. I test those with a real call and a fake audience. Chrome can use a video file as its camera and an audio file as its microphone.

open -na "Google Chrome" --args --user-data-dir=/tmp/pumpkin-test --no-first-run \
  --use-fake-ui-for-media-stream --use-fake-device-for-media-stream \
  --disable-features=AudioServiceSandbox,AudioServiceOutOfProcess \
  --use-file-for-fake-video-capture=camera.mjpeg \
  --use-file-for-fake-audio-capture

open -na "Google Chrome" --args --user-data-dir=/tmp/pumpkin-test --no-first-run \
  --use-fake-ui-for-media-stream --use-fake-device-for-media-stream \
  --disable-features=AudioServiceSandbox,AudioServiceOutOfProcess \
  --use-file-for-fake-video-capture=camera.mjpeg \
  --use-file-for-fake-audio-capture

open -na "Google Chrome" --args --user-data-dir=/tmp/pumpkin-test --no-first-run \
  --use-fake-ui-for-media-stream --use-fake-device-for-media-stream \
  --disable-features=AudioServiceSandbox,AudioServiceOutOfProcess \
  --use-file-for-fake-video-capture=camera.mjpeg \
  --use-file-for-fake-audio-capture

open -na "Google Chrome" --args --user-data-dir=/tmp/pumpkin-test --no-first-run \
  --use-fake-ui-for-media-stream --use-fake-device-for-media-stream \
  --disable-features=AudioServiceSandbox,AudioServiceOutOfProcess \
  --use-file-for-fake-video-capture=camera.mjpeg \
  --use-file-for-fake-audio-capture

The camera file is a Motion-JPEG movie that ffmpeg builds from still pictures. Those pictures are AI-generated to avoid privacy concerns with photos of kids. It shows an empty yard, a group of teenagers, and a small child with a parent. The mic file holds lines spoken with macOS's say command, which ffmpeg places on a timeline and mixes into one WAV. On macOS, Chrome's audio sandbox has to be off, or Chrome never reads the WAV and the fake mic stays silent. I press Start on the page, let it run, and read the result back from the live log.

Grade every reply

A whole night is one long call with a hundred shows, so a summary at the end comes too late to act on anything. Instead I attach our AI sidecar, a second AI on the same call that listens and never speaks. It gets its own prompt, which describes the character the way a reviewer would. For each visitor's line it predicts what the pumpkin should say, and then it grades what the pumpkin actually said.

return {
    "prompt": {"pom": SPEC},
    "lang": "en-US",
    "model": "gpt-4.1-mini",
    "direction": ["remote-caller", "local-caller"],
    "customer_role": "remote-caller",
    "url": f"{authed}/events",
    "hints": hints,
    "SWAIG": {"defaults": {"web_hook_url": f"{authed}/swaig"}, "functions": TOOLS},
    # Report-only: nothing it does can change the call.
    "params": {"act_on_channel": False, "max_history_tokens": 16000, "idle_timeout_ms": 400,
               "max_iters_per_tick": 5},
}
return {
    "prompt": {"pom": SPEC},
    "lang": "en-US",
    "model": "gpt-4.1-mini",
    "direction": ["remote-caller", "local-caller"],
    "customer_role": "remote-caller",
    "url": f"{authed}/events",
    "hints": hints,
    "SWAIG": {"defaults": {"web_hook_url": f"{authed}/swaig"}, "functions": TOOLS},
    # Report-only: nothing it does can change the call.
    "params": {"act_on_channel": False, "max_history_tokens": 16000, "idle_timeout_ms": 400,
               "max_iters_per_tick": 5},
}
return {
    "prompt": {"pom": SPEC},
    "lang": "en-US",
    "model": "gpt-4.1-mini",
    "direction": ["remote-caller", "local-caller"],
    "customer_role": "remote-caller",
    "url": f"{authed}/events",
    "hints": hints,
    "SWAIG": {"defaults": {"web_hook_url": f"{authed}/swaig"}, "functions": TOOLS},
    # Report-only: nothing it does can change the call.
    "params": {"act_on_channel": False, "max_history_tokens": 16000, "idle_timeout_ms": 400,
               "max_iters_per_tick": 5},
}
return {
    "prompt": {"pom": SPEC},
    "lang": "en-US",
    "model": "gpt-4.1-mini",
    "direction": ["remote-caller", "local-caller"],
    "customer_role": "remote-caller",
    "url": f"{authed}/events",
    "hints": hints,
    "SWAIG": {"defaults": {"web_hook_url": f"{authed}/swaig"}, "functions": TOOLS},
    # Report-only: nothing it does can change the call.
    "params": {"act_on_channel": False, "max_history_tokens": 16000, "idle_timeout_ms": 400,
               "max_iters_per_tick": 5},
}

The sidecar hears only speech. It doesn't know which mode the pumpkin is in, which tools it called, or that the stage camera has reported a group leaving. Left with speech alone, it grades correct behavior as wrong, and a gentle line to a child looks like the character going soft. So my server fills it in with a short note on every mode change, every tool call, and the shoo point from part 7. Its grades go to a page that lists problems first, and a script turns them into a report, grouped by problem, for tuning.

Watch it live

The live log is one compact line per debug event, covering what visitors said, what the pumpkin said, every tool call, and every step change. I can read it from my phone during the show. On Halloween that's how I found that visitors kept holding things up and asking "what is this?" The pumpkin didn't know what people were looking at, so it had no good answer and kept claiming it was blind. That night I shipped a new tool, guess_what_it_is, which gives a confidently wrong verdict without looking.

Deploy without dropping the call

The call runs all night, so a deploy can't end it. The tests run before every deploy. The container mounts the code read-only, and a file watcher restarts only the Python process when a .py file changes. A filter keeps a change to the page or a log file from restarting anything.

class CodeAndSurroundings(PythonFilter):
    def __call__(self, change, path):
        return path.endswith("/surroundings.txt") or super().__call__(change, path)
class CodeAndSurroundings(PythonFilter):
    def __call__(self, change, path):
        return path.endswith("/surroundings.txt") or super().__call__(change, path)
class CodeAndSurroundings(PythonFilter):
    def __call__(self, change, path):
        return path.endswith("/surroundings.txt") or super().__call__(change, path)
class CodeAndSurroundings(PythonFilter):
    def __call__(self, change, path):
        return path.endswith("/surroundings.txt") or super().__call__(change, path)

After a deploy, /version reports which commit the process started from. A deploy counts as done only when that commit matches, so a crash on start can't hide behind the old process.

Traps to avoid

Don't stop at testing the logic. Replay through the real server code as well, because the wiring between the pieces holds bugs the logic doesn't.

Don't drive Web Audio tests with Playwright on macOS. In a Playwright-driven browser, audio worklets never finish loading. Use a normal Chrome window instead, with Chrome's audio sandbox turned off for the fake mic.

Don't give a grader only what it hears. Tell it the mode and the events it can't hear, or it'll grade correct behavior as wrong.

The code

The ai-jackolantern repository has the complete code for all nine parts. This is the actual running code that ran 366 visits on Halloween night this year.

The series

  1. The system and the call.

  2. The agent: a personality and three modes, as contexts and steps.

  3. Tools: what the AI calls on my server, and why its material lives in code.

  4. Vision: letting the agent see, and checking the camera before any decision that matters.

  5. The stage: detecting who is standing in front of the pumpkin, in the browser.

  6. The voice: audio effects in the browser.

  7. Pacing and state: the server keeps score.

  8. The operator: a person with a phone who can overrule the agent.

  9. Testing it, and running it for a whole night (this post).

Bottom Linear Gradient  Lines image

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.

The Communications Stack for What's Next

APIs built for speed. Infrastructure built for scale. AI built in from day one.