AI CompendiumA public chart of the language
Home / Agents & Harness / Agent Loop
Agents & Harness

Agent Loop

also called Agentic loop

Think, act, observe — repeated until the task is finished.

Definition

The control loop that drives an agent: send the current context to the model, let it emit either a tool call or a final answer, execute the tool, append the result, and repeat.

Most agent bugs are loop bugs: the loop never terminates, it repeats the same failing action, or the stopping condition is ambiguous. Guardrails on iterations, time and spend are not optional.

Two properties of the loop drive most practical advice. It is unbounded unless you bound it, so step and spend limits are part of the design rather than an afterthought. And it appends everything to the same context, so quality tends to fall over the course of a run — which is why compaction and subagents exist.

How people use it
Post-mortem on an agent that burned a budget overnight.
"The loop had no iteration cap and the tool kept returning an error it could not recover from. Classic."
Worked examples

The loop that ran all night

A background agent is given a vague task with no budget.

It oscillates — edits a file, breaks a test, reverts, tries again — because nothing tells it that continuing is failing. A step limit, a wall-clock limit and an explicit stop condition are what turn a runaway loop into a bounded job that reports back.

Verification belongs inside the loop

An agent says the task is complete.

Make the loop require evidence before it may exit: tests run and passing, build clean, the specific acceptance check executed. Without that, "done" is a claim, and the loop terminates on a claim.

Sources
Related terms