Stop prompting your AI agent by hand. Build the loop that prompts it instead.
“I don't prompt Claude anymore. I have loops that are running. My job is to write loops.”
Here is how to add loop engineering to your own project, one step at a time.
The five parts of every reusable loop
- The instructions. What the loop does each cycle.
- The thing being improved. A query, a model, a document.
- The feedback signal. Tests passing, a number going up, a judge saying yes.
- The run log. An append-only record of what was tried, scored, kept, or reverted.
- The stop condition. A plateau, a budget, or a target.
If the loop cannot decide from a real signal whether a change was good, it is not a loop. It is a wish.
1Define done as a check, not a feeling
Write the success test the system can run on its own, without human judgment. Tests pass. No lint errors. Numbers match. A second model with different instructions confirms the answer. If you cannot check it automatically, your loop cannot run without you watching it.
The most common failure: the agent writes some code, sees progress, and says done while the tests still fail. The message that ends the conversation is not the same as the job being finished.
Pick one task you do by hand and write down what you look at to know it worked. That is your verifier. Automate it first.
2Add brakes before you add freedom
Here is the math that makes brakes non-negotiable. If each step is 90% accurate, a chain of 5 unsupervised steps fails roughly 40% of the time. The agent makes one small mistake, the error compounds across steps, and it ships garbage with total confidence.
Three guards from day one:
- A hard cap on the number of turns so a stuck agent cannot spin forever.
- A ceiling on money and time spent.
- A detector that spots the agent repeating the same action and kills the loop.
Every loop in the open-source collection at github.com/gaasher/Agent-Loop-Skills ships with these built in. Start tight. Loosen the caps once the system proves itself.
Add a turn limit and a timeout to any agentic workflow you already run. Twenty turns and ten minutes beats infinite.
3Move memory out of the conversation
The model forgets everything between runs. Your storage does not. A status column, a markdown file, a task board. The simplest version is a run log: an append-only file listing every attempt, its score, and whether you kept or threw away the change. The loop reads the log before the next try so it knows what failed and what plateaued. Resume from where you left off instead of starting over.
Re-doing completed work because the system forgot is not a model problem. It is a memory problem.
Take one long-running task and make it write "step 3 of 14 done" somewhere durable after each unit of progress. Have it skip finished steps on the next run.
4Separate the maker from the checker
Whatever grades the work cannot be the same model that produced it. A loop with no critic is just an agent nodding along to its own work. The pattern is simple: propose a change, run it, score it against a real signal, keep it only if it is better, and throw it away otherwise. The verifier decides. Not the proposer. Only take your hands off once you trust the thing that can say no.
Add one automated check after your agent's output that runs on its own. Tests for code. A different model with a strict checklist for content. Close the loop only when the check passes.
5Protect the context and the tools
Long loops rot from the inside. Old outputs and dead ends pile up in the context (what the model can see). Quality drops as the pile grows, noise feeds more noise, and the loop spirals. This is called the doom loop.
Three fixes:
- Summarize long conversations and continue from the summary.
- Move big outputs to files and keep only the slice you need in view.
- Hand messy subtasks to helper agents so only clean results come back.
Tools need discipline too. A few focused tools beat a hundred overlapping ones. Every write must be safe to run twice without creating duplicates. Every error message must tell the agent what to do next, because inside a loop an error is not a dead end. It is the next instruction.
Remove overlapping tools. Make one write operation safe to run twice. Rewrite one error message so someone seeing it cold would know the next move.
What these steps look like with real numbers
A correctness-gated SQL tuning loop took a query from roughly 1,132 milliseconds down to just over 1 millisecond. A speedup of roughly a thousand times. On every try, the result was checked against a verified baseline. If the output did not match, the change was thrown away no matter how fast it was. The verifier decided. Not the optimizer.
A tournament-style research loop ran against a CIFAR-10 image model under a fixed training budget. Competing agents proposed changes each round. A separate judge scored them, kept the winners, and threw away the regressions. Accuracy climbed from 0.734 to 0.798, entirely hands-off. Seven of eleven changes were kept. All four regressions were caught and discarded. The judge drove every decision.
Both examples come from the open-source Agent-Loop-Skills collection. They work because the feedback signal is real and the verifier is independent.
This is what it looks like in production
Vero, our pharma MLR document pipeline, runs every step. Each extracted claim is re-checked against source documents by a separate validation phase. A drafting agent produces the analysis, an independent quality judge reviews it with a strict checklist, and a consolidator assembles the final verdict. No agent grades its own work. Progress is saved to durable storage so interrupted runs resume instead of restart.
The Amsyst chatbot applies the same pattern. A separate task-modification agent handles structured updates so the main conversation stays clean. Calls that could block became async with timeouts. Logging moved to background tasks so replies stay fast.
Start today
You do not need an overnight autonomous agent on day one. Start with Step 1. Define done as a check. Add a brake. Move state outside the conversation. Separate one checker from its maker. The system gets better from there.
To move faster, you do not have to build from scratch. Ready-made, open-source loops exist at github.com/gaasher/Agent-Loop-Skills. Plug in your own task, the thing to improve, and the signal that decides better. The five pieces are already wired. You supply the work and the test.
We picked this name for a reason. Radical change, running on a loop. The industry is catching up to what the name always meant.
Sources: Addy Osmani, "Loop Engineering" (June 2026); Boris Cherny and Peter Steinberger via the Akshay Pachaar thread on X; dailydoseofds, "Loop Engineering, Clearly Explained!"; gaasher/Agent-Loop-Skills for the five-part anatomy, the verification math, and the real run results cited above.