lowob

What Is an Agent Loop?

An agent loop is the repeated cycle in which an AI model reads the current state, decides on a next step, calls a tool, observes the result and goes round again until it finishes or a limit stops it. It is what separates an agent from a single model call. The loop itself is now standard in every major agent toolkit. What differs between agents is the context that goes in and the limits placed around it.

Gateway 0ToolingContextRecordReasoningGateway 1Gateway 2Gateway 3
Agents are the reasoning layer, and they touch every stage of the build.

What an agent loop means

A model on its own answers once. An agent keeps going. Each pass through the loop has the same shape, and each step has its own failure mode.

StepWhat happensWhere it goes wrongControl
ReadThe model receives instructions, history and retrieved materialStale or missing contextCurrent records, scoped retrieval, precedents
DecideIt chooses to answer or to call a toolMisread goal, wrong toolClear tool descriptions, few tools
ActThe application runs the tool callOver-broad actionPermissions, draft-only tools, blocking hooks
ObserveThe result is added to contextHostile or misleading tool outputTreat tool output as data, not instructions
StopThe model gives a final answer, or a limit is hitRuns long, costs too muchTurn and budget caps, a defined finish

The pattern has a short history. ReAct, from researchers at Princeton and Google Research, had models write a reasoning step, take an action such as a Wikipedia lookup, read the result and continue. Grounding each step in retrieved facts reduced the hallucination and error propagation seen when models reasoned without acting.

How it works in today's toolkits

Anthropic's documentation for its Claude Agent SDK walks through a four-turn example. Asked to fix failing tests, the agent runs the tests, reads two files, edits one and reruns the tests, then replies in text with no tool call. That text-only reply ends the loop. The SDK offers a maximum number of turns and a maximum spend in dollars; both default to no limit, and the documentation recommends a budget as "a good default for production agents".

OpenAI's Agents SDK describes the same cycle with one addition: a handoff, where control passes to a different agent. If the run exceeds its `max_turns` setting, the SDK raises a `MaxTurnsExceeded` error.

Two details matter for business use. First, context accumulates. Every tool result stays in the conversation, and when the window fills, Anthropic's SDK summarises older history. Its documentation warns that instructions from early in a session may not survive, so standing rules belong in a file reloaded on every request. Second, both SDKs let code intervene between deciding and acting. Anthropic's "hooks" can block a tool call before it runs, and its permission modes range from asking before each tool to running without approval.

An illustrative commercial loop: a meeting-prep agent searches the CRM for the account, reads the last email thread, opens the current proposal, drafts a brief and stops. Four or five turns, all read-only except one draft. Nothing in that loop needs to send.

Why it matters for a commercial team

Because the loop is a commodity, buying decisions should not rest on it. As we argued in A loop with good context, two agents running the same loop on the same model differ in what they are given to read and what they are allowed to do. Anthropic's own guidance makes the same point in engineering terms: agents need "ground truth" from the environment at each step, and it is "common to include stopping conditions (such as a maximum number of iterations) to maintain control".

It also means the loop is the wrong tool when the steps are known. If a process always runs the same five steps in the same order, a fixed workflow is cheaper, faster and easier to test. Use a loop when the next step depends on what the last one found.

Common mistakes

  • No cap. A loop with no turn or budget limit can run for a long time on an open-ended request.
  • Judging only the final answer. Review the trace: which tools were called, in what order, with what inputs.
  • Too many tools. Each tool definition takes context and adds a wrong choice the model can make.
  • Letting the loop send. Keep outbound actions as drafts. The loop's last step should hand work to a person.

lowob takeaways

  • The loop is standard. Reason, act, observe and repeat is built into every major SDK.
  • The edges are where control lives. Context in, tools allowed, approvals and stop rules.
  • Set a cap from day one. Some defaults allow unlimited turns and spend.
  • Use a workflow when the steps are fixed. A loop earns its cost only when the next step is uncertain.

Common questions

What is the agentic loop in AI?

The cycle in which a model decides what to do next, calls a tool, reads the result and repeats until it finishes or reaches a limit. It is the defining feature of an AI agent.

What is the ReAct pattern?

A method, published in 2022 and presented at ICLR 2023, in which a model alternates written reasoning steps with actions such as searches, using each result to decide the next step.

How does an AI agent know when to stop?

It stops when the model returns a final answer with no further tool calls, or when a limit set by the developer, such as a maximum number of turns or a spending cap, is reached.

Sources and notes

What Is an AI Agent, and Where Does It Fit in the Brain?

Read next in The Build Order