Module 2 · Phase 1: Foundations from raw APIs · Weeks 3–5
The Agent Loop
An agent is an LLM calling tools in a loop, with the model deciding what to do next. This module is the heart of the curriculum: the loop itself, ReAct, Anthropic's workflows-vs-agents taxonomy, planning, termination, budgets, and failure recovery.
After this module you can
- ▸Implement the core agent loop — model picks a tool, you execute, results feed back — with the model choosing the path
- ▸Explain Anthropic's workflows-vs-agents taxonomy and argue when a workflow beats an agent (the interview staple)
- ▸Implement the five workflow patterns: prompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer
- ▸Explain ReAct and how native tool calling absorbed it; add upfront planning and re-planning to a loop
- ▸Enforce termination with layered guards: finish tool, max iterations, cost budget, wall-clock deadline — with graceful degradation
- ▸Recover from tool failures without crashing, keep context from exploding across iterations, and emit a JSONL trace log for every run
Lessons
125 min225 min330 min425 min525 min
The Loop That Makes an Agent
A chatbot maps one input to one output. An agent runs a loop where the model itself decides which tools to call, in what order, until the task is done. The loop is ~20 lines; everything else in this module is guardrails around it.
ReAct & Planning
ReAct — reason, act, observe, repeat — is the intellectual ancestor of the modern agent loop. Today the pattern is baked into native tool calling, but the ideas (verbalized reasoning, plan-then-act, re-planning on surprise) still decide whether your agent flails or converges.
Workflows vs. Agents: The Taxonomy
Anthropic's 'Building Effective Agents' taxonomy is the single most-cited framework in agent interviews. Workflows: your code orchestrates LLM steps. Agents: the LLM drives. Five workflow patterns cover a huge share of real systems — and the senior move is knowing when NOT to build an agent.
Termination, Budgets & Graceful Degradation
Never trust the model alone to stop. Production agents layer termination conditions — an explicit finish tool, iteration caps, dollar budgets, wall-clock deadlines — and when a budget trips, they degrade gracefully instead of raising.
Failure Recovery, Context Discipline & Tracing
An agent's quality is defined on the unhappy path: tools fail, outputs balloon, and at 2 a.m. the only witness is your trace log. Error feedback loops, per-tool retry budgets, output truncation, and JSONL tracing turn a demo into a system.
Module quiz
12 questions · pass ≥ 80%
Lab: Lab 02 — File-System Research Agentportfolio
Build an agent that answers natural-language questions about any local codebase or folder: it plans, lists, greps, and reads files across the repo, then synthesizes an answer with file-path citations — under hard iteration, cost, and time budgets, with a full JSONL trace and graceful degradation. Raw SDK only; starter code lives in labs/lab02-research-agent/.
Best external resources
Curated reading, docs, and tools that pair with this module.
Anthropic — Building Effective Agents
The essay this module is built on. Read it twice; interviews quote it.
EssayOpenAI — A Practical Guide to Building Agents
Complementary vendor view: guardrails, orchestration, HITL.
GuideLilian Weng — LLM Powered Autonomous Agents
The classic conceptual grounding: planning, memory, tool use.
EssayReAct paper (Yao et al.)
Skim for the idea and the lineage question above.
PaperChip Huyen — Agents
The most rigorous long-form treatment of planning, tool selection, and agent failure modes.
Essay12-Factor Agents (23k★)
Production principles from someone who tried every framework: own your loop, prompts, and context window.
Repo