ANKIT YADAV

AI Engineering · 24 Nov 2026 · 2 min read

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.

Introduction

Automation that always asks a person is a form with extra steps. Automation that never asks is a liability when money, identity, or an insurance claim is involved.

In the WhatsApp contact center I built, the question is concrete: at any moment, who owns this chat, the AI or a person? This post is the set of rules that answers it, and why each rule exists.

Ownership is a state, not a flag

Every chat has exactly one owner. Transitions between owners are explicit and recorded.

Loading diagram…

The model never moves itself out of a state. It can recommend a handoff through a classifier, and the service decides whether that transition is allowed right now.

Rule 1: the AI owns the chat by default

A new chat starts with the AI, scoped to the department the customer picked. The AI answers questions, calls tools for policy status, complaints, drafts, and documents, and keeps the conversation going. Most chats never need a person.

Rule 2: a person takes over when the customer needs one

A small classifier reads each message and answers one question: does this person want a human? It runs at temperature 0, with retries and a short timeout. When it says yes, the router assigns the agent in that department with the lowest load, and the agent sees the whole thread, so the customer never repeats themselves.

Rule 3: working hours decide who can answer

Each department has hours per weekday, a lunch break, and holidays. Outside them, there is nobody to hand off to, so the AI stays in charge, sets expectations, and the chat waits in the queue for the morning.

Rule 4: the AI steps back in when the person goes quiet

This was the rule that fixed the most complaints. If an agent owns the chat and the customer sends three messages with no reply, the AI takes the chat back:

  1. It tells the customer that an agent will reply shortly, or reassigns the chat to another available agent.
  2. It notifies the assigned agent and the supervisor in the console.
  3. It emails both, with a cooldown so nobody gets a flood.
function onCustomerMessage(chat) {
  if (chat.owner !== "human") return;
  chat.unansweredCount += 1;
  if (chat.unansweredCount >= 3) {
    notify([chat.agentId, chat.supervisorId], "chat-waiting", chat.id);
    reassignOrHoldWithAI(chat);
  }
}
 
function onAgentMessage(chat) {
  chat.unansweredCount = 0;
}

A scheduled job sweeps for anything the event path missed, and chats with no activity for 96 hours close themselves.

Rule 5: visibility follows roles

"Human in the loop" fails quietly if the right human cannot see the chat.

  • Agents see their department's chats that are with the AI, plus chats assigned to them.
  • Supervisors see every chat in their departments and can take over, self-assign, transfer, close, or reopen.
  • Closing and reopening are permissions, not defaults.

Rule 6: record every transition

Every transfer, takeover, close, and reopen is written to a history with timestamps. That history powers the agent reports: first response time, time in queue, and handling time. If you cannot measure how long chats wait for a person, you cannot tell whether the loop works.

Lessons

  • Draw the ownership state machine before writing a prompt.
  • Plan for slow humans, not only slow models.
  • Never let the model change its own state. It recommends, the service decides.
  • Measure queue age before you measure model speed.

Related articles

AI Agents · 24 Nov 2026 · 6 min

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.

LLM Engineering · 19 Nov 2026 · 6 min

Multi-LLM Fallback Architecture

A practical way to call a second model when the first one times out or returns an unusable response, without repeating the same side effect.