Tools and function calling
The model doesn't "run Python": it emits a special token the harness reads as a request, and runs it.
A tool is a function you make available to the model, and function calling is how the model asks for it: it never runs the function itself, but emits a structured request that your code reads, runs, and answers. This lesson covers what that request physically is and how it travels through the loop.
What a tool is: a described function the model can request
A tool is an ordinary function in your own code that you make available to the model by describing it three ways: a name, a short description in plain language of what it does, and a schema listing its arguments and their types. The model is given these descriptions alongside the conversation, but never the function's body and never the ability to run it. It works out which tool fits the task and what arguments to pass from the description alone, which makes that description the whole of the interface between the model and the code behind it.
Read
What a tool call is: special tokens the harness parses
When the model decides to use a tool it does not execute anything. It emits a run of special tokens: one that means "interpret what follows as a tool call", then a JSON object naming the tool and the arguments to call it with, then a closing token. These tokens are not ordinary text, and the model can produce them only because it was trained to, on synthetic examples of tool use — they are, in Cloudflare's phrase, things it has "never seen in the wild". The harness recognises the tokens, parses out the name and arguments, and runs the real function, so the familiar phrase "the model runs Python" is misleading: the model only ever produces tokens, and the code around it does the running.
Read
The round trip through the loop
Function calling is not separate machinery from the loop in lesson 2; it is what the loop's "run any tool it asks for" step is made of. One pass goes like this: your code sends the conversation together with the list of tool definitions; the model replies with a tool-call request and a stop_reason of tool_use; your code runs the named function and appends its result to the conversation as a tool-result message; then the whole conversation is sent again so the model can read the result and carry on. The model decides what happens, but every action happens in your code between one request and the next.
Read
Tool descriptions: the model's only view of a tool
The model chooses which tool to call and fills in its arguments from the name, description, and schema alone, because it has no other view of what the tool does. A description that is vague or a schema that is loose leaves the model to guess, so it picks the wrong tool or passes arguments the function rejects; a precise description and a tight schema make the right call the likely one. This is why designing tools is a real part of building an agent rather than an afterthought, and it is the subject of lesson 9 on agent–computer interfaces.
Read
My notes
- LLMs generate special tokens to request a tool use, where they give the name of the tool and their parameters. They also consume special tokens to get the tool definitions. These tokens are not seen in normal-text training phase, they need to be later added to training data or included during a finetuning step.
- Tool definitions can also undergo prompt engineering. The choice and definition of tools is something that needs to be calibrated and evaluated carefully depending on the tasks the LLM needs to carry out.
Build — write the agent
Tiny Agent v0.2 changes how the agent's tools are wired, not what the agent does. In v0 each tool was described and dispatched in three separate places: a JSON schema sent to the model, an if/else chain that routed a call to the right function, and the function itself. v0.2 replaces the first two with one abstraction. A Tool is a small object that holds a tool's three descriptions — its name, a sentence saying what it does, and a schema listing its arguments — together with the function that runs it. A Registry holds a set of Tools and does two things: it hands the model every tool's schema, and it takes a tool call from the model, finds the named Tool, checks the arguments against the schema, runs the function, and returns the result. You write the Tool and the Registry; the loop and the three tool bodies are carried forward from v0 and provided.
Provided for you — don’t edit these
agent/v0_2/loop.py— the lesson-2 loop, unchanged. A failed tool call is already recorded as an error result, which is what lets invalid arguments be reported back to the model without changing the loop.agent/v0_2/tools.py— the three tool bodies (list_files,read_file,edit_file), carried forward from v0.agent/v0_2/__main__.py— the runner. It builds the registry, binding the fixture repo to each tool body, and hands the registry's schemas and dispatch to the loop.
To do
agent/v0_2/registry.py— theToolobject and theRegistry. Dispatch is a short sequence: find the tool by name, validate the call's arguments against its schema withjsonschema, run the function, and return the result. The full recipe is in the file's docstrings.
Run it
uv run --env-file .env python -m agent.v0_2When you run it, the agent fixes the same misspelled greeting as in lesson 2, and the trace is saved to src/content/traces/04-tools.json; the interactive demo below reads that file once it exists. The behaviour is identical to v0's, because the registry is a refactor and not a new capability: the same run, now produced from one tool definition instead of three scattered edits.
The greeting printed by this package is misspelled. Find the file it lives in, fix the spelling, and tell me what you changed.
Measure — tool descriptions
Question. Do careful tool names, descriptions, and schemas make a model pick the right tool and pass valid arguments more often than vague ones — and does a weaker model lean on them more?
- Hypothesis
- The model chooses a tool and fills in its arguments from the name, description, and schema alone, so clearer ones should raise both the share of tasks where it picks the intended tool and the share where the arguments it passes are valid. A smaller model has less room to infer intent from a thin description, so the gain should be larger for it.
- Variants
- Tool set — vague (opaque names like `tool_a`, a thin phrase each, loose schemas) vs. careful (clear names, a precise sentence each, tight schemas)
- Model — a strong one (`claude-opus-5`) and a much smaller one (`claude-haiku-4-5`)
- Held constant
- the same six tools under both sets of descriptions
- the same tasks, each with a known correct tool and arguments
- one forced tool call per task, scored on the model's first choice
- Metric
- the share of tasks where the model selects the correct tool, and the share where the arguments it passes satisfy that tool's schema
To do
- Write the experiment in
experiments/tool-descriptions/: for each model, run each task under both tool sets and record how often the correct tool was chosen and the arguments were valid. - Grow the task set in
tasks.pyto around 30, then run it with your key and commit the numbers toexperiments/tool-descriptions/results.json, which the chart below reads.
What I learned
Using detailed tool descriptions helped the LLM mostly with getting the right arguments complying to the schema of the tool. Selecting the right tool was not as impacted by tool descriptions. Using a more powerful model did not have any effect on the results.