Tool calling lets an Ollama model request a function call instead of guessing information it does not have. The application executes the requested tool, appends the tool result to the conversation, and asks the model for the final answer.
A tool definition is a JSON schema for function arguments. The first model response may contain tool_calls with no final content, which is the signal for application code to run the tool and continue the chat.
Use a small deterministic tool while validating the message flow. Once the request and response shapes are correct, replace the stub with the real service lookup or calculation.
$ curl -s http://localhost:11434/api/chat -d '{ "model":"gpt-oss:20b", "messages":[{"role":"user","content":"What is the temperature in Paris?"}], "stream":false, "tools":[{"type":"function","function":{"name":"get_temperature","description":"Get the current temperature for a city","parameters":{"type":"object","required":["city"],"properties":{"city":{"type":"string"}}}}}] }' {"message":{"content":"","tool_calls":[{"function":{"name":"get_temperature","arguments":{"city":"Paris"}}}]},"done":true}
$ python3 - <<'PY' def get_temperature(city): return {'city': city, 'temperature': '22 C'} print(get_temperature('Paris')) PY {'city': 'Paris', 'temperature': '22 C'}
$ curl -s http://localhost:11434/api/chat -d '{ "model":"gpt-oss:20b", "messages":[ {"role":"user","content":"What is the temperature in Paris?"}, {"role":"assistant","tool_calls":[{"type":"function","function":{"name":"get_temperature","arguments":{"city":"Paris"}}}]}, {"role":"tool","tool_name":"get_temperature","content":"22 C"} ], "stream":false }' {"message":{"content":"The temperature in Paris is 22 C."},"done":true}
$ python3 - <<'PY'
allowed = {'get_temperature'}
print('delete_file' in allowed)
PY
False
$ printf '%s\n' 'tool=get_temperature city=Paris' tool=get_temperature city=Paris