Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/anthropic/lib/tools/_beta_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down Expand Up @@ -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] = []
Expand Down