CONTENTS
CHAPTER 13

Three designs, end to end

6 MIN READ

Reading about components is one thing. Designing a system means choosing among them under real constraints. This chapter walks through three designs using the method from Chapter 2, so you can see the reasoning, not just the result. Each is the kind of problem you'd meet at work or in a system design interview.

Design 1: a documentation assistant for a developer platform

Task. Developers ask questions about a platform with 4,000 pages of docs across three major versions, plus a changelog and an API reference. The assistant answers with citations, or says it doesn't know.

Quality bar. Correct for the user's version, every factual claim cited, refuses when the docs don't cover it. The cost of an error is moderate: a wrong answer wastes a developer's afternoon and erodes trust, but isn't dangerous. The docs team's lead is the judge of quality.

Budgets. First token within 1.5 seconds at p95; answers under 300 words; under $0.02 per question at 50,000 questions per day.

Napkin math. 4,000 pages is several million tokens, far over the "just put it in context" threshold, so retrieval it is. Context per request: 1,200-token system prompt, about 6,000 tokens of retrieved chunks, 800 tokens of history, 300-token answer.

Design.

 question + chosen version
      │
      ▼
 rewrite (small model): standalone query + filters {version, product area}
      │
      ▼
 hybrid search (BM25 + embeddings, filtered by version) ─► RRF ─► rerank top 100 → 12
      │
      ▼
 answer (mid-size model): cite chunk IDs, "not found" path
      │
      ▼
 check: every citation exists in context; links rendered from our own URLs only
      │
      ▼
 stream to user, with sources and thumbs up/down

Key decisions and why.

  • Version as a metadata filter, not a prompt instruction. "Wrong version" was the top failure category in error analysis; filtering at search time removes it structurally.
  • Hybrid search. Developers search for exact identifiers (function names, error codes) that embeddings blur.
  • Contextual chunk descriptions at index time, via the batch API to halve the cost.
  • A mid-size model, not the largest. Evals showed answer quality was limited by retrieval, not by the writer.
  • Prompt caching on the system prompt; history after it.
  • Links rendered from known URLs only, so the model can't produce arbitrary links (an output-handling defense).

Evals. A synthetic retrieval set (recall@12) generated from chunks, then replaced by real questions from logs. Code checks for citations and length. Two binary judges, built with critique shadowing with the docs lead: "answers the actual question" and "claims supported by cited chunks". A set of unanswerable questions to test refusal.

What would change it. If questions turn into multi-step debugging ("why does my deploy fail with this log?"), add a bounded agentic step with search and log-reading tools. If the docs were 200 pages, skip RAG entirely.

Design 2: a customer support agent that can take actions

Task. An e-commerce company wants an agent that resolves order issues: tracking, address changes before shipment, returns, and refunds up to $100. Anything else goes to a human.

Quality bar. Resolved correctly without a human, never a wrong refund, never acting on another customer's account. The cost of an error is high for actions (money, privacy) and moderate for answers. The head of support is the judge.

Budgets. Replies start within 2 seconds; conversations average 6 turns; under $0.40 per resolved conversation (a human-handled ticket costs about $6).

Architecture choice. This needs an agent: conversations branch unpredictably, and the environment (order APIs) gives clear feedback. But the action space should be small and guarded.

 customer (authenticated session: customer_id)
      │
      ▼
 input guardrail (fast classifier, in parallel with the agent's first step)
      │
      ▼
 agent loop (large model) ── tools ──► orders_search      (read)
      │                               ► order_track        (read)
      │                               ► address_update     (write, only if not shipped)
      │                               ► return_create      (write)
      │                               ► refund_issue       (write, ≤ $100, idempotent)
      │                               ► handoff_to_human   (always available)
      ▼
 policy layer (code): customer_id injected from session; amount limits;
                      order ownership checked; idempotency keys; audit log
      │
      ▼
 durable state per conversation (resume after crash; wait for warehouse callbacks)

Key decisions and why.

  • customer_id comes from the session, never from the model. The model can't be talked into acting on someone else's account, because it never chooses the account.
  • Limits in code, not in the prompt. The prompt says refunds are capped at $100; the policy layer enforces it. An injected or confused model can't exceed it.
  • Rule of Two check. The agent reads untrusted input (customer messages) [A] and changes state [C]. Its access to sensitive data [B] is limited to the authenticated customer's own orders, and it has no outbound channel except replying to that same customer. Product descriptions and reviews (which outsiders write) are kept out of its context.
  • Idempotent writes with keys derived from conversation and step, so a crash and resume can't double-refund.
  • Handoff as a tool, with a summary of the conversation, so the human doesn't start from zero.
  • Refunds over $100 or repeated refunds on one account go to human approval, which can wait hours (durable state).

Evals. A simulated-customer harness in the style of τ-bench: an LLM plays customers with scripted goals against a sandboxed order system, and success is judged by the final database state. Measure pass^k with k=4k = 4 on each scenario, because the agent handles the same scenario thousands of times a day. Error analysis on production traces weekly. Red-team scenarios: customers claiming to be someone else, injected instructions in messages, attempts to exceed limits.

What would change it. If volume is very high and most conversations are tracking questions, put a router in front: tracking goes to a simple workflow with a small model, and only the rest reaches the agent.

Design 3: a research report generator

Task. Analysts request reports such as "competitive landscape for battery recycling startups in Europe." The system searches the web and internal documents, and produces a 3,000-word report with citations within 15 minutes.

Quality bar. Comprehensive, accurate, well-sourced. Errors are moderate-cost because an analyst reviews every report. Value per report is high (it replaces a day of work).

Budgets. Up to 15 minutes; up to $5 per report.

Architecture choice. Breadth-first research over independent sources is exactly where Anthropic found multi-agent orchestration strongest. The high value per task justifies roughly 15× chat-level token use.

 request ─► lead agent: clarify scope, write plan (saved to state)
               │
               ├─► sub-agent: market size        ─┐
               ├─► sub-agent: company profiles    │  each: own context, web + internal
               ├─► sub-agent: regulation          │  search tools, brief with objective,
               └─► sub-agent: technology          ─┘  format, sources, boundaries
               │                                       returns ≤ 1,500-token findings
               ▼
            lead agent: synthesize, find gaps, maybe spawn round 2
               │
               ▼
            writer: draft report from findings
               │
               ▼
            citation pass: attach and verify sources ─► evaluator: rubric check ─► analyst

Key decisions and why.

  • Sub-agents only read and return findings; one writer writes. This follows Cognition's warning: the parts that make interdependent decisions (the report's structure and argument) stay in one context.
  • Detailed briefs for each sub-agent, with explicit boundaries to avoid duplicate work.
  • Security. Web content is untrusted, and internal documents are private. The research agents have no outbound actions beyond search queries, and those queries are a narrow channel (an injected page could still try to leak data through a search string, so internal documents are summarized by a separate sub-agent that has no web access). That breaks the trifecta: no single context has private data, untrusted content and an open channel out.
  • Checkpoints after each phase, so a crashed run resumes rather than restarts and burns another $5.
  • An evaluator-optimizer pass with a rubric (coverage, source quality, claims supported) before the analyst sees it.

Evals. Start, as Anthropic did, with about 20 real requests and the analysts' judgment of the outputs. Code checks: every claim with a number has a citation; every citation resolves. An LLM judge per rubric item, calibrated against analyst critiques. Track cost and duration per report; token use is the main cost driver.

The pattern behind all three

Look at what the three designs share:

  1. Structure removes failure classes. Version filters, injected IDs, limits in code, citation checks. Whenever possible, a failure was made impossible rather than less likely.
  2. The model decides only what needs judgment. Everything else is code.
  3. Every design has an eval plan that came from the quality bar, not from a generic metric list.
  4. Security is in the data flow, not in the prompt.
  5. Complexity matches value. The docs assistant is a pipeline. The support agent is one agent with guarded tools. Only the high-value research task uses multiple agents.

That's AI system design. The model is a remarkable component, and the system around it is what makes it a product.

Key takeaways

  • Run the method: quality bar, budgets, napkin math, lightest architecture, failure modes, measurement.
  • Turn top failure categories into structural fixes (filters, injected values, code-enforced limits).
  • Match architecture complexity to the value and error cost of the task.
  • Put security in the data flow; check every agent against the trifecta and the Rule of Two.

Exercises

  1. Design an AI feature that summarizes a team's Slack channels into a daily digest. Run the full method and draw the architecture.
  2. Take Design 2 and add a voice channel (phone support). What changes in the latency budget and the architecture?
  3. Pick one of the three designs and argue for a simpler version. What would you give up, and how would you measure whether it mattered?