Skip to content

fix(ai-constructs): handle reasoning content blocks from Bedrock Converse - #3368

Open
pcbeingused333 wants to merge 1 commit into
aws-amplify:mainfrom
pcbeingused333:fix-bedrock-reasoning-content
Open

pcbeingused333 wants to merge 1 commit into
aws-amplify:mainfrom
pcbeingused333:fix-bedrock-reasoning-content

Conversation

@pcbeingused333

Copy link
Copy Markdown

Problem

Claude models that think by default (e.g. Claude Sonnet 5.5) return reasoningContent blocks from Bedrock Converse. BedrockConverseAdapter didn't handle them:

  • Streaming: askBedrockStreaming only reads delta.toolUse and delta.text, and on contentBlockStop treats every non tool use block as text. Each reasoning block became { text: '' }:
    • in the tool use loop, so the next Converse request fails with messages: text content blocks must be non-empty;
    • in accumulatedTurnContent, so the empty block is persisted and every later turn of the conversation fails the same way.
  • Non-streaming: askBedrock returned the final message content as is, so the reasoning blocks were sent to AppSync, whose AmplifyAIContentBlockInput doesn't define reasoningContent.

Issue number, if available: fixes #3362

Changes

  • askBedrockStreaming accumulates reasoningContent deltas (text, signature, or redacted content) into a reasoning block. On contentBlockStop the 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 to accumulatedTurnContent, or counted in the client facing block indexes.
  • askBedrock keeps the full message in the tool use loop (as before) and filters reasoning blocks out of the content it returns.
  • When the message history is loaded, empty text blocks are skipped if the message has other content. Conversations that already have the empty block persisted can then continue. Messages whose only content is an empty text block are left as they are.

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

  • New unit tests, run for both the streaming and non-streaming adapter:
    • 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' }].
  • The stream mock now emits reasoning blocks the way Bedrock does in the issue's log (deltas without a content block start).
  • bedrock_converse_adapter.test.ts: 22/22 pass. With the fix reverted, the 4 new tests fail.
  • prettier and eslint pass on the changed files.
  • Not verified against a live Bedrock endpoint (no AWS account available to me).

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label 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

…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>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner October 16, 2026 02:34
@changeset-bot

changeset-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c3dcc82

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/ai-constructs Patch

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

@pcbeingused333

Copy link
Copy Markdown
Author

Friendly ping: this is ready for review whenever someone has a moment. Happy to adjust anything.

@pcbeingused333

Copy link
Copy Markdown
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant