The term "agent loop" now covers several different systems: a cron job that prompts a model, a retry wrapper, or a model calling tools until it declares completion. Those designs have different state, stopping behavior, and failure modes despite sharing a name.
Most of those setups reduce to this:
while True:
ask_the_model_again()A production loop needs a control system that reads state, chooses an action, executes it, and checks the result against an external condition. That verdict changes the next iteration and decides when the run stops.
One word, five generations
The term has changed meaning several times since 2022.
2022 ReAct reason -> tool -> observe, one model, one cycle
2023 AutoGPT goal-seeking, famous for spinning in place
2025 ralph same prompt repeated over durable files
2026 /goal productized loop, a validator decides done
now orchestration supervisor loops scheduling worker loopsReAct introduced the think-act-observe cycle inside a model run. AutoGPT put a goal around repeated actions and exposed how easily an agent could continue without progressing. The ralph pattern emphasized durable files that accumulate work across repeated prompts. Newer product loops add external validators and supervisors that schedule specialized workers. The important change is that a validator, rather than the model generating the work, can decide whether the run is complete.
Using one term for these designs hides consequential differences.
What a loop actually contains
A loop that can run unattended needs four parts.
The human writes the intent and stopping behavior up front: stop when tests pass, when the PR is open, or after thirty iterations.
The controller prompts the agent each tick. This is plain code, not a model. It owns the schedule, the budget, and the decision to continue.
The agent session does the work: reads the issue, edits the code, runs the tools, touches GitHub or Slack or the database.
The feedback gate checks the work. Tests, lint, a validator model, a metric, a human. The gate's verdict, not the agent's self-assessment, decides what happens next.
while not done:
action = agent(state) # model decides what to do
result = execute(action) # tools do it
verdict = evaluate(result) # tests/lint/validator judge it
state = update(state, result, verdict)
done = verdict.satisfied or limits.exceededThe evaluate step feeds a verdict back into state, so iteration twelve can respond to what happened in iteration eleven. Without it, the controller only repeats the prompt.
I wrote before about moving negotiation policy out of the prompt and into code. The same boundary applies here: a model produces work, while tests, policy code, or another independent check decide whether the work satisfies the task.
The loop also needs resumability across a crash, context compaction, browser refresh, or delayed human approval. Files, checkpoints, and recorded verdicts preserve progress outside the chat transcript.
- 01IntentThe goal, acceptance criteria, and explicit stop behavior.Read every tick.
- 02Working artifactsFiles, diffs, traces, eval outputs, screenshots, or records the agent produced.The system memory.
- 03VerdictsTest results, lint output, judge scores, human approvals, and failed assertions.Progress is measured here.
- 04BudgetIterations, tokens, dollars, wall-clock, and tool-call count.A loop without a meter is a billing bug.
- 05Stop reasonSatisfied, blocked, no progress, budget exceeded, or human intervention required.Never let the model invent this.
Control graph
The gate changes what the controller does next
A conceptual control graph from the article: choose a verdict or limit, then follow the state transition.
Scenario
Completion belongs to the external gate.
Sequence
- Reserve the runCurrent
- Execute an actionUpcoming
- Ask the external gateUpcoming
- Finish with evidenceUpcoming
Reserve the run
The controller reads durable intent and reserves budget before scheduling work.
Read the full explanation
Gate passes
Completion belongs to the external gate.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Ask the external gate. Tests, a validator, a metric, or a human check the result independently of the working agent.
- Finish with evidence. The passing external verdict satisfies the declared acceptance criteria; preserve the result and stop.
Gate fails
A failure changes the next tick through durable state.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Ask the external gate. Tests, a validator, a metric, or a human check the result independently of the working agent.
- Return the failed assertion. Persist the artifact and failed verdict, then return to Running with this evidence if budget and progress checks permit.
No progress
Repeated activity is not evidence of progress.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Return the blockage. Unchanged artifacts or repeated failed actions trigger the no-progress rule. Preserve the trace and seek outside input.
Budget exhausted
A controller limit can interrupt any state.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Stop at the ceiling. The iteration, time, token, or dollar limit stops the run. Preserve state rather than granting the agent more budget.
Gate passes
Completion belongs to the external gate.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Ask the external gate. Tests, a validator, a metric, or a human check the result independently of the working agent.
- Finish with evidence. The passing external verdict satisfies the declared acceptance criteria; preserve the result and stop.
Gate fails
A failure changes the next tick through durable state.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Ask the external gate. Tests, a validator, a metric, or a human check the result independently of the working agent.
- Return the failed assertion. Persist the artifact and failed verdict, then return to Running with this evidence if budget and progress checks permit.
No progress
Repeated activity is not evidence of progress.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Return the blockage. Unchanged artifacts or repeated failed actions trigger the no-progress rule. Preserve the trace and seek outside input.
Budget exhausted
A controller limit can interrupt any state.
- Reserve the run. The controller reads durable intent and reserves budget before scheduling work.
- Execute an action. The agent uses tools to produce an artifact. Its claim to be finished is not a verdict.
- Stop at the ceiling. The iteration, time, token, or dollar limit stops the run. Preserve state rather than granting the agent more budget.
Operate one tick of the controller
Set the next tool result and external verdict, then advance the run. These rules are illustrative: two unchanged failures block progress, and the cap limits iterations. Changing the ceiling starts a fresh run.
- Tick 1Not run
- Tick 2Not run
- Tick 3Not run
- Tick 4Not run
Inspect the durable checkpoint
This is simulated local state. A production controller would persist it outside the browser; resetting starts a new run.
No tool action has run. The intent and limit are ready; no verdict has been invented.
Precedence: an exhausted cap prevents the next action; approval pauses before work. After a completed tick, a passing gate finishes the run; otherwise the cap and no-progress rule apply. Production limits can also interrupt in-flight work.
Scheduling and state
Cron can provide the schedule, but the loop body still has to read current state, choose an action, evaluate the result, and decide whether to continue. Firing the same static prompt every hour does not provide those controls.
The context window is also an unreliable state store. Iteration 27 may find a bug, iteration 28 may patch it, and iteration 29 may reveal that the tests still fail. That history needs to survive restarts and context compaction in files, task records, artifacts, or checkpoints.
The three limits that make it production
Loops that run unattended near real money need three guardrails:
- An iteration cap. Thirty steps, then stop, no appeals. Prevents the runaway.
- No-progress detection. If the diff hasn't changed and the test count hasn't moved in N iterations, the loop is spinning, not working. Stop it. This is the AutoGPT lesson, paid for in 2023 and still being re-learned.
- A token and dollar ceiling. A five dollar task should not be able to become a five hundred dollar bill because the gate kept saying "not yet." Track tokens, cost, and wall-clock per run, and kill at the ceiling.
These limits make unattended operation bounded and observable.
- ReAct vs. State machinesContrasts autonomous inner loops with explicit state and control graphs, including the different failure boundaries of each.
- Why Agent Loops Fail in ProductionCovers the database work behind unattended loops: checkpoints, transactions, audit trails, and bounded blast radius.
- LangGraphReference implementation family for durable execution, human-in-the-loop interrupts, and stateful agents.
- Running agentsOfficial OpenAI framing of the runner loop: tools, handoffs, approvals, and streaming build on top of the loop rather than replacing it.
- LangGraph interruptsShows how a loop can pause, persist its state, and resume after receiving external input.
The loop is not the asset
The controller itself may be only a hundred lines of code. Its value comes from the capabilities available inside it: search, editing, tests, database queries, and pull requests.
loop = schedule
+ model decision
+ tools
+ feedback
+ durable state
+ hard limitsAn elaborate orchestration diagram does little if the workers lack reliable, tested capabilities. The scheduling layer can change while a library of named skills remains reusable across loops.
If you repeatedly paste test output into a chat, re-prompt after each failure, and decide when the task is finished, you are supplying the controller and feedback gate manually. That is reasonable while discovering what the checks should be. Once a check is stable, move it into the loop with durable state and an explicit stop condition.

