How an AI receptionist works: a conversation is stored state, not one request
A receptionist that handles a WhatsApp thread or a phone call cannot keep its memory in a process. Workers restart, two messages arrive together, and a lead writes back three days later. So the state lives in Postgres. Every message, inbound and outbound, is a row tied to a conversation, a contact and an agency, and a conversation carries a JSON column for structured memory such as the shortlist a client was shown and the viewing times offered.
Each turn rebuilds its context from those rows. The last thirty messages become the model's history, and the model keeps nothing of its own between turns. A phone call gets its own conversation and each spoken turn is saved as two messages, so a call can be replayed and a colleague who picks it up sees all of it. The caller is matched to the same lead record as a WhatsApp contact by phone number, so one person stays one lead.
The channels need stating plainly. The receptionist holds conversations on WhatsApp and on the phone. Email and SMS are used to send confirmations and notices; we do not run receptionist conversations on them.
How an inbound message reaches the AI without being lost
The webhook endpoint does as little as it can. It checks the provider's signature, validates the shape of the payload and puts the raw payload on a Celery queue backed by Redis. It answers 200 only once the broker has accepted the task, and answers 503 if the queue is unavailable, which tells the provider the delivery failed. A worker does the real work. It acknowledges late and retries up to five times with backoff and jitter, so a worker that dies mid-task does not take the message with it.
The order inside the worker matters. This is the sequence, simplified:
A Redis lock keyed on the conversation makes two near-simultaneous messages take turns, so the second turn sees the first one's reply. If Redis is unavailable we skip the lock rather than block the reply.
async def handle_inbound(msg):
async with claim(msg.provider, msg.id): # a duplicate delivery runs once
agency = resolve_agency(msg.to_number) # no match: refuse, never guess
contact = find_or_create_contact(agency, msg.from_number)
conv = find_or_create_conversation(contact) # per-contact advisory lock
save_inbound(conv, msg) # stored before the model runs
if staff_own(conv):
return notify_staff(conv) # the AI stays silent
async with turn_lock(conv.id): # one turn at a time
reply = await run_agent(conv)
await send(reply)How the model is called: deterministic checks, a scope check, then a capped tool loop
Plain code runs first for the cases where a wrong answer has legal or data consequences: a withdrawal of consent, a request for erasure, a reply to a star-rating question, a tap on a viewing reminder. The model cannot refuse, miss or paraphrase something code has already handled.
A smaller model then classifies the message as in scope or not and decides whether it needs rewriting into a clearer request. A lead who keeps going off topic reaches a cap of five strikes, and we stop replying and stop spending model calls until a day has passed.
Messages that pass go to one tool-calling agent. It never touches the database directly. It calls tools on an in-process MCP server scoped to one agency, one contact and one conversation, and every call carries an HMAC that only our own processes can compute. The loop is capped, at six rounds by default.
How we stop the model stating things it never looked up
A prompt asking for honesty is a request, not a control. After the model replies, code checks the reply against what the tools returned. If it lists properties but no search ran this turn, the loop gets one more round with an instruction to search first, and the same applies to saying nothing fits without searching. A numbered list of viewing times that did not come from the availability tool is replaced with the real ones, and a reply that describes a client's bookings is checked against the diary.
We added several of these after a failure in a real conversation, which is the honest reason the pipeline is long. The trade-off is that the checks are pattern based. They catch the failures we have seen, not every possible one.
What happens when the model or the provider fails
On WhatsApp the inbound message is stored before the model is called, so a model failure never loses it. If the pipeline raises, the client gets a short apology and the message stays in the CRM for a person. If history cannot be loaded the turn carries on with the live message, and if saved conversation state cannot be read nothing is forced that turn. Other faults, such as a database error outside the pipeline, produce silence rather than an apology. We do not fail over to a second model on WhatsApp today.
One bug is worth naming. We cached the HTTP client for the model API per process. Celery runs each task on a fresh event loop and closes it afterwards, so the cached client held connections bound to a dead loop and every other turn on a worker failed. The client is now cached per loop.
The phone path has a second layer. When the primary model returns a 429, a 4xx or 5xx, or a connection error that survives one retry, the call switches to a fallback model for the rest of that call, because the fallback's turns leave state the primary's endpoint would reject. Each reply records which model produced it, so failover frequency can be read from the data. Slowness alone almost never triggers a switch: the latency budgets are set high on purpose.
How hand-off to a human works
Hand-off is a tool the model can call, not a mode. The escalation tool marks the conversation escalated and emails the agency's assigned agent, or the first active admin if nobody is assigned. It reports whether anyone was actually notified, and the model is told not to promise a callback when nobody was. For months an earlier version reported success whatever happened.
An escalated thread keeps being answered by the AI, because the client may have other questions. It goes quiet when a named member of staff replies. From then on the conversation belongs to that person: inbound messages are stored, staff are notified, and a reminder goes out if a customer message has waited an hour (configurable, checked every fifteen minutes). If a colleague replies while the AI is mid-turn, the AI's draft is held and shown to staff instead of sent, so the client never hears two voices.
Handing back is explicit: a member of staff does it from the inbox, and the AI takes the conversation again from that point.
What an AI receptionist does after hours
There is no separate after-hours mode in the code. The receptionist behaves the same at 02:00 as at 14:00: it answers, searches stock, books viewings into the diary and takes details. What changes is what a person can do. A hand-off at night becomes an email and a notification that wait, and the prompt tells the model to promise no timeframe and never to quote an out-of-hours number it does not have.
An urgent hazard such as a gas smell is not treated as routine: the model logs a repair, escalates in the same turn and tells the client to call 999 for gas or fire. If an agency's AI is paused or its account suspended from our admin console, messages are still stored, nothing is sent, and the held reply is recorded rather than sent later.
Where to go next
If you want to see this running on your own WhatsApp number and phone line, the AI receptionist page explains what it does for an agency day to day. A demo connects it to your number and opening hours, and you decide what it asks and when it hands over.
Questions people ask
How does an AI receptionist work?
It receives each WhatsApp message or call through a verified webhook, stores it, rebuilds the conversation from stored messages, and lets a language model answer by calling tools that read and write the agency's records. Checks in code sit before and after the model, and a person can take over at any point.
What happens if the AI receptionist cannot answer a question?
It can hand the conversation to a person, which marks the thread escalated and emails the assigned agent or an admin. If the model fails instead, the inbound message is already stored, so staff can see it and reply.
Does an AI receptionist work outside office hours?
In ours it behaves the same at any hour: it answers, searches stock and books viewings. A hand-off outside hours becomes a notification that waits for a person, and the receptionist promises no callback time.
How do you stop an AI receptionist talking over a colleague?
Once a named member of staff replies, the conversation is owned by them and the AI stays silent. If they reply while the AI is mid-turn, the AI's draft is held and shown to staff instead of being sent.