The model writes, the app acts
Tool calling (also called function calling) is an agreement about format. The app describes its tools in the prompt: their name, what they do and which arguments they take, as JSON Schema. During fine-tuning the model has been trained to answer with a call in a fixed format when a tool fits, and otherwise with plain text. The app recognises the call, runs the function and sends the result back. The model never runs anything itself; it only writes text, and the app decides what actually happens.
It is just tokens
In Qwen2.5 the tools sit in the system message between <tools> and </tools>, and the model answers with JSON between <tool_call> and </tool_call>. Each of those two markers is a single token in the vocabulary (IDs 151657 and 151658), so the model can learn them as one signal. The result comes back in a user message between <tool_response> tags. Other models use other markers and other templates. With hosted APIs you typically send the tools as structured fields and get the calls back as structured data; the provider translates to and from the model’s own text format.
Because the descriptions sit in the prompt, they cost tokens in every request. In the demo, the three small tools take 357 tokens in the English weather question, far more than the question itself. Many tools make the prompt longer and can make it harder for the model to pick the right one.
Always validate the call
The model can write invalid JSON, invent a tool, forget an argument or give an argument in the wrong format. So the app must check the call against the description before running anything, and reject it or ask for a new attempt if it does not fit. Some systems use constrained decoding, where only tokens that keep the JSON valid for the schema can be chosen. That guarantees the format, but not that the content is right: a valid date can still be the wrong date.
From tool call to agent
An agent is essentially the same loop repeated: the model calls a tool, reads the result and decides the next step, until the task is done or a limit is reached. That makes multi-step tasks possible, but errors can pile up along the way, and every result that comes back is new text in the prompt. A tool result from a web page or an email can contain instructions the model wrongly follows: that is prompt injection. So give only the tools the task needs, and let a person approve actions that cannot be undone.
The Model Context Protocol (MCP), an open standard Anthropic introduced in 2024, describes tools in a common way so the same tool server can be used by different apps and models. Inside the model it still ends up as text in the prompt.
When there is no tool
Pick the question about 17 times 23: there is no calculator tool, so the model answers in text. Here the answer is right, but a language model calculates by predicting tokens, and with larger numbers it goes wrong more often. A calculator tool or running code is more reliable. Switch the weather tool off and pick the weather question: a good model says it cannot look it up instead of making up an answer.
See the chat template’s tokens yourself
In the free Tokenization lab you write a system and a user message and see them in Qwen2.5’s chat template with real token IDs, including the markers <|im_start|> and <|im_end|>. The AI safety lab goes further with evaluating language-model behaviour and requires full access.