Tool calling, also known as function calling, lets a model running in Ollama ask your own code to do something it can't do on its own, such as look up a value, run a calculation or query a database, and then use the result in its reply. The model never runs your function itself: it returns a structured request, your script runs the function, and you send the result back. This guide is based on Ollama's tool calling documentation. It hasn't been tested by us on specific hardware, and you'll need a model that supports tool calling, so check the model's page in the Ollama library before you start.
What you need
Ollama installed and running, listening on http://localhost:11434 by default.
A model that supports tool calling. Ollama's own examples use qwen3.
Optionally, the Ollama Python library (pip install ollama -U) or the JavaScript library (npm i ollama). See our guide to using Ollama with Python if you haven't set that up.
Tool calling uses the /api/chat endpoint. Alongside your messages, you send a tools list. Each tool has a type of function, a name, a plain-English description and a JSON schema for its parameters. In Ollama's example, a get_temperature tool takes one required string parameter, city.
The description matters: it's how the model decides whether your tool is relevant to the question.
If the model decides to use a tool, its reply message contains a tool_calls field instead of (or as well as) normal text. Each call names the function and gives the arguments as an object, for example get_temperature with {"city": "New York"}.
Step 3: Run the function and send the result back
Your code runs the real function with those arguments. You then make a second /api/chat request containing the whole conversation so far: the original user message, the assistant message with its tool_calls, and a new message with the role tool, a tool_name and the result as content (in Ollama's example, "22°C"). The model then writes its final answer using that result.
In the Python library you can pass ordinary Python functions straight into the tools list, or describe them as a JSON schema. Ollama's examples give each function a clear docstring describing what it does and its arguments, which is a good habit to copy.
Parallel calls and agent loops
Parallel tool calling: a model can request several tool calls in one reply, for example the weather in New York and in London. Run each one and send all the tool results back before asking for the final answer.
Multi-turn (agent loop): keep calling /api/chat in a loop, running any tools the model asks for, until it replies without a tool call. Ollama's docs note that it can help to tell the model that it is in a loop and can make multiple tool calls.
Streaming: if you stream responses, gather every chunk of thinking, content and tool_calls, then return those fields together with your tool results in the follow-up request.
Tips
Start with one simple tool and a clear description before building a bigger agent.
Validate the arguments the model sends before you act on them, especially for anything that writes files or changes data.
If you only need a reply in a fixed shape rather than an action, structured outputs may be simpler.
Our verdict
Tool calling in Ollama is a simple loop: describe your functions in a tools list on /api/chat, run whatever the model asks for, and send the results back as tool messages. Pick a model that supports tools, keep descriptions clear and check arguments before acting on them, and you can build useful local assistants without sending data to the cloud.