Back
PythonGoogle Gemini 3.5 FlashPipecat (WebRTC)Deepgram STTElevenLabs TTSSQLitepytestLLM-as-judge (GPT-5.5)

NightShift:After-Hours Voice Dispatcher for Plumbing & Heating

An after-hours voice agent for a plumbing and heating shop that triages calls into safety, emergency and routine, reads the address and callback number back, and pages the on-call tech only after the caller says yes. Five of its six rules are enforced in backend code, not just the prompt, and checked by a 40-scenario eval harness with a simulated caller.

Core Impact

“Scored 80/80 on a 40-scenario eval harness after fixing 6 bugs the evals found (baseline 76/80, a dev set I tuned against, not a held-out score), with voice latency on 16 real calls at p50 2.4s / p90 5.8s and no real pages or SMS sent since everything downstream is simulated.”

NightShift: After-Hours Voice Dispatcher for Plumbing & Heating

80/80

Eval pass rate after fixes (baseline 76/80, dev set)

6

Safety-critical rules checked by the eval harness

2.4s / 5.8s

Voice latency p50 / p90 on 16 real calls

The Problem

A plumbing and heating shop's phone goes to voicemail after hours, so a burst pipe at 2 AM has to wait until morning. I wanted something that could answer instead, work out how serious the call is, and act on it: give fixed safety instructions for a gas smell without ever booking over it, get the address and callback number read back and confirmed before paging the on-call tech for a real emergency, and handle routine bookings and price questions on its own.

The Approach

01

Why the rules live in code, not just the prompt

An agent that books jobs and wakes people up at night can't rely on the prompt alone. Confirm-before-acting, no booking on a safety call, callers only touching their own bookings by matching name and phone, phone numbers coming only from the caller, and never reading back a short 7-to-9-digit number are all enforced as backend gates the model can't talk its way around. Only the price-list rule is prompt-level, checked by the evals instead of hard-blocked.

02

Why one handle_turn() for text, voice and evals

Text mode, voice mode and the eval harness all call the same handle_turn() function in agent/core.py. The agent loop itself is hand-written, about 20 lines, which is what lets a gate sit between the model wanting to book something and the booking actually happening. Pipecat just swaps in handle_turn() for its own built-in LLM step to run the browser audio pipeline over WebRTC.

03

What the eval harness found

The 40 scenarios caught 6 real agent bugs: a strongly-worded gas smell that matched no safety keyword and got booked anyway, a spoken-word phone number that tripped the caller-only-digits gate, a tool call with a missing argument that crashed the turn, a page that got blocked but the agent claimed it happened anyway, a read-back guard firing on dates instead of just phone and address, and a spoken read-back plus a yes that still triggered a second read-back. Fixing all six took the score from 76/80 to 80/80.

04

Why a second LLM judges repetition

The pass/fail grader only checks the final database state and the tool-call trace, so it can't tell if the agent repeated itself out loud. A separate judge, gpt-5.5, reads each transcript and answers one question: does the agent repeat itself? It's a different model family from the Gemini agent to avoid self-preference bias, and it caught a double read-back the deterministic grader had no way to see. It's not calibrated against human labels, so I treat it as a rough signal, not a score.

05

What voice testing caught that text testing missed

Three bugs only showed up once I was actually talking to the thing: a short pause getting treated as the end of a turn and cutting the caller off mid-sentence, the agent recording the read-back details internally but never actually saying them out loud, and a phone number ending in three zeros getting silently corrected to four. That last one is exactly what gate 5 exists to block now.

Technical Deep Dive

01

Triages every call into safety, emergency or routine lanes, with 5 of 6 rules enforced in backend code (not just the prompt) so a gas-smell call can never be booked and no booking, reschedule, cancel or page happens unless the caller already heard the details read back and said yes.

02

Built a 40-scenario eval harness: a simulated caller (`gemini-3.5-flash-lite`) drives the real agent (`gemini-3.5-flash`) through the same `handle_turn()` used by text mode, voice mode and evals, graded against the final SQLite state with no LLM in the grading loop. Baseline 76/80, 80/80 after fixing 6 agent bugs the evals found; this is a dev set I tuned against, not a held-out score.

03

Added a repetition judge on top of the grader: `gpt-5.5`, a different model family than the Gemini agent, reads each transcript and flags repeated read-backs. It caught a double read-back bug the first grader missed, for about $0.47 across 80 judged calls, and is explicitly not calibrated against human labels.

04

Measured voice latency on 16 real browser calls (73 turns): p50 2.4s, p90 5.8s, max 8.1s from the caller finishing a sentence to the bot speaking, with the agent's own reasoning making up about 70% of that time.

05

Pipecat runs the browser audio pipeline over WebRTC with Deepgram STT and ElevenLabs TTS, swapping Pipecat's built-in LLM step for the same hand-written `handle_turn()` loop (about 20 lines) that gates every tool call.

06

Paging, transfers and the calendar are simulated with SQLite; no real SMS is ever sent.

Systems Analysis Concluded

© 2026 · Marian Glen Louis

Engineered with Next.js, Tailwind v4 & Framer Motion