fix(tools): continue tool_runner loop on pause_turn with server_tool_use blocks#1235
Open
s-zx wants to merge 1 commit intoanthropics:mainfrom
Open
fix(tools): continue tool_runner loop on pause_turn with server_tool_use blocks#1235s-zx wants to merge 1 commit intoanthropics:mainfrom
s-zx wants to merge 1 commit intoanthropics:mainfrom
Conversation
…use blocks
When using client.beta.messages.tool_runner() with server-side tools
(web_search, web_fetch) alongside @beta_tool functions, the runner
exited prematurely when the API responded with stop_reason='pause_turn'
and server_tool_use blocks.
Root cause: _generate_tool_call_response() filters content for blocks
with type='tool_use'. When only server_tool_use blocks are present, the
filter returns an empty list and the method returns None. The __run__
loop then exits:
response = self.generate_tool_call_response()
if response is None:
return <- exits even though server is still processing
Fix: add _has_pause_turn_server_tools() helper to both
BaseSyncToolRunner and BaseAsyncToolRunner. In __run__ (sync and async),
check this helper before deciding to exit. When True, skip the
generate_tool_call_response call and continue the loop without appending
a new user turn — the server will resume on the next API call.
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.
Problem
When using
client.beta.messages.tool_runner()with server-side tools (web_search,web_fetch) alongside@beta_toolclient functions, the runner exits prematurely when the API responds withstop_reason="pause_turn"andserver_tool_useblocks.until_done()then returns a message whose last content block is aBetaServerToolUseBlockinstead of text, causingAttributeError: 'BetaServerToolUseBlock' object has no attribute 'text'.Closes #1170
Root Cause
_generate_tool_call_response()filters content fortype == "tool_use"blocks. When the response contains onlyserver_tool_useblocks, this filter returns nothing and the method returnsNone:The
__run__loop then seesNoneand exits:Fix
Add
_has_pause_turn_server_tools()to bothBaseSyncToolRunnerandBaseAsyncToolRunner. In__run__(sync and async), check this helper before deciding to exit. When it returnsTrue:generate_tool_call_response()entirely