Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Lab · Loop Engineering

The Loop Designer.

Don't read about loop engineering — break a loop, then fix it. An agent must migrate 8 files overnight, unattended. You design its outer loop: toggle the hard cap, the independent verifier, and the external memory, hit Run, and watch what actually happens to your budget and your codebase.

hard cap · verification split · external memory · stopping conditions
HARD CAP

Max iterations + budget ceiling. The bluntest guard — the only thing standing between a stuck loop and your invoice.

VERIFIER

Who decides "done"? The agent's own claim, or something independent — tests, a reviewer with fresh context.

MEMORY

A checkpoint outside the model recording done/next. Without it every run starts from amnesia.

STOP

Loops must end loudly — goal verified, or cap hit and leftovers escalated to a human. Never silently.

loop-designer.sim — goal: "migrate all 8 files to the new session API"
The repo — 8 files to migrate
BUDGET BURNED$0.00
0
Iterations
0/8
Verified done
0
Bugs shipped

Design your loop, then run it
Hard cap — stop after 15 iterationsGuard 1 · max_iterations + budget ceiling
Independent verifier — tests decideGuard 2 · off = the agent grades its own work
External memory — checkpoint fileGuard 3 · off = every run starts from amnesia

The four runs every loop engineer should feel once

The simulator above is honest about one thing most tutorials skip: the agent is good but not perfect — it succeeds about 70% of the time, and one file (legacy_parser.py) is beyond it entirely. Every classic loop failure comes from how the outer loop handles those two facts. Run all four scenarios:

01

🔥 The $500 Hour — no cap

Memory and verifier on, cap off. The loop grinds through 7 files beautifully… then hits the impossible one and retries it forever. Nothing is wrong with any single iteration — that's what makes runaways expensive. The cap isn't pessimism; it's the price of unattended.

02

🔁 Groundhog Day — no memory

Cap and verifier on, memory off. With no checkpoint, each iteration picks a target blindly — re-migrating finished files while real work waits. The cap trips with most of the queue untouched. Busy is not the same as progressing.

03

🚢 Plausible Mistakes — no verifier

Cap and memory on, verifier off. The agent grades its own homework, so failures get reported as wins. It finishes fast, green across the board — and the reveal shows what actually shipped. A loop without a verifier is a machine for shipping plausible mistakes at scale.

04

✅ The Well-Guarded Loop — all three

Cap, verifier, and memory on. Failures become retries, retries become verified progress, and the impossible file gets escalated loudly when the cap trips. 7 of 8 verified-done plus one honest escalation is what success looks like — a loop that ends loudly, never silently.

Now flip the guards yourself and re-run. The lesson worth internalizing: the same agent produced all four outcomes. Only the loop around it changed.

The picture: one outer loop, three guards

cron fires iter < 15 ? stop + escalate no guard 1: cap yes checkpoint: next file agent try, $2.75 tests decide guard 3: memory guard 2: verifier PASS: save checkpoint FAIL: retry, no write next iteration
The loop the simulator runs, with its three guards highlighted. Each one sits at a different point: the cap is checked before any money is spent, the checkpoint decides what to work on, and the verifier decides whether a result counts. Switch one off in the lab and the arrow it guards changes. Without the cap, the “no” branch never fires. Without memory, the next file is a blind pick. Without the verifier, the FAIL box disappears and the agent’s own claim is saved as done. Read the arrows as the order of operations inside one iteration: check the cap, pick from memory, spend $2.75, verify, then write or do not.

Worked example: the well-guarded run, iteration by iteration

This is the run the ✅ scenario plays back. Each iteration costs $2.75 and the cap is 15, so the worst this loop can ever spend is 15 × $2.75 = $41.25. Order matters here: the loop checks the cap first, then reads the checkpoint for the first file not yet verified, so a failed file is retried at once instead of going to the back of the queue.

IterationFileTestsBudgetVerified
1–4auth/session.py, auth/token.py, api/users.py, api/orders.pyPASS ×4$11.004/8
5db/models.pyFAIL, state untouched$13.754/8
6db/models.py (picked again from the checkpoint)PASS$16.505/8
7–8jobs/cleanup.py, utils/dates.pyPASS ×2$22.007/8
9–15legacy_parser.pyFAIL ×7$41.257/8
cap15 iterations reached—$41.257/8 + 1 escalated

Iteration 5 is the guards working together. The tests caught a bad migration, nothing was written to the checkpoint, and because memory said db/models.py was still undone, iteration 6 went straight back to it and fixed it. The ending matters just as much. Iterations 9 to 15 spent $19.25 on a file the agent can never fix, and the cap is what stopped it there. The 🔥 scenario uses the same seed, so its first 8 iterations are identical, $22.00 for 7 files. With no cap it then fails on legacy_parser.py 174 more times, until the simulator’s $500 stop ends it at iteration 182 and $500.50. That is $478.50 spent on one file with nothing to show for it, where the cap held that waste to $19.25. Notice too what this log never contains: a “done” that rests on the agent’s word. Every PASS is the tests talking, and every FAIL leaves the checkpoint exactly as it was, so the next iteration starts from the truth rather than from a claim.

What each guard costs: the four runs compared

Same agent, same files. Time is iterations run, Space is money spent, and Why is what you actually got. Read it for what each guard buys: the cap bounds money, memory turns iterations into progress, and the verifier makes “done” true. The cheapest run in the table is the one that shipped broken code, which is why spend alone is a bad health metric for an agent loop.

CaseTimeSpaceWhy
🔥 no cap182$500.507/8 done after 8 iterations, then 174 failing retries on legacy_parser.py. The loop never stops itself. The simulator’s $500 limit does.
🔁 no memory15$41.25Only 5/8 done. 7 of the 15 iterations re-migrated files that were already finished: $19.25 of busy work.
🚢 no verifier8$22.00The cheapest run, and it reports 8/8. The reveal shows 4 of those 8 broken, legacy_parser.py among them, so only 4 really work.
✅ all three15$41.257/8 verified, plus legacy_parser.py escalated to a human with a trail of 7 failed attempts.
Any capped design≤ 15≤ $41.25The cap is the only guard that bounds spend before the run starts, whatever the agent does.
✅ with a cap of 88$22.00Same 7/8 on this seed, because the seventh doable file passed at iteration 8. On an unluckier seed the same cap leaves good files undone.
✅ plus a per-file limit of 3 (not in the lab)11$30.25legacy_parser.py is escalated after its third failure, at iteration 11, and nothing else is left. Same 7/8, $11.00 less than the 15-iteration run.

The guarded run cost the same as the amnesiac one and did 2 more files, all of them verified. The last two rows are about sizing the cap. At a 70% success rate, the 7 doable files need 7 / 0.7 = 10 attempts on average, so a cap of 15 leaves about 5 iterations of slack for bad luck. Set it tighter and a merely unlucky night looks like a stuck one. Set it looser and the impossible file burns more money every night. A per-file retry limit attacks the real waste: a whole-run cap is spent on one bad unit, while a per-unit limit spends the slack only where retries still have a chance. Memory’s value grows as the run goes on. The amnesiac loop picks blindly from all 8 files, so once 5 are done, 5 of every 8 picks re-do finished work, and the waste gets worse the closer it gets to the end.

Where this shows up in production

  • Turn and budget limits in agent tools

    Agent runtimes expose the hard cap directly as a maximum number of turns per run, such as --max-turns in Claude Code’s headless mode. Pair it with a spend alert at the provider, because a turn limit caps one run, not a cron job that starts a new run every hour. A wall-clock limit is the third bound, for the iteration that hangs instead of failing.

  • Large automated migrations

    Overnight codemods, dependency upgrades and API migrations across many files are exactly this lab’s shape: a queue of units, an agent that succeeds most of the time, and a few units it cannot do. The design work is in the queue, the check, and the leftover inbox, not in the prompt. Keep the checkpoint as a plain file that both the loop and a person can read: done, failed with the reason, still to do. The morning review is then a two-minute read instead of an archaeology dig through logs.

  • CI as the independent verifier

    The cheapest verifier most teams already own is the build: type-check, tests and lint, run by something other than the agent that wrote the change. A loop that marks a unit done only after CI passes on it has guard 2 for free. It also gives each escalation something useful to carry: the failing output for the file a human has to finish.

  • The interview angle

    “How would you let an agent run unattended overnight?” A strong answer names all three guards and where each sits in the loop, then says how it ends: verified progress plus a short list escalated to a human. Bonus points for saying that the verifier must not be the agent that did the work, and for sizing the cap from the success rate: expected attempts, plus slack for a bad night.

Check yourself

1 · The loop keeps failing on the same file with no cap set. Each iteration looks reasonable. What actually stops it?

A goal loop's natural state is "keep going". Every guard that stops a runaway is machinery you add — max_iterations, a wall-clock limit, a budget cap that alerts when it trips.

2 · With the verifier off, the loop finished fastest and everything showed green. Why is that the worst outcome of the three failures?

Runaways cost money and amnesia costs time — both are loud. Self-verified success is silent: the loop reports victory while shipping defects. That's why the verifier must not be the implementer.

3 · The well-guarded loop ended with 7/8 done and one file escalated to a human. Is that a failure?

Loops don't replace judgement; they conserve it. The human inbox for leftovers is a design feature — the alternative is either a runaway or a lie.

Questions

Is the 70% success rate realistic?

Directionally, yes. Real agents succeed at different rates per task type, but no agent is at 100% on nontrivial work — which is the whole point. Loop design is about what happens on the 30%, because unattended, the failures compound.

What maps to what in a real setup?

The hard cap is max_iterations plus a token/dollar budget. The independent verifier is your test suite, linter, or a reviewer subagent with fresh context. The checkpoint is a state file, markdown board, or issue tracker the loop reads before framing each task and writes after verification.

Where does the inner loop fit?

Each single iteration here — "agent attempts auth/token.py" — is an entire inner plan→act→observe run compressed into one box. This lab is about everything around that box. To drive the inner loop itself, run the Agent Loop Simulator.

You just did loop engineering.

Same agent, four outcomes — the guards were the difference. Now go design real ones.

Finished this one? 0 / 61 Labs done
NextThe MCP Playground Next on the “Agents, and what breaks them” ladder · rung 3 of 4

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Labs