New Tool Radar

AI Agents & Automation

How to Call Tools From a Local Ollama Model Through the Chat API

Send a tools list with an Ollama chat API request so a local model can call a function and use the result in its reply.

Schematic diagram with three steps: Start Ollama locally, Send tools with the request, then Read the tool call.

A local model behind the Ollama chat API can call tools the same way a hosted model does: the request carries a tools list, the model replies with a tool call, the app runs the function, and the result goes back to the model. The model, the tools and the data all stay on your machine.

Before you start

You need Ollama running locally with a model that supports tool calling, and one small function to expose, for example a calculator that adds two numbers. Test the function on its own first: the model can only call what works.

Send the chat request with a tools list

Send a chat request to the local Ollama API with the model name, the user message, and a tools list describing the function: its name, its description and its parameters. Keep the description to one sentence stating exactly what the function does, because the model only reads that when it decides to call it.

Run the called function and send the result back

When the model reply contains a tool call, run the function with the arguments the model chose and send the result back to the model in a follow-up request. Check the final reply quotes the function result. If the model never calls the tool, the description is too vague about when it applies.

Worked example: A calculator tool for a fictional invoices desk

Maple Invoices is a fictional billing desk. Its local Ollama model adds invoice totals with a calculator tool. The table shows three calls.

Question Tool call Result
Add 48 and 36 calculator, 48 and 36 84
Add 120 and 24 calculator, 120 and 24 144
Add 250 and 37 calculator, 250 and 37 287

Expected result (UNTESTED): each question produces one tool call and a reply quoting the computed total. We checked the Ollama and local-agent documentation summaries, which describe tool calling through the chat API, but we did not run the calls on this machine.

Limits

A local model can only call tools the app runs, so validate the arguments inside the function and never let it run a command from raw model text. Small local models call tools less reliably than large hosted ones, so keep the tool list short and the descriptions exact.

Sources

See all