AGENT LOOP

The repeated cycle of decide, act with a tool, observe the result, and decide again that makes an AI an agent.

Zero retention: everything you type stays in this browser. Verify it yourself in DevTools.
Plain-language definition

What Does Agent Loop Mean?

An agent loop is the repeating cycle that turns a language model into an agent. The program sends the model the goal and everything that has happened so far. The model replies either with a final answer or with a request to use a tool, such as reading a file, running a test or searching. The program runs that tool, adds the result to the conversation, and asks the model again. This continues until the model says it is finished, a step limit is hit, or a person stops it. The model itself does not run anything; the surrounding program does.

Why Does Agent Loop Matter?

Most of what makes coding agents useful, and most of what makes them go wrong, happens inside this loop. Each turn adds tool output to the context, so long loops get slow, expensive and confused. Knowing the loop exists helps you give agents a way to check their own work, such as a test command, so each pass through the loop moves toward a verified result instead of a guess.

What Does Agent Loop Look Like in Practice?

A coding agent asked to fix a failing test might loop like this: read the test file, run npm test, read the error, open the source file, edit one function, run npm test again, see it pass, and report back. That is roughly six turns of the loop. If the instructions file had not named the test command, the agent would spend extra turns guessing it.

What Do People Get Wrong About Agent Loop?

An agent is not a different kind of model. It is usually the same chat model wrapped in a program that runs tools and feeds the results back. The loop, the tools and the instructions are what make it agentic.

Which Terms Are Related?

  • Agentic workflow: A setup where an AI takes multiple steps on its own, using tools and checking results, rather than giving one reply.
  • Tool use: A model asking its application to run a defined function, such as search or run tests, and using the result.
  • Subagent: A helper agent that a main agent starts for one focused task, with its own separate context, returning a summary.
  • Context window: The maximum amount of text, measured in tokens, that a model can take into account in a single request.
  • Guardrail: A rule or check, in the instructions or in code, that keeps an AI system from doing what it should not.

All 28 terms are in the AI glossary. For models side by side, see frontier vs open-weight.

Frequently Asked Questions

When does an agent loop stop?

It stops when the model returns a final answer instead of a tool request, when the program hits a limit on steps, time or cost, or when a person interrupts it. Good agent setups always have some limit.

Why do long agent sessions get worse?

Every tool result is added to the context, so the context fills with old output. The model then has more to read, costs more per turn and can lose track of earlier details. Shorter tasks or subagents help.

Does the model run the commands itself?

No. The model only writes text that asks for a tool call. The agent program decides whether to run it, often asking a person for permission first, and then passes the result back.

Was this helpful?