fix(tools): use filtered messages list in async compaction#1124
Open
fede-kamel wants to merge 2 commits intoanthropics:mainfrom
Open
fix(tools): use filtered messages list in async compaction#1124fede-kamel wants to merge 2 commits intoanthropics:mainfrom
fede-kamel wants to merge 2 commits intoanthropics:mainfrom
Conversation
The async _check_and_compact() method was using self._params["messages"] instead of the local `messages` variable when building the compaction request. This caused the filtering logic (which removes tool_use blocks from the last assistant message) to be ignored. When compaction runs and the last message is an assistant with only tool_use blocks, those blocks should be filtered out before sending the summarization request. Without this fix, the API rejects with: "tool_use ids were found without tool_result blocks" The sync version correctly uses `*messages`, the async version was incorrectly using `*self._params["messages"]`. Added regression test that verifies tool_use filtering works correctly.
- Add cast() to fix pyright type error where lambda returns dict instead of ParseMessageCreateParamsBase - Fix bug: use params["messages"] (existing conversation) instead of messages (input variable)
412ceba to
8684857
Compare
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
Fixes a bug where async
_check_and_compact()ignores the tool_use filtering logic.The Bug
When compaction runs and the last message is an assistant with only
tool_useblocks, those blocks should be filtered out before sending the summarization request. The sync version does this correctly, but the async version was usingself._params["messages"]instead of the filteredmessagesvariable.Without fix:
With fix: Compaction succeeds - tool_use is filtered out.
Code Change
Test Plan
test_async_compaction_filters_tool_use