ai newsDi., 1. Dez.

Building an AI Call Coach to Help My Wife Train

Nov 29, 2026 · @rubarajan Why I built it My wife started a new job answering customer calls for a US company. She wanted practice before real callers reached her.Role-playing with me only went so far: I ran out of believable customers quickly, and I couldn't judge her English fairly. So I built Cal

dev.toMontag 22:24 · 30.11.6 Min. Lesezeit
Bild: dev.to

My wife started a new job answering customer calls for a US company. She wanted practice before real callers reached her.Role-playing with me only went so far: I ran out of believable customers quickly, and I couldn't judge her English fairly.

So I built CallCoach, a small web app that runs on her phone. She picks a caller, taps Start call, and talks to an AI customer in a natural voice. When she hangs up, a second AI reads the transcript and writes her a coaching report.

The key design choice is that the AI plays the customer, not the coach. She is the representative. That flip turns a chatbot into a training simulator, and the same design works for any call-center or front-desk role.

It has four parts, built in four phases:

[embedded content: CallCoach architecture · live call and after the call]

Her phone never talks to a model directly. Everything goes through my server, which holds the API keys and saves the transcript, and the grader runs only after the call ends.

Every practice caller is a persona: a record in MongoDB that is turned into a system prompt at call time. Keeping callers as data means I can add a new scenario from the phone in a minute, without a deploy.

A small function, buildPersonaPrompt, assembles these fields into Markdown sections: Who you are, Personality and mood, How you speak, Why you are calling, and so on. Empty fields are dropped, so a thin persona still makes a clean prompt.

Three parts of that prompt do most of the work:

Difficulty is a paragraph of behaviour, not a number. Easy is patient and forgives small mistakes. Hard pushes back on vague or scripted answers and calms down only if she acknowledges their feelings, explains clearly and gives next steps.

Personas get tuned constantly, so every save writes an append-only version. A personaVersions collection holds every edit with who made it and a note, and the personas collection holds the current copy. Restoring an old version copies it forward as a new version, so history is never rewritten. Archiving is also just a version, so it can be undone.

Each call records the persona version it used. That matters later: the coaching report is graded against the exact caller she spoke to, even if I have edited it since. The editor also sends the version it started from, and the server rejects a save if someone saved a newer one in the meantime.

A practice call is three WebSocket hops: her phone, my server, and Deepgram's Voice Agent API. The voice agent does the listening, thinking and speaking in one stream, so I never wire speech-to-text, the LLM and text-to-speech together myself.

The browser could talk to the voice agent directly, but routing through my Express server buys four things:

The protocol is small. The browser sends a JSON start message with its token and persona ID, then raw 16 kHz 16-bit mono audio as binary frames. The server sends back JSON events ( ready, transcript, interrupt, hangup, ended, error ) and the caller's voice as 24 kHz binary audio.

When the upstream socket opens, the server sends one Settings message that defines the whole caller:

agent: { listen: { provider: { type: 'deepgram', model: 'flux-general-en', keyterms: keytermsFor ( persona ), eot_threshold: 0.7 } }, think: { provider: { type: 'anthropic', model: 'claude-haiku-5-5' }, endpoint: { url: 'https://api.anthropic.com/v1/messages', headers: { 'x-api-key': ANTHROPIC_API_KEY } }, prompt: buildPersonaPrompt ( persona ), functions: [ { name: 'end_call', defer_until_eot: true,... } ] }, speak: { provider: { type: 'deepgram', model: persona. voice } }, } Enter fullscreen mode Exit fullscreen mode A few choices here matter more than they look:

Real callers get interrupted, so the AI caller must stop talking the moment she speaks. The voice agent sends UserStartedSpeaking; the server forwards it as interrupt; the browser stops every queued audio buffer at once.

Hanging up is a tool call. The persona prompt tells the caller to say goodbye and then call end_call. The server waits for the agent's audio to finish, with a 6-second fallback, then sends hangup. The browser lets the goodbye play out before closing the call. Without this, the caller says goodbye and then sits silently on the line.

This was the hardest part of the project, and none of it is AI.

Every call also stores a small diagnostics snapshot: browser, audio context state, mic label and peak level. When she said "it didn't hear me", I could see exactly why without asking her to reproduce it.

When a call ends, the server starts the grader in the background and the call page polls every 4 seconds until the report is ready. The grader is Claude Opus 5.5 at high effort, given a fixed rubric and the full transcript.

The English score is five categories, each 0 to 100, combined with fixed weights:

The model returns the five scores; my code computes the weighted overall score. LLMs are poor at arithmetic and inconsistent at weighting, so the deterministic part stays in code.

Call handling is scored separately, as a checklist rather than a number: greeting, identity verification, understanding the need, accurate answers, empathy, next steps and closing. Each step is done, partly, missed or not applicable. Keeping it apart from the English score means a well-spoken call that skipped verification can't hide behind a high number.

"You said / Try" is the most useful part of the app. A score tells her how she did; seeing her own sentence beside a natural rewrite tells her what to change.

Very short calls are skipped. Under 10 words from her, the report explains why and offers "Score it anyway". With no words at all, it tells her to check her microphone.

Writing a good persona by hand means filling in a dozen fields. The generator cuts that to a sentence: "an impatient retiree who was charged twice and wants it fixed today, hard". Claude Opus 5.5 expands it into every field, and the draft opens in the normal editor. Nothing is saved until she taps Create caller, so a person always reviews what goes into the library.

The generator's system prompt contains three things:

The response uses a JSON schema whose voice and difficulty fields are enums, so the model can't invent a voice that doesn't exist. The output then goes through the same sanitizePersona function as a hand-written persona, which trims every field to a maximum length and checks the required ones.

Two safety rules are in the prompt. Verification details must be obviously fictional: 555 phone numbers, example.com emails, made-up addresses. And no real people, companies or product names. Generation is also capped at 30 per user per day, and each run's token usage is logged.

The whole app runs on a Raspberry Pi and a static host.

Most of the code is domain-neutral. To train for a different kind of call, change three things:

The WebSocket bridge, the audio code, the version history and the report UI work unchanged for a help desk, a sales line, or a front desk.

Quelle: dev.to (dev.to). Original öffnen