Repository navigation
Python: Keep pending Anthropic server tool calls as server_tool_use - #9513
Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
Conversation
When Claude calls a local tool and a server tool (such as web search) in parallel, the response ends with a pending server_tool_use. The hosted call was sent back as a plain tool_use, so Anthropic expected a local tool_result for it and rejected the next request with HTTP 400. Hosted calls that have no result in the conversation are now sent back as server_tool_use, so the API runs the server tool on the next request. Fixes microsoft#9478 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shivam Sharma (ShivamSharma43)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 18, 2026 17:23
Shivam Sharma (ShivamSharma43)
deployed
to
github-app-auth
October 18, 2026 17:23 — with
GitHub Actions
Active
Shivam Sharma (ShivamSharma43)
deployed
to
github-app-auth
October 18, 2026 17:23 — with
GitHub Actions
Active
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
When Claude calls a local tool and a server tool (for example
get_web_search_tool()) in the same turn, the response ends with a localtool_useplus a pendingserver_tool_use. The parser keeps the hosted call as an informationalfunction_callwithhosted=True, but_prepare_message_for_anthropicsends everyfunction_callback astool_use. Anthropic then expects a localtool_resultfor the server call and rejects the next request with HTTP 400 (tool_use ids were found without tool_result blocks immediately after: srvtoolu_...). Per Anthropic's server-tool docs, the client returns the local result and the API runs the pending server tool on the next request, which needs the block to stayserver_tool_use.Description & Review Guide
_prepare_messages_for_anthropiccollects the hosted calls that have nofunction_resultanywhere in the conversation and passes them down to_prepare_message_for_anthropic, which sends those calls asserver_tool_useinstead oftool_use. The hosted call is found from the call's ownhostedflag, which survivesto_dict/from_dict, so a reloaded session behaves the same.assistant [tool_use(local), server_tool_use(srv)]followed byuser [tool_result(local)]. Server tool calls that already have a result in the conversation keep today'stool_use/tool_resultpairing. I left those alone on purpose: the parsedweb_search_tool_resultcontent is stored stringified on theContent, so a native result block (withencrypted_content) can't be rebuilt from history. Switching only the call type would leave the result without a matchingtool_use.Tests:
test_prepare_messages_preserves_parallel_server_tool_use(in memory and after ato_dict/from_dictreload, from realBetaToolUseBlock/BetaServerToolUseBlockparsing) fails on main and passes with the change.test_prepare_messages_keeps_completed_server_tool_call_paired_with_its_resultpins the unchanged pairing once the search result arrives. The anthropic package unit tests pass (204), ruff check/format are clean, and mypy/pyright report no new errors inagent_framework_anthropiccompared with main. I did not run it against the live Anthropic API.Related Issue
Fixes #9478
The issue was reproduced by the repository's triage workflow (
reproducedlabel, assigned to Eduard van Valkenburg (@eavanvalkenburg)). It has no maintainer comment on the direction yet, and no open PR references it. Happy to adjust or close if you'd rather handle it differently.AI Assistance
AI assistance details: implementation, tests and this PR description were drafted with Claude Code and reviewed before submitting.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.🤖 Generated with Claude Code