🛠️ How to Build an AI Voice Agent for Phone Calls: The Step-by-Step Guide From Production
This is the build we actually run on lines that take thousands of calls a month in Nepal, written as steps you can follow, with the mistakes we paid for so you do not have to.
A phone voice agent is six parts: a SIP line into a PBX, an audio bridge that streams the call to a conversation engine, a persona prompt with rules, a knowledge base the engine searches rather than memorises, a few tools (end call, transfer, look up, create ticket), and a review loop over recordings. The engine is the smallest part of the work. Audio handling, number pronunciation and knowledge-base hygiene are where projects fail.
Step 1: Get a phone line into a PBX you control
Everything starts with SIP. Rent a DID from a local provider or bring your existing number and have it delivered to a PBX you run, usually Asterisk on a small VPS. Register one or more extensions on the trunk; each extension is a concurrent call. Two notes from production:
- Some cloud providers filter UDP 5060. Bind SIP to another port (5160 works) before you spend a day debugging "registration rejected".
- Carriers behave differently on outbound: some fake-answer with an announcement, some restrict outbound entirely on certain accounts. Test a real outbound call to a mobile and listen to the recording before you promise campaigns.
The SIP trunk guide covers providers and Asterisk configuration.
Step 2: Bridge the audio to the engine
The PBX hands each answered call to a bridge process over an audio socket: raw 16 kHz PCM both ways. The bridge streams caller audio to the conversation engine and plays the engine's speech back, and it owns four things the engine cannot:
- Greeting. Play the greeting immediately and once; a watchdog re-prompts if the caller heard nothing within a few seconds.
- Barge-in and echo. When the caller speaks, stop the agent. But the agent's own voice leaks back on cheap handsets; gate on energy and duration, or 40% of your replies get cut off by echo, which is exactly what happened on one shop line until we fixed it.
- Silence. A quiet line is not a hang-up. Re-ask once after a few seconds, then wind down politely. Never terminate on noise.
- Jitter. Mobile audio arrives in bursts. Buffer a little or the greeting sounds choppy.
Step 3: Write the persona, then make it short
The system prompt defines identity, tone, language rules and hard limits. Ours for a shop line started at 15,800 characters and worked better at 6,500. Keep in it: who the agent is, the register (formal हजुर for an office, warmer for a shop), the "never" list (no invented prices, no medical advice, no reading account data), when to transfer, how to end. Keep out of it: your catalogue, your FAQ, anything that belongs in a lookup. Two rules that cost us real calls:
- Greet once. A greeting that repeats when the caller says "hello?" makes people hang up.
- Answer the question asked. An agent that deflects a price question to "the team will call you" loses the sale; give the model and offer the confirmation.
Step 4: Knowledge base: search it, do not stuff it
The single most common failure. Teams paste 40,000 characters of FAQ into the prompt and the engine quietly truncates it; one of our early lines only ever saw the first 15,000. The fix is retrieval: chunk the documents, index them (we run a small local embedding service plus a keyword index), and let the agent call a search tool during the call. Combine semantic and exact-match search; section numbers, hospital names and product codes must hit exactly. Large catalogues go in a database with a lookup function: a drug-information line searches 10,077 brands this way and the prompt holds only rules.
Scanned PDFs need OCR and manual clean-up, especially Devanagari tables. Budget time for it; it is half the project on a government line.
Step 5: Give the agent tools, few and strict
| Tool | What it does | Rule |
|---|---|---|
| search_knowledge | Retrieves passages from the documents | Called before answering any factual question |
| lookup (catalogue, CRM, order) | Reads live data from your system | Must return within about 1.5 s or the pause is audible; the agent says "one moment" first |
| transfer_to_human | Dials a person or department, bridges on answer | Office-hours aware; message and ticket on no-answer |
| create_ticket / create_order | Writes the outcome with the transcript | IDs come from the database, never spoken from memory |
| end_call | Ends politely and reports an outcome | The outcome label feeds your reports; make the agent classify its own call |
Step 6: Numbers, names and pronunciation
Voice engines read "9841234567" badly and read a transcript of it correctly, which is worse because you will not notice. Store phone numbers as spoken digit groups (nine eight four, one two three, four five six seven), write "WiFi Six" not "Wi-Fi 6", and keep a pronunciation list for brand names in the script. Verify by listening to recordings, not by reading transcripts.
Step 7: Test with callers who behave badly
Before any real traffic, run simulated callers through the full audio path: one that interrupts constantly, one that goes silent, one that mumbles a drug name in Nepali, one that asks for a human in the first sentence, one on a noisy line. Then let staff call for a week. Keep a question set (ours is 62 to 74 questions per line) and track the hit rate after every knowledge-base change; "52 of 62 became 60 of 62, none worse" is the kind of result you want to be able to say.
Step 8: Review recordings every week
The agent is never finished. Weekly, pull ten recordings, listen, and fix the knowledge base or the prompt. Watch for invented numbers, repeated offers ("shall I place the order?" after every answer), loops on long calls, and transfers that ring nothing. One client's resolution rate rose about 30% in three months from this routine alone. Add guards for the expensive mistakes: a missed-order alarm that re-checks calls where an order was started but not finished caught every real lost order on one line while cutting false alarms from 88 to 11.
Step 9: Campaigns, if you need outbound
Outbound adds a dialler: a contact list, calling hours, concurrency, retries and per-contact openers. Three lessons: clean the list first (43% of one real list could not be dialled); keep the opener under ten seconds; and free a dialling slot the moment a call fails, or ghost slots quietly turn a ten-line campaign into a two-line one, which is what happened to us before the reaper was fixed.
Step 10: Count the cost
Per minute, a production voice agent costs the engine's audio processing plus telephony plus a share of the server, and every tool call adds a processing pass. Our usage price of $0.03 to $0.06 a minute reflects that; building it yourself lands in the same range once you add the engineer who maintains it. The pricing page has the breakdown.
Or skip steps 1 to 10
All of this is what TalkC runs as a service: your number, your knowledge base, your rules, our bridge and engine, with the review loop included. If you want to build it yourself, this guide is honest about the work. If you want it live next week, call the demo line to hear the result and then book a scoping call.
Frequently Asked Questions
How long does it take to build a voice agent?
A first working line in a few days if you use a managed platform; two to three months to build and harden your own, mostly on audio handling, knowledge-base hygiene and testing.
Do I need Asterisk?
You need a PBX that can hand audio to your bridge. Asterisk with an audio socket is what we run; FreeSWITCH works the same way. Hosted PBXs rarely give you the raw audio you need.
Why not put the whole FAQ in the prompt?
Because it gets truncated silently and costs you on every reply. Index the documents and let the agent search them during the call; put catalogues in a database with a lookup tool.
How do I stop the agent inventing prices or numbers?
Keep facts out of the prompt and in lookups, mark the catalogue as authoritative, let the agent say 'not found', generate IDs from the database, and verify numbers by listening to recordings.
What does a built agent cost to run?
Around $0.03 to $0.06 per minute of talk time once engine, telephony and servers are counted, plus the engineer who maintains it. That is the range TalkC charges as a managed service.
Ready to see TalkC.ai in action?
Get a personalized demo of TalkC.ai's voice AI platform. See how we handle calls for CG, Padam Machinery, the Office of the Company Registrar and municipalities — same-day setup, 70+ languages.
Book a Demo →