The design brief#
“Design an AI agent for an e-commerce company that resolves customer-support requests — order status, returns, refunds, address changes — over chat and email, escalating to humans when needed.”
1. Requirements#
Functional
- Understand requests in chat and email, in 5 languages.
- Look up orders, shipments, customers and policies.
- Perform actions: change delivery address (before dispatch), create return labels, issue refunds, apply goodwill vouchers.
- Escalate to a human agent with a summary when unsure, when the customer asks, or for sensitive cases (complaints, legal threats, vulnerable customers).
- Full audit trail of every action.
Non-functional
| Requirement | Target |
|---|---|
| Volume | 40,000 conversations/day, peak 3× |
| Latency | First response < 3 s in chat; email within 5 minutes |
| Automation | ≥ 60% resolved without a human, with CSAT ≥ human baseline |
| Safety | Zero unauthorised refunds; refunds > €100 need human approval |
| Availability | 99.9%; degraded mode routes to humans |
| Compliance | GDPR; PCI scope excluded (agent never sees card numbers) |
2. Estimates#
- 40,000 conversations × ~6 turns × ~2 LLM calls per turn ≈ 480,000 LLM calls/day.
- ~6,000 input tokens per call (system + tools + history + retrieved policy), ~250 output.
- ≈ 2.9B input + 120M output tokens/day. Prompt caching of the ~3,000-token static prefix (system prompt + tool definitions) cuts input cost substantially.
- Router on a small model handles ~30% (simple status questions) cheaply.
- Target cost: < €0.15 per resolved conversation vs ~€4–6 for a human-handled contact.
3. Agent topology#
flowchart TB
IN["Chat / email channel"] --> TRI["Triage & router<br/>small model: intent, language,<br/>sentiment, risk flags"]
TRI -->|"status, tracking"| SA["Order-status agent<br/>read-only tools"]
TRI -->|"returns, refunds"| RA["Returns & refunds agent<br/>read + write tools, limits"]
TRI -->|"account, address"| AA["Account agent"]
TRI -->|"complaint, legal,<br/>vulnerable, angry"| HUM["Human agent queue"]
SA -->|"handoff"| RA
RA -->|"needs approval"| APR["Approval queue<br/>human supervisor"]
SA -->|"escalate"| HUM
RA -->|"escalate"| HUM
AA -->|"escalate"| HUM
Why this split: each specialist has a small tool set and a focused prompt; the read-only agent cannot change anything (security boundary); refunds are isolated with stricter limits; triage runs on a cheap model.
4. Architecture#
5. Tools (exposed via MCP servers owned by domain teams)#
| Tool | Type | Guardrails in code |
|---|---|---|
get_order(orderId) |
Read | Order must belong to authenticated customer |
track_shipment(orderId) |
Read | Same ownership check |
search_policy(query) |
Read | RAG over approved policy documents |
change_address(orderId, address) |
Write | Only before dispatch; address validation; idempotency key |
create_return(orderId, items, reason) |
Write | Within return window; item eligibility |
issue_refund(orderId, amount, reason) |
Write, financial | Amount ≤ order total − prior refunds; ≤ €100 automatic; above → approval; idempotency key; daily cap per customer |
apply_voucher(customerId, value) |
Write, financial | ≤ €15; max 1 per 30 days |
escalate_to_human(summary, priority) |
Control | Always allowed |
Customer identity comes from the authenticated session and is passed as tool context, never from model-provided arguments.
6. Conversation flow with a refund#
sequenceDiagram
actor C as Customer
participant T as Triage
participant R as Refunds agent
participant O as Orders MCP
participant P as Policy RAG
participant PAY as Payments MCP
participant A as Approval service
C->>T: "My blender arrived broken, order A-10293. I want my money back."
T->>R: intent=refund, sentiment=negative, lang=en
R->>O: get_order(A-10293) [customer from session]
O-->>R: delivered 2 days ago, total €129, item: blender
R->>P: search_policy("damaged item refund")
P-->>R: "Damaged on arrival: full refund, no return needed under €150 with photo"
R-->>C: "Sorry about that! Could you upload a photo of the damage?"
C->>R: photo
R->>R: vision check: damage visible
R->>PAY: issue_refund(A-10293, 129.00, "damaged")
PAY-->>R: PENDING_APPROVAL (amount > €100)
R->>A: approval request + evidence + reasoning
R-->>C: "I've requested a full refund of €129. You'll get confirmation within 2 hours."
A-->>R: approved by supervisor
R->>PAY: confirm refund (idempotency key)
R-->>C: "Your refund of €129 has been issued."
7. State and memory#
- Conversation state and checkpoints in PostgreSQL; the agent can pause for photos or approvals and resume on any pod.
- History management: running summary + last 6 turns + pinned facts (order ID, decision).
- Long-term memory: limited customer facts (preferred language, previous contacts summary) with retention limits.
8. Guardrails and security#
- Input: injection classifier on customer messages and email attachments; PII masking in logs.
- Actions: per-agent tool allow-lists; authorisation in every MCP server; financial limits in the payments service, not the prompt.
- Output: policy compliance (no promises outside policy), tone, no internal data leakage.
- Lethal-trifecta check: the agent reading untrusted email has no tool to send data to arbitrary external addresses.
- Kill switch per agent and per tool; anomaly alerts (refund volume spikes).
9. Evaluation and rollout#
- Offline: 500 scenario simulations with simulated customers and sandboxed MCP servers; metrics: task success, correct final state, policy violations (must be 0), pass^3 consistency, cost and steps per conversation.
- Red teaming: social engineering (“my manager approved a €500 refund”), injected instructions in emails, other customers’ order numbers.
- Rollout: shadow mode → approval for all actions → auto-approve within limits → expand to email and more languages.
- Online: resolution rate, escalation rate, CSAT, re-contact within 7 days, refund accuracy audits on samples.
10. Trade-offs to discuss#
| Decision | Choice | Trade-off |
|---|---|---|
| Specialists vs one agent | Router + 3 specialists | Better focus and security; more components and hand-off logic |
| Tools via MCP | Domain-owned MCP servers behind a gateway | Reuse by other AI apps and governance; extra hop and platform work |
| Approval threshold | €100 | Lower → safer, more human work; higher → more automation, more risk |
| Model tiers | Small for triage, mid-tier for specialists | Frontier only for hard cases if evaluation shows a gain |
| Degraded mode | Route all to humans with transcript | Protects customers; capacity planning for human team |
Summary#
- Router plus specialised agents with small tool sets; humans for sensitive cases and approvals.
- Tools as domain-owned MCP servers behind a gateway; identity from the session; limits enforced in services.
- Durable state for pauses; idempotent financial actions; full audit.
- Evaluate with simulations and red teaming; roll out autonomy progressively.