Part 1 of 7 · 1 min read
Overview
In this module you will
- Describe a function so a model can decide to use it, with a JSON Schema generated from Pydantic.
- Run the complete loop: request, validate, execute, return the result, final answer.
- Turn every kind of bad tool request into an error message the model can read, instead of a crash.
- Explain why the model never runs anything itself, and why that matters for safety.
Tool calling is what turns a text generator into an agent. The model decides what to do. Your code decides whether to do it and how. Almost every agent bug in the first weeks lives on this boundary: a malformed argument, an unknown tool name, a tool that throws, a loop that never ends. This module builds the boundary carefully so later levels can trust it.
About the examples
ScriptedToolModel is an offline imitation that asks for tools by simple rules, so the loop can be tested without a key. Real providers use a similar shape (a reply that contains tool requests, then results sent back) but the field names differ. Some providers send results as a tool role message, others as a block inside a user message. Read your provider's reference. No real SDK was run.