Agent architecture

The tool-use loop

The tool-use loop is the core cycle an AI agent runs: the model decides on an action, a tool executes it, the result is fed back, and the model decides again — repeating until the task is done.

An LLM on its own only produces text. An agent wraps it in a loop: the model is given a goal and a set of tools, it emits a tool call, the harness runs that tool and appends the result to the conversation, and the model is invoked again with the new information. Each turn the model can call another tool, correct course, or stop and answer. This loop is what turns a text predictor into something that can search, read files, run code, and act on the world.

Key points

  • One iteration = model reasons → calls a tool → tool result is appended → model is called again with that result.
  • The loop ends when the model returns a final answer instead of another tool call, or a step or budget limit is hit.
  • The conversation (or a compacted form of it) is the agent’s working state carried between turns.
  • Good loops add guards: step limits, error handling, and verification so a wrong tool result does not derail the whole run.

Learn it by building

Way of the Agent teaches AI agent engineering level by level — concepts like this one, then hands-on practice, XP, and the AI Chronicles.

Start learning free →