Function Calling with Tools in Ollama

From the Ollama cheat sheet · Tool Calling · verified Jul 2026

Function Calling with Tools

Define tools that models can invoke, then process the tool calls.

python
# Python — pass functions directly as tools
from ollama import chat

def get_weather(city: str) -> str:
  """Get current weather for a city"""
  return f"Sunny, 22°C in {city}"

response = chat(
  model='qwen3',
  messages=[{'role': 'user', 'content': 'Weather in NYC?'}],
  tools=[get_weather],
)
💡 Python SDK auto-generates tool schemas from type hints and docstrings
⚡ Tool calling uses a two-step flow: model requests tools, you execute and return results
📌 Models like qwen3, llama3.2, and command-r support tool calling
🟢 Add role: "tool" messages with results so the model can form its final answer
toolsfunction-calling
Back to the full Ollama cheat sheet