Ollama tool calling works by sending a tools list with your /api/chat request: a model that supports tools replies with tool_calls (function name plus arguments) instead of text, you run the function yourself and send the result back with the tool role. The model never runs anything on its own.
We tried the whole thing on 20 November 2026 with Ollama 0.40.16, the latest stable release that day: the official Linux binary, no GPU, a tiny qwen3:0.6b that supports tools and a gemma3:270m that doesn’t. Every reply on this page is the server’s real output (formatted with jq in the screenshots), including the moments the model let us down. On 24 November 2026 we repeated the tests with Ollama 0.40.17 (released 10 November) on the same machine: the API answers with the same structure and the same errors (the model’s wording varies from run to run, and in the Madrid-and-Paris test it made 1 call instead of 2); what’s new, a 20-run thinking test and the schema keywords that 0.40.17 no longer drops, is further down.
OllamaRuntime sheet
How tool calling works in Ollama: tools in, tool_calls out
You describe each function with a name, a description and a JSON schema for its parameters. This is the request we sent, with a single made-up weather function:
curl -s http://localhost:11434/api/chat -d '{
"model": "qwen3:0.6b",
"think": false,
"stream": false,
"options": {"temperature": 0},
"messages": [{"role": "user", "content": "What is the temperature in Madrid?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_temperature",
"description": "Get the current temperature for a city",
"parameters": {
"type": "object",
"required": ["city"],
"properties": {"city": {"type": "string"}}
}
}
}]
}'
Ollama 0.40.16 didn’t answer with a sentence. It answered with an empty content and a tool_calls list: the function it wants, the arguments already as a JSON object and an id of the form call_….

get_temperature with {"city": "Madrid"} and writes no text at all Output of our test, Ollama 0.40.16, 20 Nov 2026That’s the whole trick, and also the most common misunderstanding: the model only writes the order. Nothing has checked the weather in Madrid yet. Your code reads tool_calls, decides whether to run the function and runs it. If you ask it something that needs no tool (“Write one sentence about the sea.”), with the same tools list, qwen3:0.6b answered in plain text and called nothing. The official Ollama extension for VS Code relies on the same thing: Agent mode only uses tools with models that report the tools capability, as our Ollama in VS Code guide explains.
Not everything in your schema reaches the model, and here the version matters. On 24 November 2026 we sent the same tool adding one JSON schema keyword at a time and counted prompt tokens with qwen3:0.6b. In 0.40.16 only enum added anything (9 tokens); default, minimum/maximum and pattern added 0, dropped without a warning. In 0.40.17 those three get through too: 5 tokens for default, 8 for minimum and maximum together, 10 for pattern. additionalProperties added nothing in either version. If a function depends on a range or a pattern, use 0.40.17 or later, and check the arguments in your code anyway: the model reads the limits, it doesn’t promise to respect them.
The full loop: send the result back with the tool role
Once your code has the result, the second request repeats the conversation and adds two messages: the assistant’s turn with its tool_calls, and a tool message with the result and the name of the function it came from (tool_name, as the v0.40.16 documentation does it):
"messages": [
{"role": "user", "content": "What is the temperature in Madrid?"},
{"role": "assistant", "content": "", "tool_calls": [
{"function": {"name": "get_temperature", "arguments": {"city": "Madrid"}}}]},
{"role": "tool", "tool_name": "get_temperature", "content": "14°C"}
]
We made up the 14°C, of course. The model doesn’t know that and doesn’t care: it takes what you give it as true.

In a real program this is a while loop: call, check whether there are tool_calls, run them, add the results, call again, and stop when the reply comes back without tools. When the tools come from an MCP server, this same loop is the bridge: we wrote it in 42 lines of Python in our Ollama MCP guide. On our machine (AMD Ryzen 7 7730U, CPU only) each round with qwen3:0.6b took less than half a second of generation: between 64 and 70 tokens per second over 4 runs, measured, 20 November 2026.
One honest note about small models. We asked for the weather conditions and the temperature in Madrid and Paris, with two functions available. The 0.6B model asked for get_conditions for both cities and forgot get_temperature. Ollama handles several calls in the same reply perfectly well (both arrived with index 0 and 1); choosing the right ones is the model’s job, and at 0.6B it has its limits.
Opens on YouTube (no cookies) only when you press play.
Almost 13 minutes building an agent that runs on your own machine, with web search and document retrieval as tools and a Llama 3 8B fine-tuned for tool use. It was published in July 2024, when Ollama had just added tool calling, so the request fields are worth checking against the ones above.
Which Ollama models support tool calling, and how to check
Not all of them. The quick check is ollama show <model>: in v0.40.16 it prints a Capabilities block, and if tools appears there, the model accepts the tools field. The API gives the same list in the capabilities field of /api/show. On ollama.com, the library labels them too: on 20 November 2026, qwen3, qwen2.5, llama3.2, granite4 and smollm2 carried the tools label, and gemma3 didn’t.

tools; gemma3:270m only completion, and the request fails Output of our test, Ollama 0.40.16, 20 Nov 2026If you’re picking a model for an agent, size matters as much as the label: the label says the model can call, not that it calls well, as our Madrid and Paris test showed. To see which ones fit in your memory, our Ollama commands guide shows how ollama ps tells you how much memory each one takes once loaded.
“does not support tools”: the error from a model without tool calling
This is what Ollama 0.40.16 returned when we sent the same request to gemma3:270m, with HTTP status 400 in 2 milliseconds, without generating anything:
{"error":"registry.ollama.ai/library/gemma3:270m does not support tools"}
Through /v1/chat/completions it’s the same message inside an OpenAI-style error, with "type":"invalid_request_error". There’s no trick to get past it: the model doesn’t declare the capability, and Ollama refuses before trying. You have two ways out: switch to a model with tools in its capabilities, or drop the tools field and ask for JSON with format, which gemma3:270m did accept (more on that below).
Thinking models: why qwen3 sometimes doesn’t call the tool
This one cost us a while. qwen3:0.6b comes with thinking on by default (ollama show says default true), and with the same question and the same tool, in 5 attempts on 20 November 2026 it called the function only once. The other 4 times it thought for between 406 and 649 characters, wrote “I should call this function”, and finished without calling it, with content empty. On 24 November we repeated it 20 times with different seeds, on 0.40.16 and on 0.40.17, same machine: 11 calls out of 20 on each version. With thinking on, this model skips the tool almost half the time, and the new version doesn’t change that.
If you do want the reasoning, it arrives in the thinking field, separate from content, and in the streaming loop of its example, the v0.40.16 documentation sends it back in the assistant’s message along with the tool_calls.
Ollama tool calling with streaming
With "stream": true you’d expect the call to arrive in pieces, the way text does. With v0.40.16 it didn’t: the tool_calls came complete in the first chunk, with "done": false, and then a final chunk with "done": true and the counters.

Even so, the documentation for that version gathers thinking, content and tool_calls from every chunk and sends them back together in the next request. We’d add one habit of our own: wait for done before running any function, because a reply can carry text and calls, or several calls.
Structured output in Ollama: format with a JSON schema
Sometimes you don’t want the model to call anything, you want it to answer with data in a fixed shape. That’s what the format field is for: "format": "json" asks for any valid JSON, and a JSON schema in format forces specific fields. It doesn’t need tool support: gemma3:270m, the one that rejected tools, filled in our schema without complaint.

Look at the last field. With the schema and the plain question “Tell me about Madrid.”, qwen3:0.6b gave the same absurd figure in all 5 runs. When we also named the fields in the prompt, close to what the v0.40.16 documentation suggests (it recommends adding the schema to the prompt as text), the value turned sensible in 2 of 3 runs (4.1) and came back as 3000000 in the third. The schema didn’t slow anything down: between 67 and 70 tokens per second with it and between 65 and 73 without format, same prompt, 3 runs each (measured, Ryzen 7 7730U, CPU).
Tool calling through the OpenAI-compatible API (/v1/chat/completions)
If your code already speaks OpenAI, point it at http://localhost:11434/v1 and the same tools list works. With v0.40.16 there are two differences worth knowing before you copy code from one API to the other:

arguments is a text string and finish_reason says tool_calls Output of our test, Ollama 0.40.16, 20 Nov 2026argumentschanges type: in/api/chatit’s a JSON object; in/v1/chat/completionsit’s a string you have to parse ("{\"city\":\"Madrid\"}"). The result goes back with"role": "tool"and the call’stool_call_id, and with it qwen3:0.6b answered “The temperature in Madrid is 14°C.” just as before.tool_choiceis not supported: the v0.40.16 documentation lists it as unsupported, and we checked: with"tool_choice": "none"the model called the tool anyway. If you need a reply without tools, leave the tools out of that request.
response_format with json_schema, the OpenAI way of asking for structured output, did work on v0.40.16 and returned clean JSON. The rest of the endpoints, ports and the Python client are in our Ollama API guide, and if you want to keep the model loaded between turns of the loop, OLLAMA_KEEP_ALIVE is covered in our Ollama environment variables guide.