System design: how would you build an AI customer-support agent?

Learning path, stage 5 of 5: Shipping to production · question 10 of 10

Start from the workflow, not the model. Ground answers in a help-centre RAG index, give the agent a small set of scoped tools (look up an order, check a refund policy, create a ticket), require approval or hard policy checks for money-moving actions, hand off to people when confidence is low or the customer asks, and run evals plus tracing from day one. Measure resolution rate, CSAT and escalation accuracy, not just answer quality.

Architecture

  1. Channel layer: chat widget or email → conversation service (auth, session, rate limits).
  2. Router: classify intent and risk. FAQs go to a cheap path, account actions go to the agent.
  3. Agent: system prompt with the policies, plus tools:
    • search_help_center (RAG)
    • get_order(order_id), scoped to the authenticated customer
    • issue_refund(order_id, amount), with hard limits in code and approval above a threshold
    • escalate_to_human(summary)
  4. Guardrails: PII redaction in logs, injection-aware handling of customer text, output checks (no promises outside policy).
  5. Memory: conversation state, plus a short customer profile (no raw history dumps).
  6. Observability and evals: traces, cost per conversation, an eval set built from real transcripts, regression tests.

Key trade-offs to discuss

  • Workflow vs agent: use deterministic flows for refunds and cancellations, and agent flexibility for diagnosis.
  • Model mix: a small model for routing and summaries, a strong model for hard cases.
  • Handoff: pass a summary plus the full transcript so the customer never repeats themselves.
  • Rollout: shadow mode → assist mode (drafts for people to send) → autonomy on low-risk intents.

Sources

Code example

tsx
1// Support-agent tools with policy enforced in code, not in the prompt.
2import Anthropic from "@anthropic-ai/sdk";
3
4export const supportTools: Anthropic.Tool[] = [
5 {
6 name: "get_order",
7 description: "Fetch an order belonging to the signed-in customer. Returns status, items, total.",
8 input_schema: { type: "object", properties: { order_id: { type: "string" } }, required: ["order_id"] },
9 },
10 {
11 name: "issue_refund",
12 description: "Refund part or all of an order. Only for orders delivered in the last 30 days.",
13 input_schema: {
14 type: "object",
15 properties: { order_id: { type: "string" }, amount: { type: "number" }, reason: { type: "string" } },
16 required: ["order_id", "amount", "reason"],
17 },
18 },
19 {
20 name: "escalate_to_human",
21 description: "Hand off to a human agent with a short summary. Use when unsure or the customer asks.",
22 input_schema: { type: "object", properties: { summary: { type: "string" } }, required: ["summary"] },
23 },
24];
25
26declare const db: { order(id: string, customerId: string): Promise<{ total: number; deliveredAt: Date } | null> };
27
28export async function issueRefund(customerId: string, input: { order_id: string; amount: number }) {
29 const order = await db.order(input.order_id, customerId); // scoped to THIS customer
30 if (!order) return "Error: order not found for this customer.";
31 const days = (Date.now() - order.deliveredAt.getTime()) / 864e5;
32 if (days > 30) return "Error: outside the 30-day refund window. Offer escalation.";
33 if (input.amount > order.total) return "Error: amount exceeds order total.";
34 if (input.amount > 100) return "PENDING_APPROVAL: a human will review refunds over $100.";
35 return `Refunded $${input.amount.toFixed(2)} on ${input.order_id}.`;
36}

To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod @opentelemetry/api vitest, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.

Open in study app