Chapter 51Capstone 3: A Multi-Agent Workflow
Here is the capstone of capstones — and the final chapter of the book. We build a small team of agents that collaborate to plan, execute, and review a real task from beginning to end. This project pulls together nearly everything you have learned: planning, the agent loop, tools, multi-agent coordination, review, and observability. If you can build and understand this, you have genuinely earned the title this book promised. We will build it step by step, and then close with a reflection on the journey from zero to here.
What We're Building
Our system is a small team of specialized agents that together accomplish a substantial goal — for example, "produce a short, well-organized briefing on a topic." A planner breaks the goal into subtasks, worker agents carry them out, and a reviewer checks the result and sends it back for revision if it falls short. It is a miniature organization of agents, coordinated toward a shared outcome, and it embodies the multi-agent ideas of Chapter 41 in a complete, working form.
Design
Every component traces to a chapter. A planner agent decomposes the goal (Chapter 35). Worker agents execute subtasks, each a full agent loop with tools (Chapters 31, 32, 33). A reviewer agent checks the combined result and requests fixes (Chapter 41), building verification into the system's structure. Orchestration wires the handoffs between them (Chapter 41), and observability traces the whole workflow so we can see what happened (Chapter 44). This is the full architecture of the book, assembled into one system.

Step 1: The Planner Agent
The planner takes the goal and breaks it into an ordered list of subtasks (Chapter 35), giving the workers a clear set of jobs.
def planner(goal):
prompt = (f"Break this goal into 2-4 concrete subtasks: {goal}. "
"Return one subtask per line, in order.")
return parse_lines(model_respond(prompt)) # -> ["subtask 1", "subtask 2", ...]Step 2: The Worker Agents
Each subtask is handed to a worker — an ordinary agent loop with the tools it needs (Chapters 31 and 32). The workers do the actual research, drafting, or computation.
def worker(subtask, trace):
trace.append({"agent": "worker", "subtask": subtask}) # observability
return run_agent(subtask, tools=[search, read]) # a full agent loopStep 3: The Reviewer Agent
The reviewer is where verification becomes structural (Chapter 41). It checks the combined work against the goal and either approves it or returns specific feedback for revision.
def reviewer(goal, draft, trace):
trace.append({"agent": "reviewer", "draft_length": len(draft)})
prompt = (f"Goal: {goal}\n\nDraft:\n{draft}\n\n"
"If the draft fully meets the goal, reply 'APPROVED'. "
"Otherwise, list specific improvements needed.")
verdict = model_respond(prompt).text
return verdictStep 4: Orchestration
Orchestration ties the team together: plan, run the workers, combine their output, review it, and loop back for revision if the reviewer is not satisfied — all bounded so it cannot revise forever (Chapter 31).
def workflow(goal, max_revisions=2):
trace = []
subtasks = planner(goal) # plan (Ch 35)
results = [worker(s, trace) for s in subtasks] # workers (Ch 31-33)
draft = combine(results)
for _ in range(max_revisions): # bounded review loop
verdict = reviewer(goal, draft, trace) # review (Ch 41)
if "APPROVED" in verdict:
break
draft = worker(f"Revise this draft per the feedback: {verdict}", trace)
return draft, traceStep 5: Observability
Notice the trace threaded through every function (Chapter 44). Because the workflow involves several agents and a review loop, observability is essential — without it, a failure could hide in any agent or any handoff. The trace lets us watch the planner's decomposition, each worker's contribution, and the reviewer's verdicts, turning a complex multi-agent process into something we can actually inspect and debug.
Step 6: Putting It All Together
Run the workflow on a real goal and watch the team collaborate: the planner divides the work, the workers produce a draft, the reviewer critiques it, and the workers revise until it passes.
briefing, trace = workflow("Produce a short briefing on the benefits of cycling.")
print(briefing)
# Inspect how the team worked together:
for step in trace:
print(step) # planner -> workers -> reviewer -> revision -> approvedTesting the Workflow
Run it on several goals and study the traces (Chapter 44). Did the planner decompose sensibly? Did the workers do their parts? Did the reviewer catch real weaknesses and did revision actually improve the draft? Evaluate the final output against what you would expect from a good result. A multi-agent system has more places to fail than a single agent, so this inspection matters all the more — but it also has the reviewer's built-in checking working in your favor.
Reflecting on What You've Built
Pause and appreciate what this final project contains. Planning from Chapter 35. The agent loop and ReAct from Chapters 31 and 32. Tools from Chapter 33. Multi-agent coordination and review from Chapter 41. Observability from Chapter 44. And resting beneath all of it, everything from the first nine parts — how models work, how they are trained, how to prompt them, how tool calling works. This one workflow is a synthesis of nearly the entire book. If you understand it, you understand agentic AI.
Where to Go From Here
You began this book knowing nothing about AI agents, and you finish it having built one that plans, acts, and reviews its own work. You understand the full pipeline you set out to learn: from data preparation, through model training, to building, deploying, and securing real agents. The field will keep changing, but you now have what does not change — the fundamentals — and the verification mindset to use any new tool wisely. So keep building real things, keep verifying that they work, keep learning from primary sources, and stay curious. You are no longer a beginner. You are a builder of agents, and the rest is practice.
Summary
This final capstone built a multi-agent workflow — a planner that decomposes the goal (Chapter 35), worker agents that execute the subtasks (Chapters 31 to 33), and a reviewer that checks the result and drives revision (Chapter 41) — all orchestrated with bounded loops and traced for observability (Chapter 44). It is a synthesis of nearly the entire book, and building it is proof that you have learned what the title promised. From the foundations of how models work, through training and prompting, to the full machinery of agents and the discipline of building them safely and reliably, you have gone from zero to hero. Keep building, keep verifying, keep learning — the journey continues, and you are well equipped for it.
That brings the book to its close. You set out to understand how agentic AI works from data preparation, through model training, to building real agents — and you now do, end to end. Everything from here is practice and exploration. Go build something, verify that it works, and share it with the world.
Exercises
- 1Design and build a three-agent workflow (planner, worker, reviewer) for a task of your choosing. Run it end to end and confirm the agents collaborate as intended.
- 2Add observability so you can trace the entire workflow, then run it and read the trace to see how the planner, workers, and reviewer each contributed.
- 3Study what the reviewer agent does to the final output. Run the workflow with and without the reviewer and describe how the reviewer changes the result.
- 4Bound your workflow so the review loop cannot run forever. Explain what could go wrong without that bound, connecting it to earlier chapters.
- 5Identify every concept from earlier in the book that this capstone uses, and write one sentence for each on what it contributes to the whole.
- 6Write a short report on your finished workflow: what worked, what failed, what you would improve, and what you want to build next now that you can build agents.
