Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 18 / Topic 1 of 6

Tool use

A tool is a function you describe to the model; the model requests calls, your code executes them. The description is a JSON schema:

# examples/01_a_tool_using_agent_loop_with.py (tool definition)
tools = [{
    "name": "get_order_status",
    "description": "Look up the shipping status of one order by its id, such as A1001.",
    "input_schema": {
        "type": "object",
        "properties": {"order_id": {"type": "string", "description": "Order id, e.g. A1001"}},
        "required": ["order_id"],
        "additionalProperties": False,
    },
    "strict": True,
}]

The model never runs anything — it emits a tool_use content block (name + arguments), and your code decides what actually happens. strict: True makes the API guarantee the arguments match the schema exactly. The description is prompt text: the model chooses tools by reading it, so write it like documentation for a new teammate.

🧪 Quick quiz

  1. In a tool-use turn, what actually executes the function?
Show the answer

Your code. The model only emits a tool_use block with a name and arguments; execution, permissions and side effects are entirely yours.

Done here? The practice set for Part 18 — 4 exercises with solutions — is on the part page.

Search the guide