Loop engineering
Loop engineering is the layer above prompt engineering, context engineering, and harness engineering: designing how an agent keeps working, checks evidence, spends budget, and stops.
Definition
Loop engineering is the practice of designing the system around an AI agent: what triggers it, what goal it pursues, what evidence it checks, how much budget it can spend, when it stops, and when a human must approve the output.
Start from what an AI loop is, add a verification loop when the work needs proof, and decide who owns the inner and outer loops.
Loop engineering vs prompt, context and harness engineering
These four layers sit on top of each other. Mixing them up is how a short instruction turns into an open-ended run.
| Layer | What it controls | In practice |
|---|---|---|
| Prompt engineering | The instruction for one turn. | It writes the ask, the format, and the constraints inside that message. It can say what to do once. It does not decide whether the agent should try again. |
| Context engineering | What the agent is allowed to know. | It chooses the notes, files, tests, logs, and product rules the agent can read. The agent can only use what this layer puts in reach. A missing source of truth shows up later as a guess. |
| Harness engineering | Which tools the agent can use. | It is the shell, the browser, CI, the file editor, or retrieval. It grants the permission to act. A tool without a stop condition can still keep running after the job is done. |
| Loop engineering | When the agent continues and when it stops. | It names the trigger, the verifier, the budget, and the approval boundary. A typical shape is to run the check, repair once, and repeat until the check passes, the budget ends, or a person has to approve. |
The six components of an engineered loop
Trigger. The trigger is the event that starts the next run: a schedule, a failing check, a new draft, or a person pressing start. Without a named trigger, the loop waits on a mood. Write the trigger before the prompt, in the same place you write the goal.
Goal. The goal is the outcome that should be true when the loop ends. It has to be something a later check can accept or reject. “Make it better” is not a goal until you say which evidence would show the improvement.
Verifier. The verifier is the evidence check. Tests, source notes, diffs, screenshots, and browser results are verifiers. A verification loop keeps that check outside the part of the agent that wrote the draft, so the maker is not grading itself.
Budget. The budget is the cap on turns, minutes, retries, files, or cost. It is set before the run. When the cap is hit, the loop stops even if the goal is unfinished, and it returns the evidence it has.
Stop condition. The stop condition is the rule that actually ends the run: the verifier passed, the budget is gone, progress stopped, a blocker appeared, or approval is required. The stop conditions page lists those exits. A budget that nobody checks is not yet a stop condition.
Approval boundary. The approval boundary is the line a person still owns. Publishing, sending, deleting, spending, and account changes stay behind that line. You can copy the AI loop template and fill these six fields before the agent starts.
Leave one of the six blank and the run has a hole. No trigger means the loop starts whenever someone remembers. No verifier means a confident paragraph can count as done. No budget means a failed check can buy another turn. No stop condition means the budget is only a note. No approval boundary means a tool that can send or delete may use that tool because the inner loop is still going.
Inner loop and outer loop
The inner loop is the fast cycle the agent runs inside one task: act, check, and retry. The outer loop is the slower cycle that sets the goal, reviews the evidence, approves the output, and chooses the next run. A person or an orchestrator usually owns that outer cycle.
Owning the outer loop means people keep goal-setting, the verification standard, and approval, while the agent is delegated the inner loop. The agent may repeat work inside the budget. It does not get to change the goal, weaken the verifier, or cross the approval boundary because a turn is going well.
A practical split is easy to check. If the agent is editing, running the same check, and reading the result, that is the inner loop. If someone is choosing the job, accepting the evidence, or deciding whether another run should happen, that is the outer loop. The catalog loops keep both: every record has a trigger and an objective for the outer choice, and a verification, stop condition, budget, and approval boundary for the run itself.
A worked example
CI Optimization is a advanced engineering loop in the catalog. The fields below are the loop record, not a retelling.
Trigger. Monthly or when CI is painful
Objective. Attack one CI bottleneck at a time until the target is met or the bottleneck report is more valuable than another tweak.
Verification. CI p50/p95 improves against the same workflow without weakening tests or hiding failures.
Stop condition. Stop when the verifier passes, the budget is exhausted, no progress is made, a blocker appears, or approval is required.
Budget. Set a time, turn, token, retry, file, or dollar cap before running the loop.
Approval boundary. Human approval required before public, destructive, financial, legal, account, or production-impacting actions.
Read that as a designed cycle. Something named starts it. One objective limits the work. The same verification decides whether the attempt counted. The stop condition and the budget end it. The approval boundary says which actions still need a person. Nothing in that record is a claim about how long a real CI system takes. The budget line is the cap you set before the run, and the stop line is the rule that ends it.
Three beginner loops to start with
Start with a beginner loop. The difficulty field in the catalog is the signal used here. Each link goes to that loop’s page.
- Claude Code Repo Readiness (Engineering). Make the repo legible to agents before asking them to do real work.
- Inbox Decision Triage (Personal Ops). Turn inbox sludge into a small list of decisions, drafts, and explicit no-actions.
- Visual Feedback Repair (Design). Show the agent the page, not just the code.
Copy one of them before you invent a new loop. The objective above is the catalog objective. Keep its trigger, verifier, stop condition, budget, and approval boundary in place for the first runs.
Loop engineering checklist
Use this before a run. It is the minimal spec plus the failure modes already listed on this page.
- ☐ The goal says what should be true when the loop is done.
- ☐ The inputs name the source of truth the agent may inspect.
- ☐ The actions say what it can change, and what it cannot.
- ☐ The verifier is evidence, not a feeling that the draft looks finished.
- ☐ The budget caps turns, minutes, files, retries, or cost.
- ☐ A stop condition ends the run on success, no progress, a blocker, budget, or approval.
- ☐ The approval boundary is explicit for publish, send, delete, and spend.
- ☐ The loop cannot rewrite the check it uses to grade itself.
- ☐ The verifier does not grade style while the evidence is still missing.
- ☐ The job is one loop. A broader task is split before the run starts.
Minimal loop spec
| Field | Question |
|---|---|
| Goal | What should be true when the loop is done? |
| Inputs | What source of truth can it inspect? |
| Actions | What can it change? |
| Verifier | What evidence decides success or failure? |
| Budget | How many turns, dollars, files, or minutes can it spend? |
| Approval boundary | What must never publish, send, delete, or spend without a human? |
Common failure modes
- No measurable stop condition.
- Verifier checks style instead of evidence.
- Approval boundary is implicit.
- The loop can mutate the source of truth it uses to grade itself.
- The task is too broad for one loop and should be split into smaller loops.
Each failure mode maps to a line in the checklist above. A missing stop condition, a style-only verifier, an unspoken approval boundary, a check the agent can edit, or a job that should have been two loops are reasons to stop designing and fix the spec. They are not reasons to add another turn.
FAQ
What is loop engineering?
Loop engineering is designing the operating cycle around an AI agent: trigger, goal, repeated action, verifier, stop condition, budget, and approval boundary.
Is loop engineering different from prompt engineering?
Yes. Prompt engineering shapes one instruction. Loop engineering shapes repeated work and the control system around it.
What is the most important part of a loop?
The verifier and stop condition. Without them, the loop can keep producing work that looks active but is not converging.
Is loop engineering replacing prompt engineering?
No. Prompt engineering still shapes the instruction for one turn. Loop engineering adds the cycle around that instruction: the trigger, the verifier, the budget, the stop condition, and the approval boundary. You still write the prompt. The loop decides when another turn is allowed.
What is an example of loop engineering?
CI Optimization is one example from the library. Its trigger is: Monthly or when CI is painful Its objective is: Attack one CI bottleneck at a time until the target is met or the bottleneck report is more valuable than another tweak. Its verification is: CI p50/p95 improves against the same workflow without weakening tests or hiding failures.
How do I start loop engineering?
Pick one beginner loop from the library and copy its trigger, objective, verifier, stop condition, budget, and approval boundary. Use the AI loop template if you are writing a new loop. Run that single job inside those limits before you add a second one.