Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 13 additions & 7 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# workflow for re-running publishing to PyPI in case it fails for some reason
# you can run this workflow by navigating to https://www.github.com/anthropics/anthropic-sdk-python/actions/workflows/publish-pypi.yml
# workflow for publishing to PyPI using Trusted Publishing
# replaces the manual PYPI_TOKEN approach with OIDC-based authentication
# see: https://docs.pypi.org/trusted-publishers/
name: Publish PyPI

on:
workflow_dispatch:
release:
types: [published]

jobs:
publish:
name: publish
runs-on: ubuntu-latest
environment: production-release

permissions:
id-token: write

steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

Expand All @@ -18,8 +24,8 @@ jobs:
with:
version: '0.9.13'

- name: Build
run: uv build

- name: Publish to PyPI
run: |
bash ./bin/publish-pypi
env:
PYPI_TOKEN: ${{ secrets.ANTHROPIC_PYPI_TOKEN || secrets.PYPI_TOKEN }}
uses: pypa/gh-action-pypi-publish@release/v1
22 changes: 18 additions & 4 deletions src/anthropic/lib/tools/_beta_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,15 @@ def __run__(self) -> Iterator[RunnerItemT]:
log.debug("Tool call was not requested, exiting from tool runner loop.")
return

if not self._messages_modified:
self.append_messages(message, response)
# If user has called append_messages() to add additional messages but also
# called generate_tool_call_response() (e.g., to log the tool result), we need
# to clear the cache so the auto-append happens. Otherwise the tool result
# is never added to history and the model re-calls the tool forever.
if self._messages_modified:
self._cached_tool_call_response = None
self._messages_modified = False

self.append_messages(message, response)

self._messages_modified = False
self._cached_tool_call_response = None
Expand Down Expand Up @@ -560,8 +567,15 @@ async def __run__(self) -> AsyncIterator[RunnerItemT]:
log.debug("Tool call was not requested, exiting from tool runner loop.")
return

if not self._messages_modified:
self.append_messages(message, response)
# If user has called append_messages() to add additional messages but also
# called generate_tool_call_response() (e.g., to log the tool result), we need
# to clear the cache so the auto-append happens. Otherwise the tool result
# is never added to history and the model re-calls the tool forever.
if self._messages_modified:
self._cached_tool_call_response = None
self._messages_modified = False

self.append_messages(message, response)

self._messages_modified = False
self._cached_tool_call_response = None
Expand Down