fix(bedrock): hoist cachePoint blocks out of ToolMessage content to comply with Bedrock API #503
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.
What this PR does
Fixes Issue #500: Incorrect nesting of
cachePoint
blocks insideToolMessage
causes Bedrock API request validation errors.Before (Invalid Bedrock format)
The
cachePoint
block is nested undertoolResult.content
, which is not allowed by Bedrock API:After (Valid Bedrock format)
This PR hoists the
cachePoint
block to be a top-level sibling entry within the message's content array:Implementation details
_messages_to_bedrock
,ToolMessage.content
is split into:tool_result_content
: Blocks safe to nest undertoolResult
(e.g., text)special_blocks
: Blocks likecachePoint
that must be top-levelTest coverage
Added
test_messages_to_bedrock_with_cache_point()
intest_bedrock_converse.py
to validate:Reference
Fixes #500