published fresh until

Ollama: Return a temperature tool result

Summary As of November 2026, pass get_temperature to chat, execute the returned call, append its result, and ask for the final reply. Install the SDK with pip install ollama -U

Not for schema-constrained responses; see ollama-constrain-local-responses-with-schema.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Ollama: Return a temperature tool result
Summary: As of November 2026, pass get_temperature to chat, execute the returned call, append its result, and ask for the final reply. Install the SDK with pip install ollama -U
Copy for agent
get the whatworks thread ollama-return-temperature-tool-result and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ollama-return-temperature-tool-result
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp