fix(tools): prevent tool_runner from exiting when server_tool_use blocks are present#1271
Open
tao-to-python wants to merge 1 commit intoanthropics:mainfrom
Open
Conversation
…cks are present When the API responds with server_tool_use blocks (e.g. web_search, web_fetch) and stop_reason='pause_turn', the tool runner's _generate_tool_call_response() only looks for type='tool_use' blocks. Since server tools have type='server_tool_use', it returns None and the runner exits prematurely. Detect server_tool_use blocks and return an empty user message to continue the loop, allowing the server to process and return results. Fixes anthropics#1170
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.
Description
Fixes premature exit of
tool_runnerwhen server-side tools are used alongside client tools, as reported in #1170.Problem
When using
client.beta.messages.tool_runner()with server-side tools likeweb_searchorweb_fetch, the API responds withserver_tool_useblocks andstop_reason="pause_turn". However,_generate_tool_call_response()only filters forblock.type == "tool_use":server_tool_useblocks have a different type, so the list is empty,Noneis returned, and the runner exits before the server can return results.Solution
When no client
tool_useblocks are found, check forserver_tool_useblocks. If present, return an empty user message to continue the loop:Applied to both sync and async paths.
Changes
src/anthropic/lib/tools/_beta_runner.pyFixes #1170