fix: continue tool runner loop on server_tool_use with pause_turn#1229
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
fix: continue tool runner loop on server_tool_use with pause_turn#1229MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
When the API responds with server_tool_use blocks (e.g. web_search, web_fetch) and stop_reason "pause_turn", the tool runner incorrectly exits the loop because _generate_tool_call_response() only checks for blocks with type == "tool_use" and returns None when it finds none. The fix checks for pause_turn stop reason before exiting. When pause_turn is detected, the runner appends the assistant message and continues the loop so the API can resolve the server tool calls on the next iteration. Applied to both sync (BaseSyncToolRunner) and async (BaseAsyncToolRunner) __run__ methods. 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.
Summary
Fixes #1170.
When using
tool_runner()with server-side tools (e.g.web_search,web_fetch) alongside client-side@beta_toolfunctions, the runner exits prematurely when the API responds withserver_tool_useblocks andstop_reason: "pause_turn".Root cause
In
_beta_runner.py, both the sync and async_generate_tool_call_response()methods filter content blocks withblock.type == "tool_use"only:When a response contains only
server_tool_useblocks (which havetype == "server_tool_use"), this returnsNone, causing the__run__loop to exit:Fix
Before exiting the loop, check if the last message's
stop_reasonis"pause_turn". If so, the server is still processing its own tool calls -- append the assistant message and continue the loop so the API can resolve the server tools on the next iteration.Applied to both:
BaseSyncToolRunner.__run__()BaseAsyncToolRunner.__run__()