Tech Blog · AI Agents
[AI Agent Basics 4] How did AI come to use tools?
AI seems to query databases, but what actually runs the query is the program wrapped around the AI. We explain how tool calling works, and why lookup tools and setting-change tools need different designs.
Jun 23, 2026 · OPTI-X
Basics series “How AI Agents Are Built” · Part 4
A language model only knows what it knew when training ended, and it often gets calculations wrong. Tool calling (also called function calling) emerged to get past these limits.
Consider the question "What was the average temperature on Line 3 yesterday?" The model's memory has no data from yesterday. To answer, it has to look up the history data and calculate the average.
The model only writes a "request form"
Here is the key point: the model does not run tools itself. It only outputs, as text, a request in a fixed format saying "please call this tool with these values." The actual execution is done by the program wrapped around the model.
The round trip of a tool call
The authority to execute lies with the program, not the model
- 1User question'What was the average temperature on Line 3 yesterday?'Passed to the model
- 2The model writes a call requestOutputs the tool name (history lookup) and arguments (Line 3, yesterday, temperature) in a fixed formatFormat and permission checks pass → executeNo permission → rejected
- 3The program runs it and returns the resultThe lookup result is fed back to the model, which then writes the answerAnswer based on the result
OpenAI's official documentation describes this process in five steps. When the program sends the question along with the list of tools it can use, the model returns a call request containing a tool name and arguments. When the program runs the tool and sends the result back, the model either writes the final answer or requests another tool.
For each tool, the list contains a name, a description and an input format (which arguments it takes, in what format). The model reads these descriptions and decides which tool to call with which values.
How did the model learn to use tools?
The Toolformer study, published in 2023, had a model teach itself how to use tools. It gave only a few human-written usage examples per tool and had the model try inserting tool calls between the sentences of ordinary text. The calls were actually executed, and only those whose results made the following text easier to predict were kept and used to train the model again.
The tools were a calculator, a question-answering system, search engines, a translator and a calendar, and the base model was GPT-J with 6.7 billion parameters. The effect was clearest on math word problems.
Accuracy on math word problems (ASDiv)
A 6.7B model that learned to use a calculator beats a 175B model · solved without examples
On the math tasks, Toolformer called the calculator on its own for 97.9% of the problems. The paper also states its limits. It could not feed one tool's result into another tool, and small changes in the wording of a question changed whether it called a tool at all. In today's commercial services, the tool list and descriptions are sent with every request, and the model reads them to decide on calls.
Tool descriptions set the quality of calls
Using tools changes the basis of the answer. But it also changes the shape of the risk. Instead of made-up figures, the model can cause a wrong execution with wrong arguments.
Answering without tools vs. using tools
Same question, different evidence
The tool definition principles that OpenAI's documentation recommends aim to reduce this risk. State the tool's purpose, the meaning and format of each argument, and what the result represents. If the allowed values are fixed, restrict them to a list (enum) so that invalid calls cannot be formed at all. Values that are already known are filled in by code rather than by the model, and the documentation gives a soft recommendation of fewer than 20 tools available at the start.
Turning on strict mode makes call requests follow the defined format reliably rather than on a best-effort basis, and the documentation recommends always enabling it. But a correct format does not mean a correct value. The format guarantees that a number arrived in the dosing field, but whether that number is within the allowed limits is something the program must check separately.
For a process history lookup tool, this means letting the model pick tag names only from the actual tag list, and writing the time range format and units (℃, mg/L, etc.) into the description. The check the documentation offers is: "Could an intern use this tool correctly given only the description you gave the model?"
Tools of different weight
A history lookup that goes wrong can simply be run again. A tool that changes the chemical dosing or reactor temperature setpoint is different. If one argument is wrong, it goes straight into the process, and its effect on product and equipment remains until it is reversed.
Filling in arguments incorrectly is not the only problem. Research on indirect prompt injection showed, on real services, that instructions hidden in documents and web pages the model reads can steer which tools it calls, and even whether it calls them. Text that comes in as a lookup result can also read to the model like an instruction.
Principles for designing tools
Enforced on the tool side, not by the model
That is why it is safer to build a tool that changes setpoints as a "change request" rather than a "change execution." The model only writes the request form, and the program and people handle the limit checks and approval.
In tool calling, the authority to execute lies with the program, not the model, and safety is enforced in that program too. When a model that can use tools calls them on its own, again and again, until the job is done, that is an agent. In the next part, we look at the agent loop.
References
- NeurIPS 2023 (Schick et al.), "Toolformer: Language Models Can Teach Themselves to Use Tools" (2023-02-09) ↗
- OpenAI API documentation, "Function calling" ↗
- AISec 2023 (Greshake et al.), "Not what you've signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection" (2023-02-23) ↗
Could this work for your process?
Talk to us