Most people still think the prompt is the main artifact. But when an AI agent starts doing real work — calling tools, writing code, reading files, running tests — the prompt is not enough anymore. The real artifact becomes the loop.
Loop engineering means designing the system around the model: the goal, the check, the budget, the stop condition, and the escalation rule.
From prompting to loop engineering
In the old model, you ran Prompt → Agent → Output and trusted the result. In the new model, the loop builds the prompt from the current state, runs the agent, checks the result, and decides whether to retry, refine, escalate, or stop.
The prompt didn't disappear. It moved down one layer — it's now a function the loop calls on every iteration.
Prompt engineering improves instructions. Loop engineering improves the system.
The core loop
A reliable AI loop has four main steps:
- Define the goal — in measurable terms
- Let the agent act — call tools, write code, fetch data
- Check the result — using a test, a rubric, a judge, or a human
- Decide what happens next — retry, stop, or escalate
The decision is the important part. If the result passes the check, the loop stops. If it fails, the loop retries with feedback. If the task is risky or the agent is stuck, the loop escalates to a human.
An agent can say, "I'm done." But the loop asks, "Did the work actually pass the check?"
The five layers of loops
Loop engineering can be understood in five layers:
- Layer 1 — Token loop: The model predicts the next token.
- Layer 2 — Action loop: The model calls tools and observes results.
- Layer 3 — Verification loop: The system checks the output and retries if needed.
- Layer 4 — Trigger loop: The loop starts automatically when an event happens.
- Layer 5 — Improvement loop: The system learns from past runs and improves future loops.
Most teams do not need all five layers. The biggest practical win usually comes from Layer 3: verification. Before building a complex agent, build a loop that knows how to check, retry, stop, and escalate.
The five AI agent loop patterns
There are five proven patterns, each matched to a different kind of check:
ReAct
The agent reasons, calls a tool, observes the result, and repeats. Best for short tasks where tool output is self-evidently right or wrong.
Reflection
The model critiques and revises its own draft. Useful for polishing output — but not a real external check.
Reflexion
External feedback plus memory of lessons across attempts. Best for coding with tests or any deterministic pass/fail signal.
LLM-as-Judge
A second model scores the work against a rubric. Best for subjective rubrics you can write down. One rule: use a different model family for the judge than the generator — two models from the same family share biases.
Human-in-the-Loop
A human approves, edits, or rejects the agent's proposal. Best for high-stakes, regulated, or ambiguous work.
The pattern you choose depends on the check. If the check is a test, use a verification loop. If the check is a rubric, use a judge. If the check is high-risk, use a human.
Coding agents: the clearest example
Coding agents show loop engineering very clearly. A coding loop looks like this:
Bug → Agent writes patch → Run tests → Pass or retry → Open PR or escalate
This works because code has natural checks. Tests pass or fail. Types pass or fail. Builds pass or fail. The agent does not need to guess whether the work is done — the system can verify it.
Vibe coding is useful for exploration. Loop engineering is what makes the output safer to ship. Vibe to explore. Verify to ship.
The pre-flight checklist
Most agent projects fail because of planning gaps, not model quality. Before you write a line of agent code, answer these:
- Can you write the check right now? If not, stop — you don't know what "done" means.
- Is the goal stated in terms of the check? ("All tests pass," not "improve quality.")
- What are the budgets? Token, time, dollar, and iteration count — all four.
- What is the stop condition and escalation rule? When does the loop hand back to a human?
- Where is the run logged? You can't debug what you don't capture.
And know when not to build a loop: one-shot tasks, anything you can't write a check for, single catastrophic actions (use a confirmation step instead), or work better solved by deterministic code.
The whole idea in one sentence
Stop being the prompter. Design the loop that prompts the agent for you — with a goal, a check, a budget, and a way out. That is loop engineering.