Chapter 16 – Case Studies and Composite Architectures

Patterns in Practice

Throughout this book, we’ve examined individual patterns in isolation. In the real world, effective agent systems combine multiple patterns into composite architectures tailored to specific use cases. This chapter presents case studies showing how the patterns come together.

Case Study 1: Coding Agent (SWE-Bench Style)

Problem

Given a GitHub issue description, automatically navigate a codebase, understand the problem, and produce a working fix.

Architecture

This is one of the most successful applications of agentic AI. Anthropic’s coding agent, which achieves state-of-the-art results on the SWE-bench Verified benchmark, uses a relatively simple architecture:

    ┌─────────────────────────────────────────┐
    │         Coding Agent Architecture       │
    │                                         │
    │  ┌─────────┐    ┌───────────────────┐   │
    │  │  Issue   │───►│    Agent Loop     │   │
    │  │  Input   │    │  (ReAct Pattern)  │   │
    │  └─────────┘    └───────┬───────────┘   │
    │                         │               │
    │              ┌──────────┼──────────┐    │
    │              │          │          │    │
    │         ┌────▼───┐ ┌───▼────┐ ┌───▼──┐ │
    │         │ Search │ │  Read  │ │ Edit │ │
    │         │ Code   │ │  File  │ │ File │ │
    │         └────────┘ └────────┘ └──────┘ │
    │              │          │          │    │
    │         ┌────▼───┐ ┌───▼────┐ ┌───▼──┐ │
    │         │  List  │ │  Run   │ │ Bash │ │
    │         │  Dir   │ │ Tests  │ │ Cmd  │ │
    │         └────────┘ └────────┘ └──────┘ │
    │                                         │
    └─────────────────────────────────────────┘

Patterns Used

Pattern How It’s Used
Agent Loop Core execution: reason about the issue, explore code, make changes, test
Tool Use File operations, code search, test execution, bash commands
Planning Implicit — the agent decides what files to examine and in what order
Reflection Agent runs tests and uses failures to revise its changes
ACI Design Critical — tools use absolute paths, return focused results

Key Insight

“We actually spent more time optimizing our tools than the overall prompt.” — Anthropic

The tool interface design (Chapter 13) was the single most impactful investment. When they switched from relative to absolute file paths, tool-use errors dropped to near zero.

Simplified Implementation

# See code/case_study_coding_agent.py for the full implementation

def coding_agent(issue_description, repo_path, llm):
    """A simplified coding agent."""
    
    tools = [
        search_codebase,    # Find relevant files
        read_file,          # Read file contents
        edit_file,          # Make changes
        run_tests,          # Execute test suite
        run_command,        # Run bash commands
        list_directory,     # Explore file structure
    ]
    
    system = (
        f"You are a senior software engineer. Fix the following issue "
        f"in the repository at {repo_path}.\n\n"
        f"Process:\n"
        f"1. Understand the issue\n"
        f"2. Find the relevant code\n"
        f"3. Make the fix\n"
        f"4. Run tests to verify\n"
        f"5. If tests fail, iterate\n\n"
        f"Always use absolute file paths."
    )
    
    return agent_loop(
        goal=issue_description,
        tools=tools,
        llm=llm,
        system=system,
        max_iterations=30
    )

Case Study 2: Customer Support Agent

Problem

Handle customer inquiries with access to order history, product catalog, knowledge base, and the ability to take actions (issue refunds, update tickets).

Architecture

    ┌────────────────────────────────────────────┐
    │     Customer Support Agent Architecture    │
    │                                            │
    │  ┌──────────┐    ┌───────────────────┐     │
    │  │ Customer  │───►│     Router        │     │
    │  │ Message   │    │ (Classification)  │     │
    │  └──────────┘    └──┬──────┬──────┬──┘     │
    │                     │      │      │        │
    │              ┌──────▼┐  ┌──▼───┐ ┌▼──────┐ │
    │              │General│  │Refund│ │ Tech  │ │
    │              │ Q&A   │  │Agent │ │Support│ │
    │              └───┬───┘  └──┬───┘ └───┬───┘ │
    │                  │         │         │     │
    │              ┌───▼─────────▼─────────▼───┐ │
    │              │      Shared Tools         │ │
    │              │ (KB, Orders, Actions)     │ │
    │              └───────────────────────────┘ │
    └────────────────────────────────────────────┘

Patterns Used

Pattern How It’s Used
Routing Classify inquiry type and direct to specialist
Tool Use Access customer data, knowledge base, take actions
Guardrails Parallel safety screening of messages
Human-in-the-Loop Escalation for complex or sensitive cases
Memory Remember customer context within the session

Key Insight

Customer support is a natural fit for agents because:

Case Study 3: Research Assistant

Problem

Given a research topic, produce a comprehensive, well-sourced report by searching multiple information sources and synthesizing findings.

Architecture

    ┌─────────────────────────────────────────────┐
    │      Research Assistant Architecture        │
    │                                             │
    │  ┌──────────┐    ┌───────────────────────┐  │
    │  │ Research  │───►│   Orchestrator        │  │
    │  │ Question  │    │ (Plan Research)       │  │
    │  └──────────┘    └──┬──────┬──────┬──────┘  │
    │                     │      │      │         │
    │              ┌──────▼┐  ┌──▼───┐ ┌▼──────┐  │
    │              │ Web   │  │ArXiv │ │Domain │  │
    │              │Search │  │Search│ │Search │  │
    │              │Worker │  │Worker│ │Worker │  │
    │              └───┬───┘  └──┬───┘ └───┬───┘  │
    │                  │         │         │      │
    │              ┌───▼─────────▼─────────▼───┐  │
    │              │      Synthesizer          │  │
    │              │ (Combine + Evaluate)      │  │
    │              └──────────┬────────────────┘  │
    │                         │                   │
    │              ┌──────────▼────────────────┐  │
    │              │     Fact-Checker          │  │
    │              │ (Verify Claims)           │  │
    │              └───────────────────────────┘  │
    └─────────────────────────────────────────────┘

Patterns Used

Pattern How It’s Used
Orchestrator-Workers Orchestrator plans research, workers search different sources
Parallelization Multiple search workers run simultaneously
Evaluator-Optimizer Fact-checker evaluates and the writer revises
Tool Use Web search, academic search, document retrieval
Planning Orchestrator decides what subtopics to investigate

Case Study 4: Data Pipeline Agent

Problem

Automate data extraction, transformation, and loading (ETL) with an agent that can handle schema changes, data quality issues, and pipeline failures.

Architecture

    ┌───────────────────────────────────────────┐
    │     Data Pipeline Agent Architecture      │
    │                                           │
    │  ┌──────────┐   ┌─────────────────────┐   │
    │  │ Pipeline  │──►│  Schema Analyzer    │   │
    │  │ Config    │   │  (Understand data)  │   │
    │  └──────────┘   └────────┬────────────┘   │
    │                          │                │
    │                 ┌────────▼────────────┐    │
    │                 │  Transform Planner  │    │
    │                 │ (Plan ETL steps)    │    │
    │                 └────────┬────────────┘    │
    │                          │                │
    │              ┌───────────┼────────────┐    │
    │              │           │            │    │
    │         ┌────▼───┐ ┌────▼────┐ ┌─────▼──┐ │
    │         │Extract │ │Transform│ │  Load  │ │
    │         │ Agent  │ │  Agent  │ │  Agent │ │
    │         └────────┘ └─────────┘ └────────┘ │
    │                          │                │
    │                 ┌────────▼────────────┐    │
    │                 │  Quality Validator  │    │
    │                 │(Check data quality) │    │
    │                 └────────────────────┘    │
    └───────────────────────────────────────────┘

Patterns Used

Pattern How It’s Used
Prompt Chaining Fixed E → T → L pipeline structure
Reflection Quality validator checks output and triggers fixes
Tool Use Database queries, file I/O, API calls
Planning Transform planner generates SQL/Python transformations

Composing Patterns: A Decision Framework

When designing a new agent system, use this decision tree:

Is the task simple enough for a single LLM call?
├── Yes → Use a single call with good prompting
└── No → Can the steps be defined in advance?
    ├── Yes → Use Prompt Chaining (Ch. 7)
    │   └── Do different inputs need different handling?
    │       └── Yes → Add Routing (Ch. 8)
    └── No → Does the task need multiple perspectives?
        ├── Yes → Use Multi-Agent Collaboration (Ch. 6)
        └── No → Does the task have clear quality criteria?
            ├── Yes → Use Evaluator-Optimizer (Ch. 11)
            └── No → Use an Agent Loop with Planning (Ch. 2, 5)
                └── Are subtasks independent?
                    └── Yes → Add Parallelization (Ch. 9)

Anti-Patterns to Avoid

1. Over-Engineering

Building a multi-agent orchestration system when a simple prompt chain would suffice. Always start with the simplest solution.

2. Agent Soup

Too many agents with unclear responsibilities, leading to redundant work and conflicting outputs.

3. Infinite Loops

Agents that keep trying to improve their output without meaningful progress. Always set hard limits on iterations.

4. Context Stuffing

Putting everything into the LLM context instead of using tools for targeted retrieval. This leads to poor performance and high costs.

5. Trust Without Verify

Assuming agent outputs are correct without verification. Always build in checks, especially for actions that affect external systems.

6. One-Size-Fits-All

Using the same model for every task. Route simple tasks to cheaper models and reserve expensive models for tasks that truly need them.

The Future of Agentic Systems

The agentic AI landscape is evolving at extraordinary speed. Several trends are likely to shape the near future:

  1. Better tool use — Models are becoming more reliable at using tools, reducing the need for complex error handling
  2. Longer context windows — As context windows grow, some memory management complexity decreases
  3. Faster inference — Lower latency makes multi-step agent workflows more practical for interactive applications
  4. Standardized protocols — MCP and similar standards will create a rich ecosystem of reusable tools
  5. Specialized agent models — Models fine-tuned specifically for agentic tasks will improve reliability
  6. Multi-modal agents — Agents that can see, hear, and interact with the physical world through robotics

Summary

The most successful agent implementations share three principles:

  1. Simplicity — Start simple and add complexity only when it demonstrably improves outcomes
  2. Transparency — Make the agent’s reasoning and planning steps visible and auditable
  3. Careful tool design — Invest in your Agent-Computer Interface as much as your prompts

The patterns in this book are building blocks, not blueprints. The right architecture for your application will combine and adapt these patterns based on your specific requirements, constraints, and goals.

Build the right system for your needs. Test relentlessly. Iterate on your tools. And ship.


Navigation: