Repository navigation
fix(ai-constructs): handle reasoning content blocks from Bedrock Converse - #3368
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
…erse Claude models that think by default (e.g. Claude Sonnet 5.5) return reasoningContent blocks. The streaming adapter turned each one into an empty text block, which Bedrock rejects in the tool use loop and which was persisted, breaking every later turn. The non-streaming adapter returned them to AppSync. Keep reasoning blocks unchanged in the tool use loop, leave them out of the client facing response, and skip empty text blocks persisted next to other content when loading the message history. Fixes aws-amplify#3362 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: c3dcc82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Author
|
Friendly ping: this is ready for review whenever someone has a moment. Happy to adjust anything. |
Author
|
Friendly ping: could someone take a look at this when there's time? I'm happy to adjust anything. Thanks! |
This branch has not been deployed
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.
Problem
Claude models that think by default (e.g. Claude Sonnet 5.5) return
reasoningContentblocks from Bedrock Converse.BedrockConverseAdapterdidn't handle them:askBedrockStreamingonly readsdelta.toolUseanddelta.text, and oncontentBlockStoptreats every non tool use block as text. Each reasoning block became{ text: '' }:messages: text content blocks must be non-empty;accumulatedTurnContent, so the empty block is persisted and every later turn of the conversation fails the same way.askBedrockreturned the final message content as is, so the reasoning blocks were sent to AppSync, whoseAmplifyAIContentBlockInputdoesn't definereasoningContent.Issue number, if available: fixes #3362
Changes
askBedrockStreamingaccumulatesreasoningContentdeltas (text, signature, or redacted content) into a reasoning block. OncontentBlockStopthe block is added to the assistant message used in the tool use loop, unchanged, since Bedrock expects reasoning blocks back with the tool results. It isn't streamed, added toaccumulatedTurnContent, or counted in the client facing block indexes.askBedrockkeeps the full message in the tool use loop (as before) and filters reasoning blocks out of the content it returns.This doesn't recover the answer text in the third case described in the issue: when the model writes it between tool calls, Bedrock returns it as a thinking block whose text is empty at the default display setting, so there's no text to show.
Corresponding docs PR, if applicable: N/A
Validation
keeps reasoning blocks in the tool use loop but not in the response: a tool use turn preceded by a reasoning block with empty text, then a final turn with a redacted reasoning block, a reasoning block and text. Asserts the second Bedrock request carries the reasoning block next to the tool use, and the response (and every streamed chunk) contains only the final text at block index 0.drops empty text blocks persisted next to other content: history with[{ text: '' }, { text: 'answer' }]is sent to Bedrock as[{ text: 'answer' }].bedrock_converse_adapter.test.ts: 22/22 pass. With the fix reverted, the 4 new tests fail.Checklist
run-e2elabel set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
🤖 Generated with Claude Code