Skip to content

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
tao-to-python:fix/tool-runner-server-tool-use
Open

fix(tools): prevent tool_runner from exiting when server_tool_use blocks are present#1271
tao-to-python wants to merge 1 commit intoanthropics:mainfrom
tao-to-python:fix/tool-runner-server-tool-use

Conversation

@tao-to-python
Copy link

Description

Fixes premature exit of tool_runner when server-side tools are used alongside client tools, as reported in #1170.

Problem

When using client.beta.messages.tool_runner() with server-side tools like web_search or web_fetch, the API responds with server_tool_use blocks and stop_reason="pause_turn". However, _generate_tool_call_response() only filters for block.type == "tool_use":

tool_use_blocks = [block for block in content if block.type == "tool_use"]
if not tool_use_blocks:
    return None  # exits the runner

server_tool_use blocks have a different type, so the list is empty, None is returned, and the runner exits before the server can return results.

Solution

When no client tool_use blocks are found, check for server_tool_use blocks. If present, return an empty user message to continue the loop:

has_server_tools = any(block.type == "server_tool_use" for block in content)
if has_server_tools:
    return {"role": "user", "content": []}

Applied to both sync and async paths.

Changes

File Change
src/anthropic/lib/tools/_beta_runner.py Handle server_tool_use in sync + async

Fixes #1170

…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
@tao-to-python tao-to-python requested a review from a team as a code owner March 20, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool runner exits early when response contains only server tool use blocks (e.g. web_search, web_fetch) and stop reason: pause_turn

1 participant