An AI voice agent for restaurant phone orders that asks instead of assumes
A build note on an AI voice agent that answers a restaurant's phone and takes orders: the Twilio and speech model architecture, the guardrail for abusive callers, the allergy flow that asks on every call, what it connects to, and what is still demo stage.
- Written by
- Baraqix Engineering
- Updated
- Read
- 8 min
- Filed under
- voice, agents, build notes
Contents7 sections
Restaurants miss orders for a boring reason. During the rush, nobody can pick up the phone. This is a build note on an AI voice agent that answers a restaurant's phone line, takes an order, and hands it to the kitchen. It was built for restaurants in the US and it is currently in demo use with our own team. It is not live with paying customers, and this note says so again at the end, because the gap between a demo and a production voice system is the entire point of the work.
The architecture
A caller dials a Twilio number. Twilio opens a media stream, which is a websocket carrying raw audio in both directions, to a Node.js server written in TypeScript. The server forwards the caller's audio to a speech model from OpenAI that listens and speaks in near real time, and streams the model's audio back to the caller. That part is the loop everyone demos. The rest of the system is what makes the loop safe to leave alone.
- An order state machine. The model does not hold the order in its context and hope. Every item, quantity and modifier is written into a structured order object, and the model is asked to read it back before the call ends.
- Menu and availability lookup. The model can only offer what the lookup returns. An item that is sold out today is not on the list the model sees, so it cannot promise it.
- A database of customers, orders, tickets, availability and call flags. The kitchen reads tickets. The guardrail reads call flags. The model reads neither directly.
- Guardrails on both sides of the conversation: one for how the agent treats the caller, and one for how the caller treats the agent.
The tools the model can call are narrow on purpose. The availability lookup exposes two methods, because two is what the agent needs. The call flag store has no delete method at all, because nothing in the request path should be able to clear a flag. This is a design rule we apply to every agent build: keep a dangerous capability off the object the route already holds, instead of adding the method and relying on everyone being careful not to call it. An agent that cannot do a thing does not need a prompt telling it not to.
Handling abusive callers
A public phone number gets abused. People test the bot, swear at it, and sometimes keep calling to do it again. The agent needed a policy that a restaurant owner would recognise as reasonable, and the policy had to live in code as well as in the prompt.
The behaviour within one call is simple. Stay calm, steer back to the order, and do that a couple of times. If the abuse continues, say goodbye politely and end the call. The server is what ends it, so the model cannot be talked into staying on the line.
Across calls, each abusive call increments a flagged call count for that caller. The count is read at the start of every call and the agent's patience shrinks as it grows. A first offence gets the full couple of chances. A repeat offender gets fewer, and past a threshold the call is ended almost immediately. The shape of the check looks like this.
const flags = await callFlags.countFor(callerId);
const allowedWarnings = flags === 0 ? 2 : flags === 1 ? 1 : 0;
async function onAbuseDetected() {
warnings += 1;
if (warnings > allowedWarnings) {
await callFlags.record(callerId, { reason: "abuse", callSid });
await say("I am going to end the call now. Goodbye.");
return hangUp();
}
return say("Let us get back to your order. What would you like?");
}Two details matter operationally. First, there is a script to reset the flag counts for testing, and it runs only on the server from the command line. It is deliberately not an HTTP endpoint, because an endpoint that clears flags is an endpoint an abuser would eventually find. Second, before Twilio resolves the real caller number, the server uses a placeholder identity, and every flag in the current demo is written against it. That is a known limitation of the demo stage and it is replaced as part of moving fully onto the Twilio number.
Allergies: ask, never assert
This is the part of the system we would show a restaurant owner first. A returning caller has a record. The record may hold the last allergy they stated and the last preference they stated, for example no peanuts, or extra spicy. The obvious thing to do with that record is to use it. The obvious thing is wrong.
If the agent asserts, it says something like: I have you down as allergic to peanuts, so I will leave the satay off. That sounds helpful. It also means the agent has made a medical decision from a database field. The record might be stale, might belong to someone else using the same phone, or might have been misheard on a bad line last month. If the agent instead reconfirms, it says: last time you mentioned a peanut allergy. Is that still the case for this order? The caller answers, and the answer for this call is what the kitchen ticket carries.
The rule in the code is that stored allergy and preference fields are only ever used to form a question. They never populate the order directly. The order gets the value the caller said on this call, or nothing. If the caller says they have no allergies, the ticket says no allergies stated, and the stored field is updated. If the line drops before the question is answered, the field stays as it was and the order carries no assumption.
| Situation | Assert | Ask |
|---|---|---|
| Record says peanut allergy | Removes peanuts silently | Asks whether it still applies, then acts on the answer |
| Record is stale or belongs to another person | Wrong order, possibly a dangerous one | The caller corrects it in one sentence |
| Caller mentions a new allergy mid call | Depends on the prompt remembering | Written to the order the moment it is said, then read back |
| Line drops before confirmation | Order carries an unverified assumption | Order carries nothing, kitchen sees no allergy stated |
Ask, never assert is a bigger principle than allergies. It is the right default any time a language model is about to act on a stored fact about a person. Memory in an agent is a hint for a better question. It is not a source of truth, and the moment it is treated as one, the agent has quietly started making decisions nobody authorised it to make.
What broke along the way
Voice systems have a particular failure mode: everything looks like it worked. A stale process answered the test calls for an afternoon while the new code sat unused. A write that appeared to succeed did not persist. A deployment matched the expected commit while no running service was actually executing it. None of these produced an error. The fix in every case was the same: a check that proves the running system is the one you think it is, such as a version endpoint that reports the commit and the process start time, and a test call that exercises a path the old code could not have handled. We now add both to every voice project before writing a second feature.
What it connects to in a real restaurant
The demo keeps its own menu, availability and order tables. A restaurant already has most of that somewhere else, and a voice agent that ignores those systems creates a second place for staff to check. For a real location, these are the integrations we would plan first.
- The phone line. The existing number forwards to the agent during the hours the restaurant chooses, so regulars dial the same number they always have.
- The menu and today's availability, pulled from the system the restaurant already updates, so a sold out dish leaves the agent's list the moment staff mark it.
- The point of sale or online ordering system, so orders land as tickets where the kitchen already looks instead of on a separate screen.
- Opening hours and closed days. Outside them, the agent says when the restaurant opens rather than taking an order nobody will cook.
- A person to hand off to. Complaints, catering orders and anything the agent is unsure about go to a member of staff, by transferring the call or by taking a message the team sees right away.
Card payments are the one thing we keep out of the conversation. A card number read aloud to a voice agent ends up in transcripts and recordings, so payment belongs at pickup or in a payment link, handled by systems built for it.
What is still demo stage
- It is used by our own team for demos. No restaurant is taking real orders through it.
- The live test setup sits behind an access gate on a temporary address. The plan is to move calls entirely onto the Twilio number.
- Caller identity before Twilio resolves the number is a placeholder, so repeat offender tracking across calls is not yet real.
- There is no load testing. One call at a time is what has been exercised.
- The evaluation set is small and hand run. A production version needs recorded test calls replayed against every change to the prompt or the state machine.
We list these because a build note that hides them would be a sales page. The path from here to a restaurant trusting it with Friday night is a Pilot: one location, limited hours, a human listening to the first hundred calls, and the evaluation set growing from what they hear.
If you are considering one for your restaurant
Start with the calls, not the model.
- Count the calls you miss. A week of your phone provider's call log shows how many calls go unanswered and at which hours. If the number is small, a voice agent is the wrong investment.
- Decide what it may do. Taking pickup orders is a narrow job that can be tested. Reservations, delivery addresses and complaints each add risk, so add them one at a time.
- Keep a person reachable. Every call needs a way to reach staff, and the agent should use it whenever it is unsure.
- Pilot one location at limited hours, with someone listening to the first hundred calls and every mistake added to the test set.
How we set up a voice agent engagement is on the services page.
Baraqix Engineering. Written by the engineers who did the work.
NOTE/01. First published , updated .