# Agent loop

> Canonical: https://skillalmanac.com/glossary/agent-loop | Last verified: 2026-11-25 | Index status: index-eligible

An agent loop repeatedly uses model decisions and environmental feedback to choose steps toward a goal. A turn may request tools, including multiple calls, or finish without one; the application manages results, retained context and stopping conditions.

Also called: agentic loop, agent reasoning loop, ReAct loop, observe act loop, think act observe loop.

## In plain language

An agent loop is the repeat-until-done cycle behind an AI agent. The agent looks at the task, picks an action such as running a command or reading a file, sees what happened, and decides the next step. Think of fixing a leaking tap: you try something, look at the result, and try again. Anthropic's engineering team describes agents as typically just models using tools based on feedback from their environment, in a loop. The limits are cost and control. Each pass uses tokens, a loop can wander or repeat itself, and it needs a stopping rule, such as a maximum number of passes or a person checking in, to keep it from running on.

## Technical definition

In Anthropic's Building effective agents, agents are typically just LLMs using tools based on environmental feedback in a loop. At each step the agent needs ground truth from the environment, such as a tool result or code execution output, to assess its progress. The article says the task often terminates on completion but that it is also common to include stopping conditions, such as a maximum number of iterations, and that agents can pause for human feedback at checkpoints or on blockers. The ReAct paper (Yao et al., arXiv 2210.03629) is one formulation: it has language models interleave reasoning traces with task-specific actions. IBM describes a Think-Act-Observe loop under its ReAct section.

## How it shows up when you use agents

In Claude Code, Codex or Cursor, the agent loop is what you watch scroll past: the agent reads a file, runs a test, sees the failure, edits, and runs the test again. The surrounding program that drives the cycle is the [agent harness](/glossary/agent-harness). A model turn can request one or several tools, or finish without a tool. The application decides which results and history to retain, summarize or omit in the [context window](/glossary/context-window); retaining more material can consume tokens and crowd out earlier instructions.

What breaks when the loop is misunderstood: people expect one prompt to give one answer, then are surprised when a task takes many tool calls, costs more than expected, or goes in circles on a failing step. Anthropic notes that stopping conditions such as a maximum number of iterations are common, and that agents can pause for human feedback at checkpoints or blockers. Use those handles. Interrupt a run that repeats itself, state the goal and the check that proves it is done, and turn on approval prompts for actions you cannot undo. See [human in the loop](/glossary/human-in-the-loop).

Next action: write the stopping rule into your request ("stop when the tests in this folder pass"), and check progress with `/context` and `/usage` in Claude Code during long runs.

## Common confusions

- **Agent loop versus ReAct.** ReAct is one published way to structure the loop, interleaving reasoning with actions. The loop itself is the general cycle, and an agent may not follow the ReAct recipe.
- **Agent loop versus a workflow.** Anthropic separates workflows, where code paths are predefined, from agents, where the model directs its own steps and tool use. A fixed chain of calls is not an agent loop.
- **Agent loop versus chat turn.** A chat turn is one reply. A loop is many model calls and tool runs inside what looks like one request from your side.
- **Myth: the loop ends by itself when the answer is right.** The model decides when it thinks the task is done, and it can be wrong. A stopping condition and a check you control are the safer habit.

## Worked examples in this catalogue

### [What Is an AI Agent? The Model, Tools and Memory Loop](https://skillalmanac.com/learn/what-is-an-ai-agent)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A walkthrough of the agent loop on one task: the model picks a step and a tool call, the tool result comes back, and the model decides what to do next.

Why it exercises the concept: It is the plainest worked case of the definition above, with the loop shown on one concrete task.

### [executing-plans](https://skillalmanac.com/skills/obra/executing-plans)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Works through a written implementation plan inline using a progress ledger, per-task tests and an end-of-branch review; routine between-task human check-ins are explicitly excluded.

Why it exercises the concept: This is a structured inline execution example, not a routine human-check-in loop. The pinned contract uses TDD and a ledger, and reserves stops for its listed exceptional conditions.

### [coding-agent-guardrails](https://skillalmanac.com/skills/skill-almanac/coding-agent-guardrails)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A pre-action checklist for coding agents plus a read-only audit of a repo's guardrail setup.

Why it exercises the concept: The checklist can guide pre-action review if the agent follows it. It is not automatically applied on every pass and is not an enforcement boundary; permissions, hooks and downstream controls are separate.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

```
claude
```

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Claude Code starts an interactive session in which the agent reads files, runs commands and edits code, using the result of each step to choose the next.

Why it exercises the concept: A Claude Code session is an agent loop you can watch. Commands such as /context and /usage show how much of the session the passes have used.

## Related terms

- [AI agent](https://skillalmanac.com/glossary/ai-agent.md)
- [Agent harness](https://skillalmanac.com/glossary/agent-harness.md)
- [Tool calling (function calling)](https://skillalmanac.com/glossary/tool-calling.md)
- [Agentic AI](https://skillalmanac.com/glossary/agentic-ai.md)
- [Context window](https://skillalmanac.com/glossary/context-window.md)
- [Human in the loop (HITL)](https://skillalmanac.com/glossary/human-in-the-loop.md)
- [ReAct prompting](https://skillalmanac.com/glossary/react-prompting.md)

## Sources

- [Building effective agents](https://www.anthropic.com/engineering/building-effective-agents), Anthropic (accessed 2026-11-24)
- [ReAct: Synergizing Reasoning and Acting in Language Models](https://arxiv.org/abs/2210.03629), arXiv (accessed 2026-11-24)
- [What are AI agents?](https://www.ibm.com/think/topics/ai-agents), IBM Think (accessed 2026-11-24)
- [Tool use with Claude: client round trip and parallel tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview), Claude Platform documentation (accessed 2026-11-25)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
