What this thread does
Do first: Install the Python SDK with pip install ollama -U.
When you need it
Tool calling lets a model request a function and incorporate its result into a reply. This follows the page’s single-tool Python example using fixed temperature data.
Steps
1. Install the SDK.
pip install ollama -U
2. Import chat and define the page's temperature lookup. The example returns fixed values rather than contacting a weather service.
from ollama import chat
def get_temperature(city: str) -> str:
temperatures = {
"New York": "22°C",
"London": "15°C",
"Tokyo": "18°C",
}
return temperatures.get(city, "Unknown")
3. Send the user message with the function in tools, then retain the assistant message.
messages = [{"role": "user", "content": "What is the temperature in New York?"}]
response = chat(model="qwen3", messages=messages, tools=[get_temperature], think=True)
messages.append(response.message)
4. If a tool call is present, execute it, append the tool result and request the final reply.
if response.message.tool_calls:
call = response.message.tool_calls[0]
result = get_temperature(**call.function.arguments)
messages.append({"role": "tool", "tool_name": call.function.name, "content": str(result)})
final_response = chat(model="qwen3", messages=messages, tools=[get_temperature], think=True)
print(final_response.message.content)
Check it worked
The page prints final_response.message.content after the follow-up request. It does not prescribe an exact final sentence.
Limits
The page recommends this first-call-only handling only for models that return a single tool call. It shows separate patterns for parallel calls and streaming. The example model is qwen3; the page does not name a version for this procedure.
Not for: schema-constrained responses; see ollama-constrain-local-responses-with-schema.
Sources
- Tool calling, Ollama documentation, read 2026-11-24: "Invoke a single tool and include its response in a follow-up request."
Checked
2026-11-24; read <https://docs.ollama.com/capabilities/tool-calling.md#calling-a-single-tool>; no command was run.
Started from a post by @Ollama, packaged by the editor. Original post