Tool-Use Loop
Also known as: agent loop, ReAct loop, function calling loop
The tool-use loop is the core agent pattern: the model receives a goal and tool definitions, chooses a tool call, the runtime executes it and returns the result into the context, and the model decides again — repeating until it produces a final answer or hits a stop condition.
Last reviewed · Part of the Architecture Glossary
In practice
Everything else in agent engineering is a variation on this loop, which is why it should be the first thing tried and the thing you have to justify moving beyond.
The stop conditions are the engineering. A loop with none of them is an incident waiting for a busy afternoon:
- Max iterations — a hard cap, typically 10-25.
- Token budget — cumulative across the loop, not per call.
- Wall-clock timeout.
- Repetition detection — the same tool with the same arguments twice usually means the model is stuck, and a third attempt will not help.
Tool design decides success rate more than prompt wording. Few tools, unambiguous names, descriptions written for a reader with no other context, and errors returned as usable text ("no customer with id 42; search by email with find_customer") rather than a stack trace the model cannot act on.
When it matters
Every agent. Start here and add structure only when a measured failure demands it — see multi-agent architecture is premature optimisation.
Common mistake
Exposing 40 tools because the API allows it. Selection accuracy falls as the tool count rises; grouping into a handful of coarse tools, or routing to a subset before the loop begins, recovers it.
See also
- Context WindowThe context window is the maximum number of tokens a model can attend to in one request — system prompt, conversation history, retrieved documents, tool definitions, tool results and the response combined.
- Eval HarnessAn eval harness is the automated test suite for a non-deterministic system: a fixed dataset of inputs, a scoring method per case, and a scoreboard run on every change.
- MCP (Model Context Protocol)The Model Context Protocol is an open standard for connecting AI applications to external tools, data and prompts through a uniform client/server interface.