Strip away the frameworks and nearly every AI agent is built on the same idea: a loop. The model looks at the situation, decides what to do, takes an action through a tool, observes the result, and repeats until the job is done. This pattern, popularised by approaches such as ReAct (reason and act), is what turns a model that answers questions into one that completes tasks.
Gather context
Read task, state, tool results
Decide
Plan the next step
Act
Call a tool or write output
Verify
Check the result, then loop or stop
The four phases
- Gather context. Assemble the task, relevant data and results from previous steps (context engineering decides what goes in).
- Decide. The model reasons about the goal and picks the next action, often a tool call with arguments.
- Act. The harness executes the tool inside its permissions and returns the output as an observation.
- Verify. Check the outcome: did it work, is it complete, does it pass policy? Then continue or stop.
Common loop patterns
| Pattern | How it works | Best for |
|---|---|---|
| Single loop (ReAct) | Reason, act, observe, repeat in one thread. | Open-ended tasks with unpredictable steps. |
| Plan and execute | Write a plan first, then run steps, re-planning when needed. | Longer, multi-stage workflows. |
| Orchestrator and workers | A lead agent delegates subtasks to specialist sub-agents. | Broad research, parallelisable work. |
| Generator and critic | One step produces, another reviews and requests fixes. | Quality-sensitive output like code, reports, contracts. |
How loops go wrong
- Endless looping: the agent retries the same failing step without making progress.
- Compounding errors: an early mistake gets treated as fact and builds on itself.
- Runaway cost: many steps with large contexts add up fast.
- Premature "done": the agent declares success without actually verifying.
- Unsafe actions: an over-privileged tool does something irreversible.
Controls that keep loops safe
- Hard budgets: maximum steps, tokens, time and spend per run.
- Explicit stop conditions: objective checks (tests pass, record updated), not the model's say-so.
- Loop and stall detection: detect repeated actions and escalate to a human or a different strategy.
- Checkpoints and approvals before high-impact actions.
- Retries with backoff and error feedback so the model sees why a call failed.
- Full tracing so every iteration can be replayed.
Read next: harness engineering, the system that wraps the loop.