Page 7 of 13 · Work that keeps going without you prompting
Loop engineering
Every agent already runs a loop inside one session. Loop engineering is the layer above: designing the goal, the checks, the stop conditions and the budget so an agent keeps working toward a verified result across many steps or many runs, without a human prompting each one. The term emerged in 2026 and is not standardized yet, but the practices behind it are solid.
3 runnable samples1 prediction4 questions
Level 1 · The rules
Anatomy of a durable loop
The shift is from being the person who prompts the agent to being the person who designs the system that prompts it.
- Goal
Goal
A result a program can verify: "all tests pass", "the build is green", "every acceptance criterion maps to a test". - model
Work
One agent run that tries to move toward the goal. - harness
Check
A sensor measures progress: tests, linters, an eval, a judge. - context
State
Progress written outside the window: a notes file, a task list, git history. - stop
Stop
Success, or a limit: iterations, money, time, or no progress. - loop · work, check, write state, until a stop fires
failing_tests = [5, 3, 1, 0]max_rounds = 10budget_usd = 3.00cost_per_round = 0.40spent = 0.0for round_no, failing in enumerate(failing_tests, start=1): spent += cost_per_round print(f"round {round_no}: {failing} failing, ${spent:.2f} spent") if failing == 0: print("goal met: verified by the test run, not by the agent's word") break if round_no >= max_rounds or spent >= budget_usd: print("stopped by a limit") break
[ harness ] check: goal verified by tests[ stop ] limits on rounds and money
[ OUTPUT ]
Press Run to see the output this code printed when the course was built.
Level 1 · The rules
"Done" is a check, not a claim
An agent that decides for itself when it is finished will sometimes stop early with a confident summary. A loop needs an exit condition that something other than the agent verifies.
def agent_says_done(summary): return "complete" in summary.lower()def tests_say_done(failing): return failing == 0summary = "Implementation complete. All edge cases handled."failing = 2print("agent claims done:", agent_says_done(summary))print("tests confirm done:", tests_say_done(failing))
[ OUTPUT ]
Press Run to see the output this code printed when the course was built.
Level 2 · Why it works
Detect when the loop is stuck
Iteration and money caps stop a runaway loop eventually. A no-progress check stops it early, when the same failure repeats.
class NoProgressError(Exception): passdef run(failing_per_round, patience=2): best, stale = None, 0 for failing in failing_per_round: if best is None or failing < best: best, stale = failing, 0 else: stale += 1 if stale >= patience: raise NoProgressError(f"stuck at {best} failing for {stale} rounds") if failing == 0: return "done"run([4, 2, 2, 2, 2])
[ TRACEBACK ]
Press Run to see the output this code printed when the course was built.
| Loop shape | What repeats | Example |
|---|---|---|
| Inner agent loop | Model step, tool call, result, inside one session | Any coding agent working on one request |
| Goal loop | Whole runs until a check passes | "Fix until the test suite is green, max 10 rounds" |
| Scheduled loop | A run on a timer or an event | Nightly dependency check, triage new issues every hour |
| Pipeline of loops | Stages that each loop until their own check passes | Plan until reviewed, build until green, verify until the eval holds |
Level 3 · Mastery
Guardrails for loops that run without you
A loop multiplies whatever the harness allows. If one run can do damage, a hundred unattended runs will. These controls are not optional:
Hard limits
Maximum iterations, maximum spend and a timeout, enforced in code outside the model.Isolation
Each loop works in its own branch, worktree or sandbox, so a bad run is thrown away, not merged.Gates on irreversible steps
Merges, deploys, payments and emails wait for a human or a stronger check.Untrusted input
Every page, issue or file the loop reads can carry injected instructions. Limit what tools a loop holds while it reads them.A trace per run
Time, tokens, cost and outcome for every iteration, so you can see where loops stall or overspend.Know when not to loop
One-shot tasks, work without a verifiable signal, and anything irreversible are better run once with review.
Predict the output
Level 3 answer before you look
Check your understanding
Levels 1 to 3 open a question to see the answer
How is loop engineering different from the agent loop?
The agent loop is what happens inside one session: model, tool, result, repeat. Loop engineering designs the system around many such runs: a verifiable goal, checks, stop conditions, state that persists, and limits.
Why is "the agent said it's done" a bad exit condition?
Agents sometimes stop early with a confident summary. The exit must be verified by something independent of the agent, such as a test run or an eval.
What three limits should every unattended loop have?
An iteration cap, a spend cap and a no-progress check (plus a timeout). The first two stop runaway loops; the third stops stuck loops early.
Where does loop state live between runs?
Outside the context window: a progress file, a task list, git history. Each new run rereads it, so a fresh session can continue where the last one stopped.