New Tool Radar

Local AI

How to Let a Local Ollama Model Call a Tool It Can Use

Give a local model one tool description in the tools field, read the tool_calls reply it returns, and run the function yourself.

Schematic diagram with three steps: describe the get_current_weather tool, read the tool_calls reply naming Toronto, then run the function and send the result back as a tool message.

A language model on its own can only answer from what it already knows. Tool calling changes that: you describe a function the model may use, and the model decides when to call it. Ollama’s tool support post says Ollama supports tool calling with popular models such as Llama 3.1, and that to enable it you provide a list of available tools via the tools field in Ollama’s API. The model never runs your code: it returns a tool_calls reply naming the function and its arguments, your program runs the function, and you send the result back as a message with the tool role.

Describe one tool and ask a question that needs it

The example below is the one from Ollama’s own tool support post, in Python. It gives the model llama3.1 a single tool, get_current_weather, which takes a city name, and asks “What is the weather in Toronto?”

import ollama
response = ollama.chat(
    model='llama3.1',
    messages=[{'role': 'user', 'content': 'What is the weather in Toronto?'}],
    tools=[{
        'type': 'function',
        'function': {
            'name': 'get_current_weather',
            'description': 'Get the current weather for a city',
            'parameters': {
                'type': 'object',
                'properties': {
                    'city': {'type': 'string', 'description': 'The name of the city'}
                },
                'required': ['city'],
            }
        }
    }],
)
print(response['message']['tool_calls'])

Try it: check the tool call, then close the loop

Run the script above, then check the reply field by field. The model does not fetch the weather; it only asks for the tool to be called.

Check What you should see
1. A tool call came back response['message']['tool_calls'] is not empty
2. The right tool was picked The call names get_current_weather, the only tool you offered
3. The right argument was picked The arguments name the city Toronto, from your question
4. Close the loop Run your own weather function, then send its result back as a message with role tool; the model then answers the question in words. For practice, supply a made-up result yourself, such as “sunny, 18 degrees”, and check the final answer repeats it

Expected result. We checked Ollama’s tool support post and the JavaScript library README’s tools field. We did not run a model or a tool on this machine.

Limits

Only models trained for tool use can do this: Ollama’s post lists Llama 3.1, Mistral Nemo, Firefunction v2 and Command-R+ under the Tools category on the models page, and a model without tool support will not return a usable tool_calls reply. The model also only chooses among the tools you describe; it cannot call anything else, and whatever the tool does — reading a file, calling an API, running a calculation — is your program’s responsibility, including its safety. Ollama’s OpenAI-compatible endpoint at http://localhost:11434/v1 supports tools too, so the same pattern works with OpenAI-style client code. We did not test any of this ourselves.

Sources

See all