fix(converters): prepend reasoningContent blocks in _openai_to_bedrock()#419
Open
cagataycali wants to merge 1 commit intoaws:mainfrom
Open
fix(converters): prepend reasoningContent blocks in _openai_to_bedrock()#419cagataycali wants to merge 1 commit intoaws:mainfrom
cagataycali wants to merge 1 commit intoaws:mainfrom
Conversation
The _openai_to_bedrock() function appended reasoningContent blocks after text and toolUse blocks. Bedrock API requires that if an assistant message contains any thinking blocks, the first block must be a thinking block. This caused ValidationException on multi-turn conversations with extended thinking enabled: 'If an assistant message contains any thinking blocks, the first block must be thinking. Found text' The fix collects reasoning blocks separately and prepends them to the content array, matching the original block ordering that Bedrock produced. Before: [text, toolUse, reasoningContent] -> ValidationException After: [reasoningContent, text, toolUse] -> Correct Fixes aws#416
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #419 +/- ##
=======================================
Coverage ? 91.24%
=======================================
Files ? 58
Lines ? 4970
Branches ? 756
=======================================
Hits ? 4535
Misses ? 249
Partials ? 186
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi team, I also facing this error for toolUse, can you all help me fix? Appreciate it |
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 #416 —
_openai_to_bedrock()appendsreasoningContentblocks aftertextandtoolUse, but Bedrock requires thinking blocks to come first.3-line fix. No new dependencies. No behavioral change for messages without reasoning.
The Bug
Bedrock error:
Changes
Verification
15 tests across 3 suites all pass:
Impact
OpenAIConverseConverterreasoningContent(empty list prepended = no change)AgentCoreMemoryConverterusers (already works correctly)I understand this repo's policy on external PRs — feel free to close if preferred and cherry-pick internally. The fix is also documented in the #416 comment thread.