Core Concepts

Agent Loop

The agent loop is the repeating perceive-plan-act-observe cycle by which an AI agent turns a goal into a sequence of actions, checking each result before deciding what to do next.

PerceivePlanActObserve
Each iteration perceives state, plans an action, acts, and observes the result before looping again.

Underneath almost every AI agent is the same basic mechanism: it looks at the current state of things, decides on an action, takes that action through a tool, and then looks at what happened as a result of that action — before deciding on the next one. That repeating cycle is the agent loop, and it's what turns a language model, which on its own just produces text, into something that can actually get a multi-step task done.

The loop typically continues until one of a few conditions is met: the goal looks achieved, a step or time limit is hit, the agent determines it's stuck and should ask for help, or a human interrupts it. Each iteration re-reads the current state rather than blindly following a pre-written script, which is what lets an agent adapt when a tool call fails, returns unexpected data, or reveals that the original plan needs to change.

This loop is the mechanism referenced across most of the other terms on this page — planning describes how the 'decide the next action' step can itself be broken into sub-steps, reflection-self-correction describes an extra evaluation pass some loops add before committing to an action, and react-prompting describes one well-known way to structure the model's own internal reasoning during the loop.

How it works

A typical iteration has four parts, matching the diagram: perceive — read the current state, which might be a file's contents, an API response, or the output of the last command; plan — decide, given that state and the overall goal, what to do next (this can be a single decision or involve the more deliberate multi-step process described under planning); act — actually call a tool, run a command, or make an edit to carry that decision out; and observe — read back what happened, including errors, and feed that back into the next perceive step.

What makes this a loop rather than a one-shot pipeline is that each cycle's observation becomes the next cycle's starting state. If a test fails during the act step, the next perceive step sees that failure and the plan step can decide to fix it rather than continuing blindly. The loop terminates on success, on hitting a limit the system enforces (max steps, max time, max cost), or when the agent decides it needs a human — the human-in-the-loop entry covers how that handoff is typically designed.

Example

A build-fixing agent's loop might go: perceive (read the CI failure log), plan (decide the failing test is caused by an outdated dependency), act (edit the dependency version and rerun the tests), observe (see the tests pass) — at which point the loop ends because the goal condition is met. If the tests had failed again for a different reason, the next perceive step would pick that up and the loop would continue.

How it differs

The agent loop is sometimes conflated with react-prompting: the agent loop is the general perceive-plan-act-observe mechanism that almost any agent implements in some form, while ReAct is one specific, published way of prompting a model to interleave its reasoning ('Thought') and actions inside that loop — ReAct is one technique for implementing part of the loop, not a synonym for the loop itself.

Common misconceptions

Often assumed: The agent loop means the agent just keeps repeating the same action.
Actually: Each iteration re-reads the current state and can change what it does next; the loop adapts to new information rather than blindly repeating a fixed script.
Often assumed: A longer loop (more iterations) always means a better or more thorough agent.
Actually: An agent stuck in many iterations without progress is often a sign it's failing to make progress or looping on an error, not that it's being more thorough — most implementations cap iterations for exactly this reason.

FAQ

What is the agent loop?
It's the repeating perceive-plan-act-observe cycle an AI agent runs — reading the current state, deciding an action, taking it via a tool, and checking the result — before deciding what to do next.
When does an agent loop stop?
Typically when the goal looks achieved, a step/time/cost limit is hit, or the agent decides it's stuck and needs a human to step in.
Is ReAct the same as the agent loop?
No — the agent loop is the general perceive-plan-act-observe mechanism, while ReAct (see react-prompting) is one specific technique for structuring the model's reasoning within that loop.

Last checked: 2026-08-28

Related terms