Loop Engineering · ~8 min
Eight lessons collapse into one reflex: read the loop pathology in front of you, then reach for the single lever that fixes that layer — and never a bigger model first.
The through-line of the whole course: a loop is a cost you pay to remove a human from one seat — grading, initiating, or harness-tweaking. Earn that seat before you automate it, gate it before you trust it, and cap it before you let it run alone.
| Symptom you're staring at | Move | Lesson |
|---|---|---|
| "It looks stuck" but you can't say why | Name the loop first — tool, verification, or convergence. Each has a distinct trace signature and its own fix; don't reach for the nearest intervention | L1 |
| Deciding what context to carry across iterations | Pick accumulated vs fresh per loop; autonomy is a spectrum and Ralph's fresh-context reset is its cheap brute-force extreme | L2 |
The loop is an ad-hoc while True | Give it a structured body — middleware / ReAct / plan-first — so each iteration has a shape, not bare retry | L3 |
| The loop keeps grinding on work already done | Detect convergence explicitly — repeated states, diminishing diffs — instead of trusting the model's own "done" | L4 |
| "Should I automate this as a loop at all?" | Run the Go/No-Go gate — cadence, objective verification, absorbable budget, real tooling must all hold | L5 |
| One turn burns millions of tokens with no progress | Cap iterations, wall-clock, and spend; detect the stuck loop and break out with a recovery move | L6 |
| The system repeats the same mistakes run after run | Close the outer loop — feed outcomes and human checkpoints back into rules so it improves between runs | L7 |
The causal mechanism is bottleneck migration: the inner agent loop produces output faster than a human can prompt the next task, so the human becomes the throughput ceiling. Each outer loop you stack removes one seat the human used to occupy — Loop 2 (verification) replaces human grading, Loop 3 (event-driven) replaces human initiation, Loop 4 (hill-climbing) replaces human harness-tweaking. LangChain calls Loop 4 "arguably most important": its return arrow doesn't loop back to the top, it reaches inside and updates the agent loop directly, so each outer cycle makes the inner loops more effective. That's the whole arc — diagnose the layer (L1), choose its context and structure (L2–L3), stop it honestly (L4), and only stack outer seats once the gate clears (L5) with caps holding the floor (L6) and a flywheel closing the top (L7).
Every lesson had a backfire box, and they rhyme. Subjective verification — when "done" is taste — leaves the maker grading its own homework and quality drifts down. A saturated reviewer caps effective throughput no matter how many agents you run; the queue gets longer, not the team faster. And a hill-climbing loop trained on stale traces silently encodes yesterday's assumptions. Bui et al. measured the tax across 567 Claude Code PRs: 83.8% merged, but only 54.9% without modification — ~45% of "automated" output still consumed reviewer time. Stack a loop only where the structure earns it.
Mixed review — the decision table, then a spaced recall
Question 1The course's through-line is that a loop earns its cost only when…
Question 2When the agent "looks stuck" but you can't say why, the first move is to…
Question 3A single turn burning millions of tokens with no progress is a runaway you fix by…
Question 4To stop a loop grinding on work that's already done, you should…
Question 5 · spaced recall from an earlier lessonA spinning inner tool loop and tests that stay red across turns are…