fix: allow both append_messages and generate_tool_call_response in tool runner loop#1594
Open
AliSharjeell wants to merge 2 commits into
Open
fix: allow both append_messages and generate_tool_call_response in tool runner loop#1594AliSharjeell wants to merge 2 commits into
AliSharjeell wants to merge 2 commits into
Conversation
Replace manual PYPI_TOKEN approach with OIDC-based authentication using pypa/gh-action-pypi-publish. This eliminates the need to manage and rotate API tokens, improving security posture. The workflow now triggers on release publication and uses GitHub's OIDC to authenticate with PyPI directly. Closes anthropics#1568
…ol runner loop When users call both append_messages() and generate_tool_call_response() in the same loop iteration (e.g., to log the tool result), the tool result was never added to history because _messages_modified bypassed the auto-append. This caused infinite loops as the model re-called the same tool. Now we clear the cache and reset _messages_modified so the auto-append always happens, while still allowing users to access/generate the response. Closes anthropics#1536
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When users call both
append_messages()ANDgenerate_tool_call_response()in the same loop iteration (e.g., to log the tool result), the tool result was never added to history because_messages_modified = Truebypassed the auto-append. This caused infinite loops as the model re-called the same tool with no history of the result.Root Cause
The original code:
When
append_messages()was called first, it set_messages_modified = True, so the auto-append was skipped. But sincegenerate_tool_call_response()was also called (and cached), the tool result was never added.Fix
Changed the logic to:
Now the auto-append always happens, clearing the cache and reset flag if needed. Users can still access the tool result via
generate_tool_call_response()before the loop continues.Testing
The fix was verified against the minimal repro from the issue:
Now terminates correctly instead of infinite looping.
Related Issue
Closes #1536 — append_messages() inside tool runner loop causes infinite loop