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
30 changes: 22 additions & 8 deletions src/anthropic/lib/tools/_beta_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,17 @@ def __run__(self) -> Iterator[RunnerItemT]:
if not self._check_and_compact():
response = self.generate_tool_call_response()
if response is None:
log.debug("Tool call was not requested, exiting from tool runner loop.")
return

if not self._messages_modified:
# When stop_reason is "pause_turn", the server is still processing
# server tool use blocks (e.g. web_search, web_fetch). Continue the
# loop so the API can resolve them on the next iteration.
if message.stop_reason == "pause_turn":
log.debug("Server tool use in progress (pause_turn), continuing loop.")
if not self._messages_modified:
self.append_messages(message)
else:
log.debug("Tool call was not requested, exiting from tool runner loop.")
return
elif not self._messages_modified:
self.append_messages(message, response)

self._messages_modified = False
Expand Down Expand Up @@ -521,10 +528,17 @@ async def __run__(self) -> AsyncIterator[RunnerItemT]:
if not await self._check_and_compact():
response = await self.generate_tool_call_response()
if response is None:
log.debug("Tool call was not requested, exiting from tool runner loop.")
return

if not self._messages_modified:
# When stop_reason is "pause_turn", the server is still processing
# server tool use blocks (e.g. web_search, web_fetch). Continue the
# loop so the API can resolve them on the next iteration.
if message.stop_reason == "pause_turn":
log.debug("Server tool use in progress (pause_turn), continuing loop.")
if not self._messages_modified:
self.append_messages(message)
else:
log.debug("Tool call was not requested, exiting from tool runner loop.")
return
elif not self._messages_modified:
self.append_messages(message, response)

self._messages_modified = False
Expand Down