BuildSpark AI

Map · Agents · 01 · Agent loop

Concept card · Agents

Agent loop

An agent loop is the cycle an AI agent repeats: a model step, a tool result, and another model step, until a stop.

A cycle of model step, tool result, and another model step, until a stop.

Last checked 2026-10-18 Free card 4 min

Ask about Agent loop

What changed

Oct 18: First card. The picture steps through one model request, one tool result, and a stop. The definition names this cycle as what an AI agent repeats. Sources are OpenAI's running-agents guide, Anthropic's tool-use guide, and Gemini's function calling guide.

1 What it is

An AI agent repeats a model step until a stop. OpenAI's running-agents guide says one run calls the model, executes any tool calls and continues, and returns a result when the model produced a final answer with no more tool work. Anthropic's tool-use guide says your application drives that loop for client tools: the model asks, you execute, you send the result back, and you repeat while the stop reason is tool use. Gemini's function calling guide says the same handoff can repeat over multiple turns, and that the model does not execute the function itself.

Illustration. It simplifies a real loop to one lookup, one result, and one stop. The steps are written for this picture. They are not a live model, and the tool is not running.

1 · ModelAsk for the warehouse close time.

2 · Tool resultNot sent yet.

3 · ModelWaiting.

The picture is on the first model step. No tool has run, and nothing has stopped the loop.

2 Why it matters

Cost

Each continuation is another model request. Anthropic's tool-use guide says every client tool call is at least one extra round trip, and that this overhead can exceed the work on a lightweight task. OpenAI's running-agents guide lists a max-turn limit among the failures that stop a run. This card does not add a price.

Quality

The next model step can use a tool result only after you send that result back. OpenAI's guide says to return a result when the model produced a final answer with no more tool work. Anthropic lists max tokens as a stop reason. A stop for that reason is not the same as a finished answer.

Risk

A loop with no stop keeps sending requests. Anthropic's server-side tool loop has an iteration limit and can pause instead of finishing. A tool result is text the next model step will read, including text you did not write.

3 How to apply · try today

Pick one task that needs one lookup. Write the stop you will accept: a final answer, or a turn limit. Run it once and read the tool result before you read the final sentence.

Common mistake

Treating the first model reply as the finished task when that reply is a tool request. Anthropic's guide says a tool-use stop means you still have to execute the tool and send the result back.

Self-check

The model reply asks for a tool and does not answer the user. What is that reply?

Questions

What is an agent loop?
An agent loop is the cycle an AI agent repeats: a model step, a tool result, and another model step, until a stop.
Does the model run the tool?
No. Gemini's function calling guide says the model does not execute the function itself. Your application runs it and sends the result back.
Is the first model reply always the stop?
No. A reply that asks for a tool is a step that is waiting for a result. Anthropic's guide says a tool-use stop means you still execute the tool and send the result back.