Agent Loop
also called Agentic loop
Think, act, observe — repeated until the task is finished.
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.
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.
- blogBuilding agents with the Claude Agent SDK ↗
States the agent loop plainly — gather context, take action, verify work, repeat — and shows subagents and compaction as context-isolation tools.
- paperReAct: synergizing reasoning and acting in language models ↗
Interleaves reasoning traces with environment actions so observations can correct the plan. The paper every agent loop is a descendant of.
- blogEffective harnesses for long-running agents ↗
The initializer-plus-incremental-sessions pattern for work that outlives a context window, and the four ways it fails: doing too much, losing context between sessions, declaring victory early, not testing end to end.
Agent
A model given tools, a goal and permission to keep going on its own.
Harness · Scaffold
Everything around the model that makes it an agent.
Tool Call
The model asking for a specific function with specific arguments.
Tool Result
What came back from the call, appended to context.
AFK · Away from keyboard
Running without a person watching.