← back to the archiveCover illustration for “Agent loop: think, act, observe, repeat”
TERM8mo ago·Published · Updated ·by Andy Padia

Agent loop: think, act, observe, repeat

In short: The agent loop is the reason, act and observe cycle an AI agent repeats until the task is done or a limit stops it, and every turn adds cost and latency.

The agent loop is the repeating cycle an AI agent runs: reason about the goal, take an action with a tool, observe the result, then reason again until the task is done or a limit stops it. The pattern goes back to the ReAct paper from October 2022, which had a model interleave reasoning traces with task-specific actions.

Agent loop in plain words

It is how you look for your keys. Think where they might be, check the table, see they are not there, think again, check your jacket. Each observation changes the next guess.

How it works

  1. Reason: the model reads the goal and history and plans a next step.
  2. Act: it emits a tool call with arguments.
  3. Observe: the harness runs the tool and returns the output.
  4. Repeat or stop: the loop ends when the model answers without asking for another tool, a step limit is hit or a check fails.

Anthropic's Agent SDK documentation, read in November 2026, calls one pass through this cycle a turn. It lets you cap a run with max_turns or max_budget_usd, and a run that hits the cap returns an error result such as error_max_turns.

Example

As an illustration, a coding agent fixing a failing test reads the error, opens the file, edits a line and runs the tests. It sees a new failure, edits again, runs again, sees green and stops. That is the same loop repeated a handful of times.

Where you'll meet it

  • Every coding agent's run log
  • Tracing tools that show one span per loop turn
  • Agent frameworks, where it is often called a "step" or "turn"
  • SDK options that cap turns or spend per run

What it changes for you

Every turn is another model call, so cost and latency grow with the number of turns, and that number is a metric worth tracking. For developers, clear tool outputs shorten the loop and noisy outputs lengthen it. For teams, a stopping condition is cheap insurance: Anthropic's December 2024 guide says it is common to include one, such as a maximum number of iterations, to keep control.

Agent loop vs chain-of-thought

Chain-of-thought is reasoning inside one model call. The agent loop spans many calls, with real-world feedback between them.

Common mistake

My view: people set no maximum turn count and discover runaway loops on the invoice. Set a budget per task, log every turn and treat "hit the step limit" as a failure category in your evals.

AI agent · Tool calling · Chain-of-thought · LLM tracing · Cost per task

From the archive: Coding agents need a refinement budget · How to keep multi-step AI agents under control

Give every agent loop a turn budget, and count hitting that budget as a failure in your evals.

#field-guide#agents#react#reasoning

Sources

  1. arxiv.org/abs/2210.03629
  2. code.claude.com/docs/en/agent-sdk/agent-loop
  3. anthropic.com/research/building-effective-agents
newer drop →
Hybrid search: combining keyword and vector search

related drops

explore all 557 drops →
← back to the archiveday 175