AI Engineering · 24 Nov 2026 · 2 min
Human-in-the-Loop AI Automation
The ownership rules behind an AI-first contact center. When the AI answers, when a person takes over, and when the AI steps back in because the person went quiet.
AI Agents · 24 Nov 2026 · 6 min read
How I built an AI-first WhatsApp contact center for an insurer, with tool-calling agents, department routing, least-load assignment, SLA takeover rules, campaigns, and an agent console.
A WhatsApp bot that answers FAQs takes a weekend. A WhatsApp contact center that an insurance company runs its customer service on takes a lot more: routing, roles, working hours, a console for the humans, campaigns, and reports that management trusts.
I built one end to end. It handles about 2,000 to 5,000 chats a day and is sized for about 1,000 concurrent conversations, where a human agent holds about two. This post walks through how it is put together and the decisions that mattered.
There are four parts:
Loading diagram…
The first message a customer gets is an interactive WhatsApp list of departments. That one choice drives everything after it:
A claims question answered with the motor sales prompt is a wrong answer, even if it sounds right. Scoping by department up front is cheaper and more reliable than asking the model to work it out.
The customer can check a policy status, register a complaint, look at a policy draft, and upload documents. Each of those is a tool. The model decides when to call it and fills in the arguments. The service validates the arguments, runs the call, and passes the result back.
That rule keeps the bot honest. A policy status always comes from the CRM. A complaint number is created by the complaints service. When a customer sends a photo of their Emirates ID, a tool sends it to the OCR service, which says what the document is and whether the other side is missing, and the bot asks for it in the same chat.
Small classifiers run beside the main agent: one for "this person wants a human", one for "this person changed department", and one for document handling. They run at temperature 0, with retries and a short timeout, so a slow model call never freezes the conversation.
Every message loads the recent turns from Redis. That covers most questions. When the answer depends on something said long ago, older details are retrieved from a vector store and added to the prompt. The model sees the recent conversation plus only the slice of history it needs, which keeps latency and cost down on long chats.
When a person should take over, the router picks an agent in that department with the lowest current load, counted with a MongoDB aggregation over each agent's open chats, and optionally only among agents who are online.
Visibility is a role rule:
This sounds like a UI detail. It is not. It is what stops two agents replying to the same customer, and it is what lets a supervisor manage a queue without asking around.
Each department has working hours per weekday, a lunch break, and holidays. Outside those hours the AI keeps the chat going and tells the customer when the team is back.
Inside working hours, the risky case is an agent who has the chat but is not replying. The rule: if the customer sends three messages with no reply, the AI steps back in. It tells the customer an agent will reply shortly or reassigns the chat, and it notifies both the agent and the supervisor in the console and by email. A scheduled sweep catches anything still waiting. Chats with no activity for 96 hours close themselves.
I wrote more about these rules in Human-in-the-Loop AI Automation.
Agents spend their day in the console, so it needs more than a message list:
The customer side is just as wide. Besides text, the bot accepts photos, PDFs, voice notes, video, locations, and contact cards, shows typing indicators and read receipts, and runs the same flows on a website chat widget. A motor quote inquiry turns into a lead for the sales team, and a complaint becomes a tracked case with a PDF record.
The contact center does not keep its own copy of insurance data. New WhatsApp customers are created in the insurance CRM, and policy status, drafts, and claims are read from it. The CRM stays in step with the Premia core system through scheduled sync jobs, so what the bot says matches the core system. Documents go to the same OCR API the CRM uses.
Loading diagram…
Agenda.js runs the outbound side: scheduled bulk sends from an uploaded list, birthday wishes on WhatsApp and email, and policy expiry reminders 30, 15, and 2 days before expiry. A template designer builds utility and marketing templates and syncs them with Meta. Admins decide which agents can use which templates, and agents can keep their own personal message templates.
Admins also train each department without a deploy: bulk Q&A uploads, PDF, Word, or web page ingestion for retrieval, and an OpenAI fine-tuning job from the same data.
AI analytics show volume over time, how many chats the AI closed alone, and where customers dropped off. Agent analytics show first response time, average and median response time, time in queue, and handling time.
The first version of those reports took 20 to 60 seconds and timed out during the day. Compound MongoDB indexes matched to the report filters, batch aggregation, and connection pooling brought them under 100 ms.
Sentiment-aware queue ordering, an agent co-pilot that suggests replies with sources, voice-note transcription, WhatsApp Flows for structured claim intake, and a one-tap satisfaction rating when a chat closes.
AI Engineering · 24 Nov 2026 · 2 min
The ownership rules behind an AI-first contact center. When the AI answers, when a person takes over, and when the AI steps back in because the person went quiet.
LLM Engineering · 19 Nov 2026 · 6 min
How an application asks a model for a structured tool call, checks the arguments, runs the tool itself, and sends the result back to the model.