Agentic loop

The agentic loop is the repeating cycle inside an AI agent: the model decides on a step, software carries it out, the result goes back to the model, and this repeats until the task is done or a limit is reached.

A chatbot answers once and waits. An agent keeps going. Anthropic's Agent SDK documentation sets out the cycle: the model receives the request along with its instructions, tool definitions and the conversation so far; it replies with text, a request to use one or more tools, or both; the software runs the tools and returns the results; and the model decides again. The loop ends when the model replies without asking for any tool.

The documentation's example is a request to fix failing tests. In the first turn the agent runs the tests and sees three failures. In the second it reads the code and the test file. In the third it edits the code and reruns the tests, which now pass. In the fourth it writes a short reply saying so. That is four turns, three of them with actions. A harder request can chain dozens of tool calls.

What makes the loop work is real feedback. Anthropic's December 2024 guide to building agents stresses that at each step an agent needs ground truth from its environment, such as tool results or code output, to judge whether it is making progress. The 2022 ReAct paper was an early demonstration that interleaving reasoning with actions and observations cuts the invented facts and compounding errors of reasoning alone.

Loops also need limits. Without them, an open-ended request can run for a long time. Agent frameworks let developers cap the number of turns or the money spent, and good designs pause for a person at checkpoints or when the agent is stuck. Every turn adds to the context the model must read, so long runs are summarised as they go, which can drop early details.

The loop explains both why agents can do more than chatbots and why they cost more. Each turn is another model call over a longer context, and a wrong step early on can carry through every later one.

Common questions

What is the agentic loop?

It is the cycle an AI agent repeats: think, act, observe the result, and think again. The model chooses an action, the surrounding software executes it, and the outcome is fed back until the model decides the task is finished.

How does an agent know when to stop?

Usually the model decides it has finished and replies without requesting any more tools. Developers also set hard limits, such as a maximum number of turns or a spending cap, and some agents stop to ask a person when they are blocked or reach a checkpoint.

Why do agentic loops get expensive?

Each pass through the loop is a fresh model call that includes the whole conversation so far, including every tool result. As the task goes on the context grows, so later turns cost more than early ones, and complex tasks can run to dozens of turns.

Finding more

Search for "agent loop", "ReAct pattern" or "tool use loop" to see how agents are structured. The clearest sources are the developer documentation of agent frameworks, which show the loop in code, engineering guides from model makers, and the original research papers on arXiv. Product demonstrations show successful runs; documentation on limits and failure handling says more about everyday use.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.