Agent loop

Definition

An agent loop is the repeating cycle an AI agent runs to finish a task: it plans a step, calls a tool, reads the result and decides whether to continue or stop. The loop ends when the goal is met or a limit is reached.

By Ronan Liedmeier, fractional head of growth and course author · Published 17 October 2026 · Last updated 17 October 2026

Also called: agentic loop, plan-act-observe loop

Every agent you use or review runs some version of it. Knowing the cycle tells you what to ask of any agent: which tools can it call, and what makes it stop?

How it works

  1. Plan: the model reads the goal and everything gathered so far, and picks the next action.
  2. Act: it calls a tool, such as a search, a file read or an API request.
  3. Observe: the result comes back into the model's context.
  4. Decide: carry on, change approach, or finish.

Claude Code's documentation describes the same cycle as gather context, take action, verify results, repeat until done. Anthropic's guide to agents recommends stopping conditions such as a maximum number of iterations. Those limits belong in code (steps, run time, spend) so a run that goes wrong ends on its own and leaves a trace you can read.

Example

A performance marketer builds a loop to audit an ad account. It gets three tools: read campaigns, read performance by date range, and write a proposal into a document. None of them can change a budget, so the loop can only suggest. It stops after 15 tool calls, or earlier when it calls a "finish" step with its report.

Common mistake

Putting safety in the prompt ("never change live campaigns") while a tool that changes live campaigns is still connected. The model can ignore a sentence in a prompt. It can't call a tool it was never given, so decide what the loop can touch by choosing its tools.

Learn it in AI Academy

Related terms

AI agent
An AI agent is an AI system that works toward a goal by choosing its own next steps: it picks a tool, uses it, looks at the result and repeats until the task is done. You set the goal and the limits, and the agent works out the path.
Tool use (function calling)
Tool use, also called function calling, is when an AI model asks your software to run a specific action, such as a search or a database lookup, and then uses the result in its answer. The model chooses the tool and the inputs; your code runs it.
Trace
A trace is the step-by-step record of a single run of an AI workflow or agent, showing every model call and tool call in order with its inputs, outputs, errors and timing. Reading one shows exactly where a run went wrong.
AI guardrails
AI guardrails are checks and limits placed around an AI system that block or flag unsafe or wrong inputs and outputs before they cause harm. The strongest ones run as code outside the model, so a cleverly worded request can't talk its way past them.

Sources

Browse all terms

Find your next step with AI