Free lesson · Module: Agent Foundations

The Tool Loop

A tool = name + description + schema

A tool is described by three fields. A name: get_weather. A description: what it does and when to use it. A JSON Schema: what data it needs, such as a city and a date. The model itself runs nothing. It writes a tool call: “get_weather, London, tomorrow.” Your program runs it and returns the result as text.

Request and result: tool_use and tool_result

The model’s request arrives as a tool_use block with the tool’s name and input. The stop_reason field is also tool_use: the model is waiting. Your program runs the tool and adds two messages to the history: the model’s reply and a tool_result block. The model reads the result and decides: ask again or answer. This is the loop from “What Is an Agent,” now for real.

More on Way of the Agent

Still in this lesson: 4 more cards, a quiz of 5 questions, XP and stars - in the course.

Continue the lesson on the Path