Agent loop: the mechanism that makes an agent autonomous

The agent loop is the decide, act, observe cycle an AI agent repeats until it reaches its goal or stops.
3 min read
Believemy logo

This is the mechanism separating an AI agent from a conversational assistant, and it is also the main line of spend in any agent project. Understanding the loop means understanding both what makes an agent capable and what makes a bill run away.


Definition

The agent loop is the cycle an agent repeats to advance towards its goal: it decides the next action, executes it, observes the result, then starts again taking into account what it just learned.

Each pass through the loop is a full call to the model, carrying all the accumulated history. That detail explains an agent's economics: the tenth pass costs far more than the first, because it carries everything that came before.

Good to know

A loop is not a fixed sequence. Two runs of the same agent on two different files will not take the same number of passes nor the same actions. That is its strength, and what makes its cost hard to predict in advance.


What stops a loop

Stopping conditionWhat it protects
The goal is reachedThe normal case
Maximum number of passesThe bill
Budget reachedThe bill, differently
No progress for N passesSilent deadlock
Unrecoverable errorPointless persistence

The last four lines are guardrails, and all of them are needed. An agent with no pass ceiling facing a problem it cannot solve does not stop on its own: it rephrases, retries, rephrases again, burning Token on every pass.


The trap of the pass that learns nothing

The classic case: the agent calls a service that returns an error, it retries in exactly the same way, gets the same error, starts again. Three identical passes and no progress.

The remedy is a simple rule to state in the instruction: if two successive attempts produce the same result, change approach or stop. It sounds obvious, but without an explicit instruction a model tends to persist.

Warning

Monitor the number of passes, not only total cost. An agent that moved from three to four passes on average has changed behaviour, and you will see it on that indicator weeks before you see it on the invoice.


Frequently asked questions

Question

How many passes for a common task?

Three to five for a well-scoped task with two or three tools, and often fewer with a Reasoning model that plans its steps better. Beyond ten on average, it usually signals that the goal is too broad or that the supplied tools are not enough.


Question

What happens when the history gets too long?

The Context window saturates and the earliest passes fall out of range. The agent then loses track of what it already tried, and can repeat an action already done. One more reason to cap the number of passes.


Question

Can a loop be made reproducible?

Not entirely, that is the nature of an agent. If you need the same result every time, a classic Workflow suits your case better.


Question

How do you build a loop that stays under control?

By setting the guardrails before the first run, not after the first nasty surprise. Our Claude Code course covers that alongside the build itself, ceilings and logging included.

Related terms

Discover our aI and automation glossary

The vocabulary of artificial intelligence and automation, explained for people who want to use it in their business, not for people who build the models.

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.