85 agentic tools audited for security incidents · Talk to the lab →
MotionticBook a call
Glossary

What is an agent loop?

An agent loop is the repeating cycle in which a model picks an action, a tool runs it and the result goes back to the model, until the model gives a final answer or a stop condition fires.

Every AI agent, however it is described on a product page, runs some version of the same cycle. The model reads the task and its context and decides whether to call a tool. The surrounding code runs that tool and appends the result to the conversation. Then the model is called again, and the cycle repeats until the model answers without asking for a tool.

Anthropic's "Building effective agents" (December 2024) describes agents as models using tools based on environmental feedback in a loop, and stresses that the agent needs ground truth from the environment, such as a tool result or code output, at every step. The loop itself is a few lines of code. Most of the engineering goes into what surrounds it, which is the agent harness.

One turn of the loop

  • Build the context

    The harness assembles the system prompt, tool definitions, conversation so far and any retrieved data into the next request.

  • Call the model

    The model returns either a final answer or one or more structured tool calls, each naming a tool and its arguments.

  • Run the tools

    Application code, or the provider's servers for hosted tools, executes each call. The model never runs anything itself.

  • Return the results

    Each tool's output is added to the conversation as a tool result, so the next model call can see what happened.

  • Check for a stop

    In Anthropic's Messages API the loop continues while the stop reason is tool_use and exits on any other reason, such as end_turn or max_tokens. Most harnesses add their own limits on top.

Where agent loops go wrong

  • Context fills up

    Every tool result adds tokens. Long runs need compaction, context editing or results that are summarised before they enter the window.

  • Runaway iterations

    A loop with no cap can keep calling tools on a task it cannot finish. Anthropic recommends stopping conditions such as a maximum number of iterations.

  • Early stops

    The model declares the task done before it is. A checklist that starts with every item marked failing, and a check the agent must pass, guards against this.

  • Derailment

    Google's post on ADK 2.0 (July 2026) notes that model loops used for routing and error handling are slow, costly and variable, and tend to skip steps as context grows.

Loop or fixed path

An agent loop earns its cost when the number of steps cannot be known in advance. When the steps are predictable, a workflow with the path fixed in code is cheaper and easier to test. The workflow versus agent comparison covers that choice in detail.

Anthropic's guide to the Claude Agent SDK frames the loop in four verbs: gather context, take action, verify the work, repeat. The verification step is the one most often left out, and the one that decides whether the loop ends with correct work or just with work.

How Motiontic's engineers apply it

Motiontic's engineers keep the loop itself plain and put the effort into its edges: a cap on iterations and spend per run, a log of every turn that can be replayed, terse tool output, and a check the agent runs on its own work before it is allowed to stop.

Each of those limits is set from eval runs on the client's real tasks rather than guessed, and revisited when the model changes.

An agent loop compared with a single model call

An agent loop compared with a single model call
Single model callAgent loop
Who decides the next stepThe calling codeThe model, one step at a time
Model calls per taskOneAs many as the task needs, up to a cap
Access to live dataOnly what is in the promptWhatever the tools can fetch
Cost and latencyLow and predictableHigher and variable
Typical failureA wrong answerLooping, stopping early or drifting off task

Common questions

What is an agent loop in AI?

An agent loop is the cycle at the core of an AI agent: the model chooses an action, a tool runs it, the result is fed back, and the model chooses again, until it returns a final answer or hits a limit.

When does an agent loop stop?

It stops when the model replies without requesting a tool, or when the harness hits a limit such as a maximum number of iterations, a token budget or a time limit. Production agents usually need both kinds of stop.

Is an agent loop the same as a ReAct agent?

ReAct is one well-known way to run the loop, with the model writing a reasoning step before each action. Modern tool-calling APIs run the same cycle with structured tool calls instead of parsed text.

How many iterations should an agent loop allow?

There is no universal number. The cap should come from eval runs on real tasks: high enough that successful runs finish, low enough that a stuck run stops before it wastes much time or money.

Running agents that have to hold up?

Describe the agent, the systems it touches and what it must never get wrong. The first call is with a lab engineer, who will say plainly whether it is ready for production, and whether Motiontic is the right team.