Agent Engineering

Tool-Use Loop

Also known as: agent loop, ReAct loop, function calling loop

Definition

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

Go deeper