diff --git a/src/anthropic/lib/tools/_beta_runner.py b/src/anthropic/lib/tools/_beta_runner.py index d2c55ea7..294c1a50 100644 --- a/src/anthropic/lib/tools/_beta_runner.py +++ b/src/anthropic/lib/tools/_beta_runner.py @@ -306,6 +306,13 @@ def _generate_tool_call_response(self) -> BetaMessageParam | None: tool_use_blocks = [block for block in content if block.type == "tool_use"] if not tool_use_blocks: + # When server-side tools (e.g. web_search, web_fetch) are present, + # the API responds with server_tool_use blocks and stop_reason="pause_turn". + # The runner should continue the loop so the server can return results. + has_server_tools = any(block.type == "server_tool_use" for block in content) + if has_server_tools: + log.debug("Server tool use detected, continuing runner loop.") + return {"role": "user", "content": []} return None results: list[BetaToolResultBlockParam] = [] @@ -598,6 +605,10 @@ async def _generate_tool_call_response(self) -> BetaMessageParam | None: tool_use_blocks = [block for block in content if block.type == "tool_use"] if not tool_use_blocks: + has_server_tools = any(block.type == "server_tool_use" for block in content) + if has_server_tools: + log.debug("Server tool use detected, continuing runner loop (async).") + return {"role": "user", "content": []} return None results: list[BetaToolResultBlockParam] = []