Build a voice agent · Chapter 20 of 21
Capstone: Bolo
By the end of this chapter Bolo is one agent in four files of your own: its words, its brain, its phone number and its scoreboard. It answers all thirteen of Kickstart's callers, callers it has never met, and calls on the mu-law line; it keeps recordings with no card numbers in them; and you can show, in the line's own numbers, that it is ready. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Production
- 4 tasks
- Python
- In the all labs plan
The first 2 chapters of Build a voice agent are free. This one comes with the all labs plan.
Why you need this
Rashmi wants Bolo on Kickstart's real number next week, and she has one question: "Is it ready?" Imran's answer is not "it works on my calls". It is a scoreboard: every caller, measured from the caller's side.
Kavita adds a warning. "The thirteen callers are people I know. On Monday, Bolo meets people I do not." A Bolo that passes because it learned thirteen sentences will fail on the fourteenth. Tejas has two lines that must hold on every call: the wrong booking is never touched, and no card number is kept or sent anywhere.
You built every piece in the chapters before this one, each in its own folder, each tested on the callers it was for. Here they become one Bolo, and the checks call it the way Kickstart's line will.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
speech.py: Bolo's words
Bring every text piece into one file: Sentences (push(delta) gives the sentences now complete; "4.5", "₹1,199" and "Dr." end none; rest()), for_speech (no markdown, booking and phone numbers digit by digit), is_backchannel, real_words, sounds_unfinished, HOLD, GOODBYE, find_numbers and redact (card, phone and OTP runs, spans with kind, start_word, end_word, start and end).
The check tries each on cases it makes up.
- Task 2
bolo.py: Bolo
Write async def converse(line, services, opts=FULL, changes) and async def run_call(caller, opts=FULL, changes) (codec="mulaw" for the mu-law line): the whole agent from your chapters, with the given line, STT, TTS and tools and your speech.py: streaming STT, semantic end of turn, the streamed model into streamed speech, marks, barge-in on words, the history cut to what was heard, backchannels, silence and hold, tools in parallel with a filler, the caller's language, numbers for speech, unsure words confirmed, and the caller's numbers redacted before the model.
The check calls it on callers it adds (an English caller who pauses after "and", a caller who interrupts) and on Sunita and Mrs Iyer over the mu-law line.
- Task 3
server.py: Bolo on a phone number
Write async def start_server(port) (a CallServer with port, active() and close()): your call server from chapter 17 running converse with a Tape on the line, its own STT and TTS per call, both closed at the end; then, in recordings next to the file (Path(__file__).parent), CALL_ID.wav (stereo, every card, phone and OTP run bleeped on both channels) and CALL_ID.txt (caller: and Bolo: lines of redacted words).
The check dials Kiran and Mr Gupta on the mu-law line and Meena on the PCM line, then listens to what you saved.
- Task 4
scoreboard.py: Bolo on every caller
Run every caller from callers() through your run_call, 7 at a time, and print CALLER ok|FAIL OUTCOME A/B/C ms cut-ins N for each, then OK/13 calls, T turns: p50 A ms, p95 B ms, max C ms, then cut-ins N, nudges N, longest talk-over N ms.
The check reads the same calls from the line: 13/13, p50 at most 1.3 s, p95 at most 2.3 s, no cut-ins, talk-over under 1.2 s, KS-4418 untouched, the silent line ended by Bolo, and no card number sent to the model.
What you will learn
- The whole agent, as a few files with clear jobs.
- What each piece is for: the caller it saves, measured with it switched off.
- Callers you have never met: why the check adds its own, and what that tests.
- Bolo on a phone number: the call server, the recorder and the bleep in one handler.
- The scoreboard: thirteen callers, the thresholds, and reading a call that fails.
More in Production
Build "Capstone: Bolo" yourself
Kickstart services scooters at the door in Nagpur, and its phone line gets 600 calls a day in Hindi, English and Hinglish. You build Bolo, its voice agent, and measure every call: who it understood, how long callers waited and who it cut off. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Build a voice agent are free. This one comes with the all labs plan.