chapter thirteen
13 Tool Use & Function Calling
This chapter covers
- How models are trained to use tools
- Why tools mitigate structure weaknesses of language models
- What to consider when giving your model tools
Language models using tools is a natural way to expand their capabilities, especially for high-precision tasks where external tools contain the information or for agents that need to interact with complex web systems. Tool-use is a skill that language models need to be trained to have, where RLHF and all the other methods presented in this book can refine it. Consider a question from a user such as:
A language model without tools will have a hard time answering this question due to the knowledge cutoff of pretraining data, but this is readily accessible information with one search query.
Before diving deeper, it is useful to distinguish related terms that are often used interchangeably:
- Tool use: the model emits a structured request (tool name and arguments); an orchestrator executes the tool; results are appended to the context; the model continues generating.
- Function calling: tool use where the arguments must conform to a declared schema for a set of functions (usually JSON Schema), enabling reliable parsing and validation.
- Code execution: a special case of tool use where the “tool” is a code interpreter (e.g., Python); results are returned as tool output.