fix: insert cachePoint before non-PDF document blocks in _inject_cache_point()#2070
Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Open
Conversation
…e_point() _inject_cache_point() always appended the cachePoint to the end of the last user message's content array. When the last block was a non-PDF document (md, docx, csv, xlsx, html, txt), Bedrock could not translate the sequence to the Anthropic API format, raising ValidationException because Anthropic does not natively support non-PDF documents and the conversion path failed. PDF documents were unaffected. The fix walks backwards from the end of the content array, skipping trailing non-PDF document blocks, and inserts the cachePoint before them. Existing behavior is preserved for all other content types (text, images, tool results, PDF documents). Resolves strands-agents#1966
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.
Description
_inject_cache_point() always appended the cachePoint to the end of the last
user message's content array. When the last block was a non-PDF document
(md, docx, csv, xlsx, html, txt), Bedrock could not translate the sequence
to the Anthropic API format, raising ValidationException. PDF documents were
unaffected because Anthropic handles them natively.
The fix walks backwards from the end of the content array, skips any trailing
non-PDF document blocks, and inserts the cachePoint before them. All other
content types (text, images, tool results, PDF documents) behave exactly as
before.
Related Issues
Resolves #1966
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change?
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.