AI agent architecture for customer service: components, flow and stack.
An AI agent architecture for customer service has six parts: a channel gateway that receives messages, a router that sorts each request, the model, tools that your own code runs, a state store that holds the conversation, and a handover path to a person. The decisive design choice is that the model never acts directly — it returns a structured tool call, your application checks and runs it, and stores the result. Here is each component, how one message flows through them, and what breaks in production.
Architecture at a glance
- Components
- Gateway, router, model, tools, state, handover
- Who runs actions
- Your application, not the model
- Conversation state
- Yours: the model API is stateless
- Start with
- A workflow, then agents where needed
- Main risk
- Prompt injection through customer text
The six components and what each one owns
A reference split. Each row is a part you can test, log and replace on its own.
| Component | What it does | What it must not do |
|---|---|---|
| Channel gateway | Receives webhooks from WhatsApp, web chat or e-mail, verifies them, answers fast and queues the message | Call the model inside the webhook request |
| Router | Sorts the request — question, order status, booking, refund, complaint — and picks the flow | Take actions itself |
| Model | Reads the conversation, decides which tool to call, writes the reply from tool results | Hold the only copy of the conversation, or reach your systems directly |
| Tools | Small functions your code runs: look up an order, check a slot, draft a refund | Run with admin rights or accept the model's word for who the customer is |
| State store | Conversation history, verified customer identity, open actions, audit log | Live only in the channel or the model provider |
| Handover | Moves the conversation, with its history, to a person when a rule or the customer asks | Lose the context, or leave the agent replying in parallel |
Workflow first, agent where it earns its place
Anthropic's engineering guide draws the line clearly: workflows are systems where LLMs and tools are orchestrated through predefined code paths, while agents are systems where LLMs dynamically direct their own processes and tool usage. It names five workflow patterns — prompt chaining, routing, parallelization, orchestrator-workers and evaluator-optimizer — and gives routing customer service queries (general questions, refund requests, technical support) to different downstream processes as its example of routing.
For support, that means the top of the architecture is usually a workflow: the router is predictable and cheap to test. Below it, an agent with a few tools handles the request types where the path is not known in advance, such as a delivery problem that needs two lookups and a decision. The same guide advises adding multi-step agentic systems only when simpler solutions fall short. For when an agent is worth it at all, see AI agents for business.
One WhatsApp message through the system
A customer writes: “I booked a table for Friday, can I move it to Saturday evening?”
- 01
Gateway receives and acknowledges
The webhook arrives; the gateway checks it, stores the raw message with its message ID, puts a job on a queue and answers 200 at once. If the same message ID is already stored, it drops the job.
- 02
State is loaded
A worker loads the conversation history and the customer record matched to the phone number from your database, because the model API keeps nothing between calls.
- 03
Router picks the flow
The request is classified as “change a booking” and the booking agent gets the history plus two tools: find the customer's bookings, and check and move a slot.
- 04
Model calls tools, your code runs them
The model asks for the customer's bookings; your code returns only that customer's records. It then asks to move the booking; your code checks the rules — opening hours, table capacity — before changing anything.
- 05
Reply, log, or hand over
The model writes the confirmation from the tool result, the gateway sends it, and every call is written to the audit log. If no slot fits the rules, the conversation goes to a person with its history.
State: the part most designs get wrong
Anthropic's documentation states that the Messages API is stateless: you always send the full conversation history. The model provider is therefore not your database. Your state store has to hold the messages, the verified identity of the customer, which actions are open or done, and who owns the conversation — agent or person.
Two consequences follow. First, long conversations grow the input of every call, so store a summary of older turns alongside the full log rather than resending everything forever. Second, handover is a state change, not a message: when a person takes over, the agent must stop replying until the conversation is handed back.
Tools are where the guards live
In Anthropic's tool use documentation, a client tool works as a round trip: the model responds with stop_reason “tool_use” and a structured call, your code runs the operation, and sends back a tool_result. Nothing reaches your order system unless your code decides it should, so every rule belongs in that layer:
- Identity from your session, never from the model. The tool takes the customer ID from the verified conversation, not from an argument the model filled in.
- Read and write tools apart. Lookups can run alone; refunds, credits and account changes create a draft a person approves.
- Treat customer text as untrusted. OWASP's LLM01:2025 describes indirect prompt injection, which occurs when an LLM accepts input from external sources such as websites or files — in support, also e-mails and attachments. Its mitigations include least privilege, human approval for high-risk actions, and segregating external content.
What breaks at scale, and the fix in the architecture
| Symptom | Cause | Fix |
|---|---|---|
| The customer gets the same reply twice | Meta retries webhooks that did not get a 200, and retries can arrive as duplicates | Answer 200 at once, deduplicate on the message ID before queuing |
| Replies arrive late during a busy hour | The model is called inside the webhook request | Queue the message, process it in workers you can scale |
| A message from days ago is answered | Meta keeps retrying a failed delivery, so it can arrive days later | Check the message timestamp and skip or hand over stale ones |
| The agent and a person both reply | Handover is not recorded in state | One owner per conversation in the state store, checked before every send |
| A changed prompt breaks bookings | No test set | Replay stored real conversations against the new version before release |
How we build it
On our stack, Anthropic Claude handles reasoning and tool use for agents, client agents run on the official WhatsApp Business Platform (Cloud API), and each project is one Docker Compose stack — app, database, workers — on Google Cloud virtual machines. Every agent ships with a daily usage cap, a dry-run mode, an off switch, human handover and logs of every action; see WhatsApp AI agents. Deciding what the agent may do is covered in how to deploy an AI customer service agent, and checking it once live in how to audit an AI customer service bot.
Sources
- Anthropic — Building effective agents — workflows vs agents, the five patterns, routing customer service queries, start simple — checked 15 November 2026
- Claude Docs — Tool use overview — client tools, stop_reason tool_use, tool_result — checked 15 November 2026
- Claude Docs — Working with the Messages API — the Messages API is stateless — checked 15 November 2026
- Meta for Developers — WhatsApp webhooks overview — retries of failed deliveries, duplicate notifications — checked 15 November 2026
- OWASP GenAI Security Project — LLM01:2025 Prompt Injection — indirect prompt injection and mitigations — checked 15 November 2026
Related
Frequently asked questions
What are the components of an AI customer service agent?
A channel gateway that receives messages, a router that sorts each request, the language model, tools that your own code runs, a state store that holds the conversation and the customer's identity, and a handover path to a person.
Should a customer service AI be a workflow or an agent?
Usually both: a predictable workflow at the top that routes each request, and an agent with a few tools only for the request types whose steps are not known in advance. Anthropic's guide advises adding multi-step agentic systems only when simpler solutions fall short.
Where should conversation history be stored?
In your own database. The Claude Messages API is stateless, so your application sends the full conversation each time; your state store also records the verified customer, open actions and who owns the conversation.
Why does my WhatsApp bot reply twice to the same message?
Meta retries a webhook when your endpoint does not answer with HTTP 200, and its documentation warns that retries can produce duplicate notifications. Answer 200 at once, then deduplicate on the message ID before processing.
Designing a support agent? Start with the architecture.
Tell us your channels and the systems the agent must reach, and we will sketch the components and the guards we would build.