ANKIT YADAV

AI Agents · 24 Nov 2026 · 6 min read

Building a Production WhatsApp AI Contact Center

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.

Introduction

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.

The shape of the system

There are four parts:

  1. The WhatsApp service. Node.js and Express behind the WhatsApp Cloud API webhook, with MongoDB, Redis, and S3 for media.
  2. The AI agent. LangChain and LangGraph for the agent loop, CrewAI for multi-step work, tool calling for anything that touches real data, and RAG over each department's documents.
  3. The agent console. A Next.js app where agents and supervisors work, updated live over Socket.IO.
  4. Jobs and reports. Agenda.js for campaigns, reminders, and SLA sweeps, and a FastAPI and Pandas service for analytics.

Loading diagram…

Start with the department, not the model

The first message a customer gets is an interactive WhatsApp list of departments. That one choice drives everything after it:

  • which system prompt and knowledge the AI uses,
  • which tools are allowed,
  • which agents can see the chat,
  • which working hours apply.

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.

Tools for facts, the model for language

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.

Memory without a huge prompt

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.

Handing off to a person

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:

  • An agent sees the department's chats that are still with the AI, plus their own assigned chats. Never another agent's chats.
  • A supervisor sees every chat in their departments and can take over, self-assign, transfer, close, or reopen.
  • An admin sees everything.

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.

Rules for when humans are slow

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.

The console is half the product

Agents spend their day in the console, so it needs more than a message list:

  • one thread with AI, customer, and agent messages,
  • notes, tags, and a flag to mark a chat as important,
  • transfer to another department, another agent, back to the AI, or to the main menu,
  • translation of customer messages and replies,
  • an auto-correct button that rewrites a rough reply into a clean one,
  • starting a new chat with an approved WhatsApp template,
  • a customer profile synced with the CRM in real time,
  • a claim card showing the customer's motor claims and their status,
  • quick replies in English and Arabic, ranked by how often they are used,
  • bulk archive, bulk template send, and bulk transfer between departments,
  • a chat finder so a call-center agent can open a customer's chat by phone number during a call,
  • online and idle status, and a full transfer history on every chat.

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.

Connected to the CRM, Premia, and OCR

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…

Campaigns and reminders

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.

Measuring it

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.

Lessons

  • Scope first. Department, role, and working hours decide more than the prompt does.
  • Tools for facts. If the answer lives in a database, the model should call the database.
  • Plan for slow humans, not just slow models. The three-message takeover rule fixed more complaints than any prompt change.
  • Build the console seriously. The AI handles volume. The console decides whether the hard chats go well.

What I would add next

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.

Related articles

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.

LLM Engineering · 19 Nov 2026 · 6 min

Understanding LLM Tool Calling

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.