Ollama Tool Calling, Explained: Let a Local Model Use Your Functions
Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.
How we wrote this: A summary of Ollama's official Tool calling documentation (linked below), checked October 29, 2026. Examples follow the docs; tool support depends on the model, so check the model's page before you rely on it.
A model on its own can only produce text. Tool calling (also called function calling) lets it ask your program to run something, such as looking up a temperature, searching a database or reading a file, and then use the result in its answer. Ollama's Tool calling documentation describes it as a way to let a model "invoke tools and incorporate their results into its replies."
The important part to understand first: the model never runs your code. It returns a request ("call get_temperature with city = New York"). Your program decides whether to run it, runs it, and sends the result back.
Pick a model that supports tools
Only some models are trained for this. Ollama's model library has a tools filter. The docs' examples use qwen3. If you haven't installed Ollama yet, our beginner walkthrough covers it.
How one tool call works
The flow takes two requests to /api/chat.
1. Describe your tool and ask the question. Each tool is described with a name, a description and a JSON schema for its parameters:
"tools": [{
"type": "function",
"function": {
"name": "get_temperature",
"description": "Get the current temperature for a city",
"parameters": {
"type": "object",
"required": ["city"],
"properties": {
"city": {"type": "string", "description": "The name of the city"}
}
}
}
}]
2. Read the model's tool call. Instead of a normal answer, the assistant message comes back with tool_calls, naming the function and its arguments (for example, {"city": "New York"}).
3. Run the tool yourself and send the result back. Add the assistant's message and a new message with role tool, the tool_name, and the result as content (the docs' example uses "22°C"). Then call /api/chat again with the full message list. The model now writes its final reply using that result.
With the official Python library, the docs show a shortcut: you can pass a normal Python function in the tools list, and the library builds the schema from its signature and docstring.
Parallel calls and the agent loop
The docs cover two patterns beyond a single call:
- Parallel tool calling: the model can request several tool calls in one turn. Run them all, then send every result back before asking for the final answer.
- Multi-turn tool calling (an "agent loop"): keep calling the model, running any tools it asks for and appending results, until it replies without tool calls. The docs note it "might help to tell the model that it is in a loop and can make multiple tool calls."
If you stream responses, the docs say to gather every chunk of thinking, content and tool_calls, then pass those fields back together with the tool results in the follow-up request.
Safety rules before you connect real tools
Tool calling becomes risky the moment a tool can change something: send an email, delete a file, move money or call another service. Practical rules:
- Start read-only. Lookups and searches first. Add tools that write or send only when you trust the setup.
- Validate every argument. The model's arguments are untrusted input. Check types, ranges and allowed values before running anything, exactly as you would for a web form.
- Confirm destructive actions with a person. Show the proposed call and require a click or keypress.
- Limit the loop. Cap how many tool calls one request can make, so a confused model can't loop forever.
- Keep the API private. Ollama binds to 127.0.0.1 by default, per its FAQ. Our local API guide explains what changes if you expose it.
- Log calls. Record which tool ran with which arguments, so you can see what happened.
When to use structured outputs instead
If you only need the model to return data in a fixed shape (for example, fields pulled from an email), you may not need tools at all. Structured outputs constrain the reply to a JSON schema without any back-and-forth.