Building Effective Agents: A Hands-On Tutorial for Anthropic's Agentic Design Patterns
How to walk through Anthropic's "Building Effective Agents" patterns hands-on in Next.js — the augmented LLM, four agentic workflows, and a fully autonomous coding agent, each as a working, inspectable feature.
Get the Full Source Code on GitHub
This article is a summary. The full, runnable project —
seven in-depth chapters with complete code, docs, and a live
demo UI — lives in the audoir/ai-build-effective-agents repository.
Introduction
Anthropic's engineering post "Building Effective Agents" lays out a simple but powerful idea: start with the simplest solution possible — often a single, well-augmented LLM call — and only reach for a workflow or a fully autonomous agent when it demonstrably improves outcomes. The ai-build-effective-agents repository turns every pattern from that post into a working Next.js feature you can chat with, watch the tool calls happen, and then read exactly how it's wired up.
This post summarizes all seven chapters: the augmented LLM building block, four agentic workflows (prompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer), and fully autonomous agents. Head to the repo for the full, runnable code and docs.
Seven Chapters
Each pattern from Anthropic's post gets its own tab in the app and its own chapter in the docs, progressively working up from the simplest building block to fully autonomous agents.
Chapter 1: The Augmented LLM
An LLM enhanced with retrieval (web search), tool use (a JS sandbox), and memory (persisted chat history) — the foundational building block every other pattern builds on.
Chapter 2: Prompt Chaining
Outline → programmatic gate check → full document, as three fixed LLM calls with a code-based check in between — trading latency for higher accuracy on a task that decomposes cleanly.
Chapter 3: Routing
Classifies customer service queries (general / refund / technical), then answers each with its own specialized prompt and tools — useful when categories are distinct and classification is cheap and accurate.
Chapter 4: Parallelization
Answer generation and three guardrail reviewers run in parallel (sectioning); a majority vote across reviewers (voting) decides whether to reveal the answer or refuse.
Chapter 5: Orchestrator-Workers
An orchestrator dynamically plans 2-4 research subtasks, worker calls research each in parallel, and a synthesizer combines their findings into one report — for tasks where the subtasks can't be hardcoded in advance.
Chapter 6: Evaluator-Optimizer
A search-and-evaluate loop (up to 3 rounds) where the evaluator decides whether findings are comprehensive enough or another round of searching is needed — iterative refinement against a clear evaluation criterion.
Chapter 7: Agents
A self-correcting coding agent — no fixed steps, just a safety cap; the model decides itself whether to write code, test it, retry, or stop. This is the final chapter, completing every pattern from Anthropic's post.
Which Pattern Should You Use?
Anthropic's own advice is to start with the simplest solution possible and only reach for a workflow or an agent when it demonstrably improves outcomes. Workflows trade latency and cost for predictability on well-defined tasks; agents trade predictability for flexibility on open-ended ones.
| Pattern | Use it when... |
|---|---|
| 🧱 Augmented LLM | A single LLM call, given retrieval/tools/memory, can complete the whole task — no multi-step process needed |
| 📝 Prompt Chaining | The task decomposes cleanly into a fixed sequence of subtasks; you're willing to trade latency for higher accuracy |
| 🚦 Routing | Inputs fall into distinct categories that are better handled by separate specialized prompts/tools |
| 🧵 Parallelization | Subtasks can be split and run independently for speed (sectioning), or multiple attempts raise confidence in the result (voting) |
| 🧭 Orchestrator-Workers | The subtasks needed can't be predicted or hardcoded in advance — a central call decides, per input, how many workers to use |
| 🔁 Evaluator-Optimizer | There's a clear evaluation criterion, and iterative refinement provides measurable value |
| 🤖 Agents | The task is open-ended enough that you can't predict or hardcode the number of steps, and you can trust the model's own decision-making |
Getting Started
Clone the repository, add your OpenAI API key, run npm install and npm run dev, then open http://localhost:3000. You'll need an OPENAI_API_KEY environment variable set in a .env.local file. See the repository README for full setup instructions and each chapter's dedicated docs page.
Key Dependencies
| Package | Purpose |
|---|---|
ai | Vercel AI SDK — streamText, generateText, Output, stepCountIs, tool |
@ai-sdk/openai | OpenAI provider, including the built-in web search tool |
@ai-sdk/react | React hooks (useCompletion) for the streaming chat UI |
better-sqlite3 | Synchronous SQLite driver — powers in-memory chat memory |
zod | Schema validation for tool inputs |
Conclusion
Across seven chapters the repository reproduces every pattern from Anthropic's "Building Effective Agents" post as a working, inspectable feature — from the augmented LLM building block through four agentic workflows to fully autonomous agents. Each chapter lets you read the concept, see it running, and read the code side by side.
Learning Outcomes
By working through the tutorial, you will gain practical experience with:
- • Augmenting a single LLM call with retrieval, tool use, and memory
- • Building fixed-sequence prompt chains with a programmatic gate check in between
- • Routing inputs to specialized prompts and tools based on classification
- • Parallelizing LLM calls for both sectioning and voting
- • Designing an orchestrator that dynamically plans and dispatches worker subtasks
- • Building an evaluator-optimizer loop that iteratively refines its own output
- • Building a self-correcting, fully autonomous coding agent bounded by a safety cap
- • Knowing which pattern to reach for — and when to just use a single augmented LLM call instead
Ready to Build It Yourself?
Clone the repository, add your OpenAI API key, and run all seven chapters locally to see the augmented LLM, every workflow, and a fully autonomous agent in action.
Clone ai-build-effective-agents on GitHubAbout the Author
Wayne Cheng is the founder and AI app developer at Audoir, LLC. Prior to founding Audoir, he worked as a hardware design engineer for Silicon Valley startups and an audio engineer for creative organizations. He holds an MSEE from UC Davis and a Music Technology degree from Foothill College.
Further Exploration
Explore the ai-build-effective-agents repository and experiment with extending the examples. Consider adding new tools to the augmented LLM, swapping in a different routing classifier, or raising the evaluator-optimizer's round limit to see how far iterative refinement can go.
New to AI agents? Start with the AI Agent Tutorial first, which covers building agents from scratch — from a simple streaming chatbot to a LangGraph-powered agent with MCP tools.
For more AI-powered development tools and tutorials, visit Audoir .