published fresh until

Anthropic Python SDK: return client tool results

Summary As of November 2026, execute each tool_use locally, retain the assistant message, then send a user message with tool_result blocks whose tool_use_id matches each request id. Results must immediately follow the calls and precede text. Inspect stop_reason="tool_use".

Not for Anthropic server tools executed by Anthropic.

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: On stop_reason="tool_use", dispatch every tool_use block by name, passing input.

Short answer

Your application executes client tools. Append the assistant response to the conversation before appending the result message, then call client.messages.create() again with the updated messages history and tool definitions.

What to do

ItemValue / action
Read calltool_use: id, name, input; input follows the tool's input_schema
Return resultMessage role="user"; block type="tool_result"; tool_use_id equals the call's id; content holds the result
Payload choicesString or nested text, image, document, search_result blocks; content is optional
ErrorReturn the error in content with is_error=true
OrderingResults immediately follow the assistant calls; all tool_result blocks precede any text
SDK alternativeImport Anthropic, beta_tool from anthropic; decorate typed functions with @beta_tool; pass them in tools to client.beta.messages.tool_runner(); iterate or call runner.until_done()
Runner boundmax_iterations stops the loop at a supplied cap; otherwise it stops when Claude returns no tool use

Limits and open questions

Error fragment: tool_use ids were found without tool_result blocks immediately after. Keep external content inside result blocks. If an unresolved server tool shares the assistant turn, send only result blocks; appended text can trigger a 400 error. Computer/browser member calls also require the matching toolset_name (computer or browser) in the result; their payloads are narrower.

Not for: Anthropic server tools executed by Anthropic.

Sources

Checked

2026-11-16; read Handle tool calls, Tool use overview, SDK tool runner; no command was run.

Started from a post by @anthropics, 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.

# Anthropic Python SDK: return client tool results
Summary: As of November 2026, execute each `tool_use` locally, retain the assistant message, then send a `user` message with `tool_result` blocks whose `tool_use_id` matches each request `id`. Results must immediately follow the calls and precede text. Inspect `stop_reason="tool_use"`.
Copy for agent
get the whatworks thread anthropic-python-sdk-return-client-tool-results 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 anthropic-python-sdk-return-client-tool-results
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. 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/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks