You already have a loop. This course is about engineering it. First, the territory.
You’ve written the thing already: a while loop that calls a model, runs the tool calls it asks for, feeds the results back, and goes again. Thorsten Ball’s famous one-liner is that an agent is just “an LLM, a loop, and enough tokens”1 — and he’s right that the skeleton is ~300 lines of boilerplate.
Loop engineering is everything that happens after that skeleton works. The gap between a toy loop and an agent you’d put in front of a customer is not a flash of genius — it’s a handful of levers, each tuned deliberately. This lesson is the map of those levers. Every later lesson zooms into one.
Before the map, fix the unit. Loop engineering operates on the turn — one pass through the loop. Strip a turn to its bones and it’s the same six moves every time:
HumanLayer compresses the whole apparatus to “prompt + switch statement + context builder + loop.”2 Memorise that phrase — every lever below is a way of engineering one of those four words.
Here are those six moves as the code you’ve already written, stripped to its spine. Notice there’s no magic — the “agent” is this loop:
# Factor 8 — own your control flow: this loop IS the agent
state = init(task)
for turn in range(MAX_TURNS): # move 6 · stop: budget guard
ctx = build_context(state) # move 1 · assemble context
reply = model(ctx) # move 2 · call the model
if reply.is_final: # move 6 · stop: goal reached
return reply.answer
calls = parse_tool_calls(reply) # move 3 · parse output
results = [run(c) for c in calls] # move 4 · execute tools (+ errors)
state = append(state, results) # move 5 · append observation
raise BudgetExceeded(state) # move 6 · stop: guard tripped
Every lever in this course is a way of engineering one of those lines: build_context is Lever 02, run and its tools are Levers 03/04, MAX_TURNS is Lever 05, the handling of errors inside run is Lever 06, and state is Lever 07. The shape of the loop itself is Lever 01.
This is the map. Each card is a dimension you engineer independently. You won’t master them today — you’ll learn to see them, so when an agent misbehaves you know which knob to reach for.
Who decides the next step — your code (workflow) or the model (agent)? The master lever; the rest hang off it.
What enters the window each turn. Anthropic calls curating it the single biggest factor in agent performance.4
The action space — what the model can do, and how clearly its tools are named, typed, and documented.3
The ground truth the loop reads back each turn to judge progress. No feedback → the loop is guessing.3
When the loop ends. Caps on turns/tokens — roughly 3–20 steps before handoff is a common rule.2
How failures fold back in — compacted, not dumped — so the loop self-corrects instead of drowning.2
Who holds the loop’s state and control — you, ideally: pause/resume, human-in-the-loop, stateless reducers.2
If you remember one thing, remember Lever 01. Anthropic draws the line cleanly:
Workflows are systems where LLMs and tools are orchestrated through predefined code paths.
Agents are systems where LLMs dynamically direct their own processes and tool usage, maintaining control over how they accomplish tasks. — Anthropic, Building Effective Agents
This isn’t a binary you pick once — it’s a dial per decision. Most production “agents” sit far toward the workflow end: mostly ordinary, deterministic software with the model placed at a few high-leverage decision points.2 Anthropic’s blunt advice: “add complexity only when it demonstrably improves outcomes.”3 The five named workflow patterns — chaining, routing, parallelization, orchestrator–workers, evaluator–optimizer — are all points on the workflow side of this dial. We’ll dedicate a lesson to them.
You can now do two things you couldn’t name an hour ago: (1) decompose any agent into the six-move turn and the seven levers, and (2) classify any design point as workflow (your code decides) or agent (the model decides). That vocabulary is the diagnostic kit for everything that follows. Lock it in below.
Don’t re-read — retrieve. Effortful recall is what turns this map into memory you’ll still have next week. Answer from your head; feedback is instant.
Anthropic — Building Effective Agents. The single highest-trust map of this territory: the workflow/agent split, the five patterns, and the “start simple” discipline. ~20 minutes. It is the backbone of this whole course.
TradingAgents loop, say)? Ask me to pick which of the seven levers it’s weakest on. Just type your question in the chat.