Part VII: Frontier Techniques & Future
Chapter 34

Agents & Multi-Agent Systems

The agent loop, planning, tool use, and orchestration
20 Exercises
34.1

We have built models that can reason (Chapter 25), use tools (Chapter 28), retrieve knowledge (Chapter 29), and remember long contexts (Chapter 33). This chapter brings them together into AGENTS — systems that pursue GOALS autonomously over many steps, deciding for themselves what to do next. An agent is where all the book's capabilities converge into something that can act in the world with a degree of independence.

Agent vs Single Model Call

A normal model call is a single round-trip: you ask, it answers, done. An AGENT is fundamentally different: given a GOAL, it operates in a LOOP — deciding what to do, taking an action (often a tool call), observing the result, deciding the next action, and continuing until the goal is achieved. The agent is not just responding; it is autonomously working toward an objective across many steps, charting its own course.

Single model callAgent
One question, one answerA goal pursued over many steps
You drive each stepThe agent decides the next step
Stateless round-tripMaintains state across a loop
No tools, or one callOrchestrates many tools
You: 'What is X?'You: 'Accomplish goal G'
ReactiveAutonomous, goal-directed
Agent
A system that uses a language model in a loop to autonomously pursue a goal — planning, taking actions (often via tools), observing results, and deciding subsequent actions until the goal is achieved or abandoned.

The Ingredients of an Agent

An agent combines several capabilities from across this book into a coherent goal-pursuing system. The model is the 'brain' that decides; tools let it act; memory lets it track progress; planning lets it sequence steps; reflection lets it correct mistakes. The agent loop ties them together. Each ingredient was covered earlier; the agent is their integration.

Arch Stack: The ingredients of an agent

Goalwhat the agent is trying to achieve
Model (the brain)reasons and decides (Ch. 25)
Planningdecomposes the goal into steps (§34.3)
Toolslet the agent act in the world (Ch. 28)
Memorytracks progress and recalls the past (§34.5)
Reflectionchecks and corrects its own work (§34.4)
Agent Note: Agents Are Where Everything Converges
Notice that an agent is not a new MODEL — it is a SYSTEM built around a model, integrating reasoning, tools, retrieval, and memory into an autonomous loop. This is why agents come at the end of the book: they require everything that came before. The model provides intelligence; the agent architecture turns that intelligence into autonomous, multi-step action toward goals.
This also means agents inherit all the strengths AND weaknesses of their components. A reasoning mistake, a tool failure, a memory lapse, or a bad plan can derail the whole agent. Building reliable agents is largely about managing this compounding of component behaviours — the theme that runs through this chapter.
34.2

At the heart of every agent is a LOOP. The agent perceives its situation, decides what to do, acts, observes the result, and repeats — until the goal is met. This generalizes the tool-calling loop of Chapter 28 and the ReAct framework of Chapter 28 into the core engine of autonomous behaviour. Understanding the loop is understanding agents.

Tool Trace: The agent loop in action: 'Book a table for 4 tomorrow at 7pm'

AgentPlan: find restaurants, check availability, book one
AgentAction: search('restaurants near me, 4 people')
ToolReturns a list of nearby restaurants
AgentObserve + decide: check the top option's availability
AgentAction: check_availability(restaurant, tomorrow 7pm, 4)
ToolReturns: available
AgentAction: book(restaurant, tomorrow 7pm, 4)
AgentGoal achieved → report success to the user
textThe general agent loop (Pseudocode)
# Given a goal, loop until done (with a step cap)
state = initial_observation(goal)
for step in range(max_steps):
    thought = model.reason(goal, state, memory)   # decide what to do
    if thought.is_done:
        return thought.answer
    action = thought.action                       # often a tool call
    observation = execute(action)                 # act in the world
    state = update(state, action, observation)     # observe
    memory.record(action, observation)            # remember
# The loop is the engine; planning, reflection, memory enrich it

Generalizing ReAct

The agent loop is essentially the ReAct pattern (Chapter 28) — Thought, Action, Observation — scaled up with planning, memory, and the autonomy to pursue a multi-step goal. ReAct gave us the basic interleaving of reasoning and acting; the agent loop adds the structure to sustain it over long, goal-directed trajectories. Everything in the rest of this chapter — planning, reflection, memory, multi-agent — enriches this fundamental loop.

Agent Note: The Loop Must Be Bounded
A critical practical point (from Chapter 28, now essential): the agent loop MUST be bounded — a maximum number of steps, a budget, a timeout. An autonomous loop that decides its own next action can, if something goes wrong, loop forever, rack up cost, or wander off-task. Every robust agent has guardrails: step caps, cost limits, and stopping conditions. The autonomy that makes agents powerful is also what makes them dangerous without bounds.
This tension — between giving the agent enough autonomy to be useful and enough constraint to be safe and reliable — runs through agent design. Too constrained and the agent can't accomplish much; too free and it becomes unpredictable and costly. Finding the balance is central to building agents that work.
34.3

A complex goal cannot be achieved in one action — it must be broken into a sequence of smaller steps. PLANNING is how an agent decomposes a goal into a structured set of subtasks and decides the order to tackle them. Good planning is what lets agents handle complex, multi-step objectives rather than just simple ones.

Why Planning Helps

Without planning, an agent reacts step by step with no overall strategy — it may pursue a dead end, miss a necessary prerequisite, or wander. Planning first — 'to book a trip I need to: choose dates, find flights, find a hotel, book both' — gives the agent a roadmap. It can then execute the plan, adapting as it goes. Planning is the difference between purposeful progress and aimless flailing.

Planning approachHow it works
Plan-then-executeMake a full plan upfront, then carry it out step by step
Interleaved (ReAct)Plan and act together; replan as you observe results
DecompositionBreak the goal into subtasks, possibly recursively
Tree-of-thoughtsExplore multiple plan branches, pick the best (Ch. 25 search)
Plan + reflectMake a plan, critique it, revise before executing

Plan-Then-Execute vs Interleaved

Two broad styles. PLAN-THEN-EXECUTE makes a complete plan first, then runs it — good for predictable tasks, but brittle if reality diverges from the plan. INTERLEAVED planning (the ReAct style) plans a step, acts, observes, and replans based on what happened — more adaptive, handling surprises, but potentially less coherent over long horizons. Many agents combine them: a high-level plan that is refined and adapted as execution reveals new information.

Tool Trace: Planning then executing a complex goal

AgentGoal: 'Write a report on our Q3 sales'
AgentPlan: (1) get sales data (2) analyze trends (3) draft (4) review
AgentStep 1: query the sales database
ToolReturns Q3 sales figures
AgentStep 2: analyze — reasons over the figures
AgentStep 3: draft the report; Step 4: review and revise
AgentPlan complete → deliver the report
Agent Note: Planning Is Hard for Current Models
An honest caveat: planning is one of the WEAKER abilities of current LLM agents. Models can produce plausible-looking plans, but they struggle with long-horizon planning, often miss prerequisites, fail to account for constraints, and don't reliably recover when a plan goes wrong. Complex multi-step tasks where each step depends on the last are where agents most often fail. Planning ability is improving (especially with reasoning models, Chapter 25) but remains a frontier limitation.
This is why robust agents lean on REFLECTION (next section) and replanning: rather than trusting an upfront plan, they continually check progress and adjust. The combination of modest planning plus strong reflection and adaptation is more reliable than betting everything on a perfect initial plan.
34.4

Agents make mistakes — a wrong tool call, a flawed step, a misread result. REFLECTION is the ability of an agent to EVALUATE its own work, recognize problems, and correct course. It is one of the most powerful techniques for making agents reliable, and it builds on the 'models judge better than they generate' asymmetry we saw in RLHF (Chapter 23) and Constitutional AI (Chapter 26).

The Reflect-and-Revise Pattern

Reflection adds a CRITIQUE step to the agent loop. After producing a result (or completing a step), the agent steps back and asks: 'Is this correct? Does it achieve the goal? What's wrong with it?'. Based on this self-critique, it revises and retries. This catches errors the agent would otherwise propagate, and often dramatically improves output quality — the same way a writer improves a draft by re-reading it critically.

Tool Trace: Reflection: the agent critiques and fixes its own work

AgentWrites code to solve the task
ToolRuns the code → test fails with an error
AgentReflect: 'The error says index out of range — I had an off-by-one'
AgentRevise: fixes the bug and resubmits
ToolRuns again → tests pass
AgentReflect: 'Tests pass, goal achieved' → done

Reflection Frameworks

Several frameworks formalize reflection. Reflexion (Shinn et al., 2023) has agents verbally reflect on failures and store those reflections to do better on retries. Self-refine has the model iteratively critique and improve its own output. Critic/actor patterns separate a 'doer' agent from a 'critic' agent that reviews its work. All exploit the same insight: a model is often better at SPOTTING a problem in a result than at AVOIDING it in the first place.

Agent Note: Reflection Exploits the Generate-Evaluate Gap
Reflection works for the same reason RLHF and Constitutional AI work (Chapters 23, 26): models are better JUDGES than GENERATORS. An agent may produce a flawed solution but readily recognize the flaw when asked to evaluate it. Reflection turns this asymmetry into a self-improvement loop — generate, critique, revise — that catches and fixes errors automatically. It is one of the highest-value additions to an agent.
Especially powerful is reflection with EXTERNAL feedback: when the agent can actually RUN its code, TEST its answer, or CHECK a result against ground truth, its reflection is grounded in reality rather than just self-assessment. Grounded reflection (run the tests, see the error, fix it) is far more reliable than ungrounded self-critique, connecting to the verifiable rewards of Chapter 25.
34.5

An agent working over many steps needs MEMORY — to track what it has done, remember key facts, and recall relevant past experience. Memory is what lets an agent maintain coherence over a long task and learn across tasks. It comes in several kinds, mirroring human memory, and connects directly to the long-context and external-memory ideas of Chapter 33.

Types of Agent Memory

Memory typeHoldsImplemented as
Working / short-termCurrent task state, recent stepsThe context window
Long-termFacts learned across tasks/sessionsExternal store + retrieval
EpisodicRecords of past experiences/tasksStored trajectories
SemanticGeneral knowledge, learned factsKnowledge base / RAG
ProceduralHow to do things, learned skillsStored routines / examples

Short-Term vs Long-Term

SHORT-TERM (working) memory is the agent's current context — the recent steps, the active task state — held in the context window (Chapter 33). It is fast but limited and lost when the context fills or the session ends. LONG-TERM memory persists across the limited window and across sessions: important information is written to an external store and retrieved when relevant (exactly the MemGPT/RAG idea from Chapters 29 and 33). Together they let an agent both focus on the now and draw on accumulated experience.

Tool Trace: An agent using long-term memory

AgentStarts a task; checks memory for relevant past experience
MemoryRetrieves: 'last time, the API needed auth in a header'
AgentApplies the recalled lesson, avoiding the past mistake
AgentCompletes the task; writes new lessons to memory
MemoryStores the experience for future tasks
Agent Note: Memory Turns Agents Into Learners
Memory is what lets an agent IMPROVE over time without retraining the model. By recording what worked and what failed, and retrieving those lessons when facing similar situations, an agent can get better at recurring tasks — a kind of learning that lives in the memory store, not the weights. This is powerful for agents that operate continuously: they accumulate experience the way a human employee learns a job over months.
It also raises the design challenges of any memory system: what to store, when to retrieve, how to keep memory relevant and not cluttered, and how to forget the obsolete. These echo the retrieval challenges of Chapter 29 — agent memory is largely a RAG problem applied to the agent's own experience, with the same chunking, embedding, and retrieval concerns.
34.6

A capable agent has many tools (Chapter 28) — search, code execution, databases, APIs, file access — and must ORCHESTRATE them: choosing the right tool for each step, sequencing them, passing results between them, and combining their outputs. Tool orchestration is where the tool-calling of Chapter 28 scales up into coordinated, multi-tool problem-solving.

The Orchestration Challenges

With many tools, the agent faces new challenges beyond single tool calls. It must SELECT the right tool from many (harder with more options). It must SEQUENCE tools correctly (some depend on others' outputs — the sequential calls of Chapter 28). It must PASS DATA between tools (the output of one becomes the input to another). And it must HANDLE failures gracefully so one tool's error doesn't derail the whole task. Good orchestration makes a many-tool agent feel coherent rather than chaotic.

Tool Trace: Orchestrating multiple tools for a research task

AgentGoal: 'Summarize recent news about company X'
AgentTool 1: web_search('company X recent news')
ToolReturns article URLs
AgentTool 2: fetch_page(top URLs) — uses search's output
ToolReturns article contents
AgentTool 3: summarize — reasons over fetched content
AgentCombines into a coherent summary → deliver

Managing Many Tools

As the number of tools grows, selection becomes harder — the model must pick correctly from dozens or hundreds. Techniques help: grouping related tools, retrieving only the RELEVANT tools for the current task (tool RAG — embed tool descriptions, retrieve the ones matching the step), and hierarchical organization (high-level tools that internally use lower-level ones). The same description-quality lesson from Chapter 28 applies: clear tool descriptions are what let the agent orchestrate many tools well.

Agent Note: Orchestration Is Where Reliability Is Won or Lost
Multi-tool orchestration is where the compounding-error problem (Section 34.1) bites hardest. Each tool call is a chance for a wrong selection, a malformed argument, or a failure — and in a long orchestration, these chances multiply. An agent making 20 tool calls, each 95% reliable, succeeds end-to-end only about a third of the time. This is why error handling, validation, and reflection (Sections 34.4) are not optional for real agents — they are what keep the compounding from destroying reliability.
The practical implication echoes Chapter 28: most of the engineering in a production agent goes into making orchestration robust — validating each step, recovering from failures, and verifying progress — not into the happy path. Reliable orchestration is the hard, unglamorous core of useful agents.
34.7

So far, one agent. But some problems are better solved by MULTIPLE agents working together — each specialized, collaborating, debating, or dividing labor. Multi-agent systems are an active frontier, promising to tackle complex problems beyond any single agent. Let us understand when and how multiple agents help.

Why Use Multiple Agents?

Several motivations. SPECIALIZATION: different agents can be experts at different things (a coder agent, a reviewer agent, a researcher agent), each with tailored tools and prompts. SEPARATION OF CONCERNS: breaking a complex task across focused agents can be more reliable than one agent juggling everything. DIVERSE PERSPECTIVES: multiple agents can debate or critique each other, surfacing errors a single agent would miss. PARALLELISM: independent subtasks can be handled by different agents simultaneously.

BenefitHow multiple agents help
SpecializationEach agent expert at one role, with tailored tools/prompts
Separation of concernsFocused agents are more reliable than one doing everything
Diverse perspectivesAgents debate/critique, catching errors (like reflection)
ParallelismIndependent subtasks handled simultaneously
ModularityEasier to build, test, and improve focused agents
Intuition: A Team Instead of a Soloist
If a single agent is one person trying to do an entire complex project alone, a multi-agent system is a TEAM — with a manager who delegates, specialists who each handle their part, and reviewers who check the work. Just as human teams can tackle bigger projects than individuals (through specialization and division of labor), multi-agent systems aim to handle problems too complex or multifaceted for one agent. The manager (orchestrator) coordinates; the specialists (workers) execute.
But teams also have COORDINATION COSTS — communication overhead, misunderstandings, conflicting work. Multi-agent systems inherit these too: getting agents to coordinate effectively is hard, and a poorly-coordinated team of agents can be WORSE than a single capable agent. The promise is real, but so are the challenges, as we'll see.
34.8

Multiple agents must be ORGANIZED — who decides what, who talks to whom, how work flows. Several coordination patterns have emerged, each suited to different problems. Knowing them helps you design multi-agent systems and understand frameworks like AutoGen and LangGraph.

PatternHow it works
Orchestrator-workerA manager agent plans and delegates subtasks to worker agents
Pipeline / sequentialAgents in a chain; each does its stage, passes to the next
DebateAgents argue different positions; converge or a judge decides
HierarchicalManagers of managers — nested delegation
Blackboard / shared stateAgents read/write a shared workspace, coordinating loosely
Group chatAgents converse in a shared thread, taking turns (AutoGen)

Orchestrator-Worker: The Most Common Pattern

The dominant multi-agent pattern is ORCHESTRATOR-WORKER (also called manager-worker or supervisor). One ORCHESTRATOR agent receives the goal, breaks it into subtasks, and delegates each to a specialized WORKER agent. The workers execute and report back; the orchestrator synthesizes their results and decides next steps. It mirrors a manager delegating to a team — clear responsibility, easy to reason about, and flexible.

Tool Trace: Orchestrator-worker coordination

OrchestratorGoal: 'Build a feature' → plans and delegates
WorkerCoder agent: writes the implementation
WorkerTester agent: writes and runs tests
WorkerReviewer agent: reviews the code for quality
OrchestratorSynthesizes results; requests fixes if needed
OrchestratorFeature complete → report to user

Debate and Critique

In DEBATE patterns, multiple agents argue different positions or independently solve a problem, then compare and critique each other's answers — often with a judge agent deciding, or the agents converging through discussion. This can improve accuracy and surface errors (different agents catch different mistakes), echoing self-consistency (Chapter 25) and reflection. The diversity of independent attempts is the value: agents that reason differently are unlikely to all make the same mistake.

Agent Note: Frameworks Encode These Patterns
Frameworks like AutoGen (Microsoft) and LangGraph (LangChain) provide the plumbing for these coordination patterns — defining agents, their roles, how they communicate, and the control flow between them. AutoGen emphasizes conversational multi-agent collaboration (agents in a group chat); LangGraph models agent workflows as graphs (nodes are steps/agents, edges are control flow). They handle message passing, state, and orchestration so you focus on the agent roles and logic.
As with serving engines (Chapter 27) and RAG frameworks (Chapter 29): use the frameworks for the plumbing, but understand the underlying patterns — orchestrator-worker, pipeline, debate — so you can design effective systems and debug them when coordination goes wrong. The framework runs the loop; your understanding of the patterns is what makes the system work.
34.9

Multi-agent systems are promising but come with real challenges, and a sober view is essential. More agents introduce more coordination overhead, more places to fail, and more cost. Sometimes a single well-designed agent beats a complex multi-agent system.

ChallengeWhat goes wrong
Coordination overheadAgents spend effort communicating, not solving
Error propagationOne agent's mistake cascades through the others
Cost multiplicationMany agents = many model calls = high cost
MisalignmentAgents pursue subtly different interpretations of the goal
Conversation loopsAgents get stuck talking in circles without progress
LatencySequential agent steps add up to slow end-to-end time
Debugging difficultyHard to trace why a multi-agent system failed

Error Propagation and Cost

Two challenges stand out. ERROR PROPAGATION: in a chain or team of agents, one agent's mistake feeds into the next, compounding (the same multiplication problem as multi-tool orchestration, now across agents). COST: each agent is one or more model calls, so a multi-agent system can make many times more calls than a single agent — multiplying both cost and latency. A debate among 5 agents over 3 rounds is 15+ model calls for one answer.

⚠️
Multi-Agent Is Not Automatically Better
A crucial reality check: adding more agents does NOT automatically improve results, and often makes them worse — more expensive, slower, harder to debug, and more failure-prone. Many tasks are better solved by a single capable agent (or even a single well-prompted model call) than by an elaborate multi-agent system. Multi-agent shines for genuinely decomposable, parallelizable, or adversarial-checking tasks; for many others it adds complexity without benefit.
The discipline, echoing all of Parts VI–VII: start with the simplest approach that works. A single model call, then a single agent, then multiple agents — add complexity only when a real limitation forces it and the data shows it helps. The allure of sophisticated multi-agent architectures often outruns their actual benefit. Reach for them deliberately, not by default.
34.10

The recurring theme of agents is the gap between an impressive DEMO and a reliable SYSTEM. Agents that work in a demo often fail on the messy long tail of real tasks. Building agents that work CONSISTENTLY requires deliberate engineering for reliability, drawing together the lessons of this chapter and Chapter 28.

Reliability Techniques

Bound everything: step caps, time limits, cost budgets — so a runaway agent can't loop or overspend forever.
Reflect and verify: have the agent check its own work, and ground that checking in real feedback (run the code, test the result) where possible.
Validate at every step: check tool arguments, tool results, and intermediate state, returning clear errors the agent can recover from.
Handle failures gracefully: expect tools and steps to fail; retry sensibly, fall back, or escalate to a human.
Human-in-the-loop: require human approval for consequential actions, and let humans intervene when the agent is stuck.
Observe and trace: log every step so failures can be diagnosed (multi-step agents are hard to debug without traces).

The Compounding-Reliability Problem

The core reliability challenge is COMPOUNDING. An agent that takes many steps, each with some failure probability, has a success rate that is the PRODUCT of the per-step rates — which decays fast. Twenty steps at 95% each gives ~36% end-to-end success. This is why per-step reliability matters so much, and why reflection, verification, and error recovery (which catch and fix per-step failures before they compound) are essential. The longer the agent's trajectory, the more this matters.

textWhy long agent trajectories are fragile
End-to-end success ≈ (per-step success rate) ^ (number of steps)

  10 steps at 99% each → 0.99^10  ≈ 90%
  20 steps at 95% each → 0.95^20  ≈ 36%
  50 steps at 90% each → 0.90^50  ≈  0.5%

# Errors COMPOUND. Per-step reliability + recovery is everything.
Agent Note: Reflection and Recovery Break the Compounding
The key to fighting compounding is that reflection and error recovery RESET the failure: if the agent catches and fixes a bad step, that step's failure doesn't propagate. An agent that verifies and corrects each step effectively raises its per-step reliability close to 1, dramatically improving end-to-end success on long trajectories. This is why grounded reflection (Section 34.4) — run the test, see the error, fix it — is the single most important reliability technique for capable agents.
This connects agents back to the verifiable-reward reasoning of Chapter 25: agents are most reliable when they can CHECK their work against reality (tests pass, code runs, the answer is verified) and correct based on that check. Where work is verifiable, agents can be made robust; where it isn't, reliability is much harder — a key consideration in deciding where agents are ready to deploy.
34.11

Agents are one of the most hyped and most rapidly-evolving areas of AI. A grounded view of where they actually work today — and where they struggle — helps separate the promise from the reality.

Where Agents Work Well Today

DomainWhy agents work there
Coding agentsWork is VERIFIABLE — run tests, see errors, fix and retry
Research / browsingDecompose into searches; synthesize findings
Data analysisGenerate and run code, inspect results, iterate
Customer supportBounded tasks with clear tools (lookup, ticket, refund)
Workflow automationWell-defined multi-step processes with clear tools

Notice the pattern in where agents succeed: VERIFIABILITY and BOUNDED SCOPE. Coding agents thrive because they can run tests and see whether the code works — grounded feedback closes the reflection loop. Bounded tasks with clear tools (support, automation) succeed because the agent's choices are constrained. Agents struggle most with open-ended, long-horizon, hard-to-verify tasks where mistakes compound and there's no clear feedback signal.

The Honest State of Agents

As of this writing, agents are powerful but unreliable for complex open-ended tasks. They shine in verifiable, bounded domains (especially coding) and increasingly handle real workflows, but long-horizon autonomous operation remains fragile — they get stuck, make compounding errors, and need human oversight. The trajectory is rapidly improving (better reasoning models, better tools, better frameworks), but the gap between agent demos and reliable agent products is still real. Deploy agents where the task is verifiable and bounded; be cautious where it is open-ended and high-stakes.

Agent Note: Agents Are Improving Fast — and Still Maturing
Agents sit at the rapidly-moving edge of the field. Each improvement in the underlying components — better reasoning (Chapter 25), longer context (Chapter 33), more reliable tool use (Chapter 28), better planning — makes agents more capable. The reasoning models that emerged recently notably improved agentic planning and reliability. So agents are getting better fast, but they are not a solved technology: building reliable agents remains as much art and careful engineering as science.
This makes agents a fitting penultimate topic: they integrate everything in the book AND they sit squarely at the unfinished frontier. The final chapter turns explicitly to that frontier — the open problems, including the reliability and alignment of increasingly autonomous agents, that the field has yet to solve.
34.12

Let us consolidate the chapter into one picture of how an agent — single or multi — is built from the capabilities of this book.

Pipeline Flow: Building a capable agent

1Goal + loopAn agent loop pursuing a goal, with step/cost bounds
2PlanDecompose the goal into steps; replan as needed
3Orchestrate toolsSelect, sequence, and chain tools (Ch. 28)
4RememberShort-term context + long-term retrieval (Ch. 33)
5Reflect + verifyCheck work, ground in real feedback, correct errors
6(Maybe) multi-agentOrchestrator + specialized workers, if it helps
7Reliability + oversightBounds, validation, human-in-the-loop, tracing

The Three Ideas to Remember

If you remember three things about agents: First, an AGENT IS A LOOP, not a model — a system that pursues a goal over many steps by planning, acting, observing, and remembering, integrating everything in this book. Second, RELIABILITY IS THE CHALLENGE — errors compound across steps, so reflection, verification, and grounded feedback (run the test, fix the error) are what make agents work. Third, SIMPLER IS OFTEN BETTER — single agents often beat multi-agent systems, and agents shine in verifiable, bounded domains; add complexity only when it earns its place.

Agent Note: Agents Are the Convergence of the Book
Agents are where the whole book comes together. A capable agent uses a pretrained, aligned model (Parts III–V) that reasons (Chapter 25), runs efficiently (Chapter 27), calls tools (Chapter 28), retrieves knowledge (Chapter 29), perceives multiple modalities (Chapter 30), and remembers long contexts (Chapter 33) — all orchestrated into autonomous, goal-directed behaviour. Every layer you have studied contributes.
And agents point toward the future: as the components improve, agents become more capable and autonomous, raising both their promise and the open questions about their reliability, safety, and alignment. Those open questions — for agents and for AI broadly — are the subject of the book's final chapter.
34.13

Agents Quick-Reference

ConceptKey ideaRemember
AgentA loop pursuing a goalA system, not a model
Agent loopPlan, act, observe, repeatGeneralizes ReAct; must be bounded
PlanningDecompose goal into stepsWeak in current models; replan
ReflectionCritique and fix own workExploits generate-evaluate gap
MemoryShort-term + long-termLong-term = RAG on experience
Tool orchestrationSelect, sequence, chain toolsErrors compound; validate
Multi-agentSpecialized agents collaborateOrchestrator-worker most common
Multi-agent riskCost, coordination, errorsNot automatically better
ReliabilityErrors compound over stepsReflect + verify + bound

Exercises

Exercises 1–10 are pen-and-paper; 11–20 require code.

Exercise 1: Pen & Paper
Define an agent and contrast it with a single model call. What makes an agent autonomous and goal-directed?
Exercise 2: Pen & Paper
List the ingredients of an agent and which book chapter each comes from. Why are agents 'where everything converges'?
Exercise 3: Pen & Paper
Describe the agent loop and how it generalizes ReAct. Why must the loop be bounded, and what bounds would you add?
Exercise 4: Pen & Paper
Contrast plan-then-execute with interleaved planning. When is each better, and why is planning hard for current models?
Exercise 5: Pen & Paper
Explain reflection and the generate-evaluate gap it exploits. Why is GROUNDED reflection (running tests) better than ungrounded self-critique?
Exercise 6: Pen & Paper
Describe the types of agent memory. How does long-term memory relate to RAG (Chapter 29), and how does memory let agents 'learn' without retraining?
Exercise 7: Pen & Paper
Explain the challenges of orchestrating many tools. Why does reliability get harder as the number of tools and steps grows?
Exercise 8: Pen & Paper
Give four reasons to use multiple agents. Then give three reasons NOT to. When is a single agent better?
Exercise 9: Pen & Paper
Describe the orchestrator-worker pattern and the debate pattern. What kind of task suits each?
Exercise 10: Derive
Using the compounding formula, compute end-to-end success for 15 steps at 98% and at 90% per-step reliability. Explain how reflection changes this.
Exercise 11: Code
Build a basic agent loop: given a goal and a set of tools, loop (reason, act, observe) with a step cap until done. Test on a multi-step task.
Exercise 12: Code
Add planning: have the agent produce an explicit plan before executing, then follow it. Compare task success with and without an explicit plan.
Exercise 13: Code Lab
Implement reflection: after each step (or at the end), have the agent critique its work and revise. Use a coding task where you can run tests as grounded feedback.
Exercise 14: Code
Implement agent memory: a short-term context plus a long-term store the agent writes to and retrieves from. Show the agent recalling a lesson from a past task.
Exercise 15: Code
Build a multi-tool orchestration agent (search + fetch + summarize). Measure how often it selects and sequences the tools correctly, and add validation.
Exercise 16: Code
Measure compounding: build an agent whose steps fail with a tunable probability, and empirically plot end-to-end success vs number of steps, with and without reflection/retry.
Exercise 17: Code Lab
Implement an orchestrator-worker multi-agent system: a manager that delegates subtasks to specialized worker agents and synthesizes their results. Test on a decomposable task.
Exercise 18: Code
Implement a debate pattern: have two or three agents independently solve a problem, then critique each other, and a judge pick the best answer. Compare accuracy to a single agent.
Exercise 19: Code
Add human-in-the-loop: require approval before the agent takes any consequential action, and let a human correct the agent when it gets stuck. Demonstrate both.
Exercise 20: Code (Challenge)
Build a complete coding agent: an agent loop with planning, tool orchestration (write file, run tests, read errors), grounded reflection (fix based on test failures), memory of past attempts, step/cost bounds, and tracing. Give it a programming task with a test suite and measure its success rate. Then build a multi-agent version (coder + reviewer + tester) and compare success rate, cost, and latency against the single agent — and report whether the multi-agent system was actually worth it.

Further reading: “ReAct: Synergizing Reasoning and Acting” (Yao et al., 2022). “Reflexion: Language Agents with Verbal Reinforcement Learning” (Shinn et al., 2023). “Self-Refine” (Madaan et al., 2023). “Generative Agents” (Park et al., 2023) for agent memory and behaviour. “AutoGen” (Wu et al., 2023) and the LangGraph documentation for multi-agent frameworks. “Toolformer” (Schick et al., 2023) and the SWE-bench / SWE-agent work for coding agents. “Debate” (Du et al., 2023; Irving et al., 2018) for multi-agent debate.


Next → Chapter 35: Open Problems & Future Directions

Across thirty-four chapters you have built a complete understanding of LLMs — from the mathematics of Part I to the autonomous agents of this chapter. But the field is far from finished. The final chapter steps back to survey what we still DON'T know and CAN'T yet do: the unsolved problems of interpretability, alignment, reliability, reasoning, and safety; the deep questions about what these systems are and where they are heading; and the frontiers where the next breakthroughs — perhaps yours — will come. Having learned how LLMs work, we close by honestly confronting their limits and the open horizon beyond them.

20 Exercises in this chapter
Attempt each exercise before checking the worked solutions.
View Solutions →