top of page

Loop Engineering: An Absolute Beginner's Tutorial

Jun 21
4 min read
What Is Loop Engineering? Beginner's Guide to AI Agent Loops

What Is Loop Engineering?


Loop engineering is the practice of building a small automated system — a loop — that drives an AI coding agent for you, instead of you manually prompting it turn by turn.



The old way:


You write a prompt → Agent responds → You read it → You write the next prompt → repeat

The loop engineering way:


You write a loop → Loop prompts the agent → Loop reads the output →
Loop decides "done or not done?" → Loop re-prompts automatically → repeat until done

You stop being the one holding the steering wheel every second. Instead, you build the car that drives itself toward a goal you defined.



Why It Matters

Two people leading AI coding tools at the top of the industry have both said versions of the same thing:


  • Peter Steinberger: "You shouldn't be prompting coding agents anymore. You should be designing loops that prompt your agents."

  • Boris Cherny (Claude Code lead, Anthropic): "I don't prompt Claude anymore. I have loops running that prompt Claude and figuring out what to do. My job is to write loops."


This is currently considered one of the fastest-growing skills in AI engineering.



The Five Building Blocks of a Loop

Every loop, no matter how complex, is built from these five pieces:

Block

Purpose

1. Goal

What "done" looks like, defined clearly in advance

2. Prompter

Sends the next instruction to the agent

3. Reader

Captures and parses the agent's output

4. Verifier

Checks if the output actually satisfies the goal

5. Controller

Decides: stop, retry, or re-prompt with corrections



GOAL → PROMPTER → AGENT → READER → VERIFIER → done? 
                     ↑                    |
                     └────── no ──────────┘


A Simple Example (Conceptual)


Goal: "Fix all failing tests in this repo."



1. Loop runs the test suite (Reader)
2. Loop finds 3 failing tests
3. Loop prompts the agent: "Fix these 3 failing tests: [list]" (Prompter)
4. Agent edits code
5. Loop re-runs the test suite (Verifier)
6. If tests still fail → loop back to step 3 with new context
7. If all tests pass → loop stops (Controller declares done)

No human typed a single follow-up prompt. The loop did it.


Why the Verifier Is the Most Important Block

A loop that runs unattended is also a loop that makes mistakes unattended. If you don't separate the verifier from the agent doing the work, the agent can simply claim "done" without it being true.


"Done" is a claim, not a proof.

Beginner rule: Never let the same agent that did the work also be the only judge of whether the work is correct. Use a separate check — tests, a second agent, or a hard rule — to confirm.



Common Beginner Mistakes


1. No Stopping Condition

A loop with no clear "done" signal can run forever, burning tokens and money.


Fix: Always define a measurable goal (tests pass, file exists, score > X) — not a vague one ("make it better").


2. No Iteration Cap

Even with a goal, a buggy loop can spin endlessly trying to fix something it can't fix.


Fix: Always set a maximum number of iterations or a compute/token budget. If the cap is hit, stop and flag for a human.


3. Trusting the Agent's Own "Done"

If the agent says "I fixed it" and the loop believes it without checking, broken code ships silently.


Fix: Verification must be independent of the agent's self-report (e.g., run actual tests, not just read the agent's claim).


4. Letting Comprehension Debt Pile Up

The faster a loop ships code you didn't write yourself, the bigger the gap between what exists in the codebase and what you actually understand.


Fix: Review what the loop produced. Don't treat "it's automated" as "it's safe to ignore."




Where This Shows Up Today

  • Claude Code has a /loop command that schedules a recurring prompt on an interval, plus hooks that fire commands at points in the agent's lifecycle.

  • Loops can be pushed to GitHub Actions to keep running even after you close your laptop.

  • Some practitioners run 10–15 parallel agent loops at once, each with its own goal, memory file, and verifier.



Practice Exercises

  1. Pick one real coding task you currently do by manually prompting an agent. Write out, in plain English, what the 5 building blocks (Goal, Prompter, Reader, Verifier, Controller) would be for it.

  2. Identify one task where you'd be uncomfortable letting a loop run fully unattended. Explain why — usually it's a missing or weak verifier.

  3. Design a stopping rule (max iterations or token budget) for a loop that fixes failing tests.




Key Takeaways

  • Loop engineering = building a system that prompts and re-prompts an agent for you, not prompting it yourself turn by turn.

  • Every loop needs a clear goal, a verifier, and a stopping condition.

  • The verifier must be independent — never trust the agent's self-reported "done."

  • Always cap iterations and budget to avoid runaway loops.

  • Automation doesn't remove your responsibility to understand and review what was shipped.

Comments


bottom of page