fix(bedrock): emit contentBlockStart for all content block types in non-streaming mode#1849
Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Open
Conversation
8759c3d to
cf480f5
Compare
Contributor
Author
|
Friendly ping — CI is green, tests pass, rebased on latest. Ready for review whenever convenient. Happy to address any feedback. 🙏 |
…on-streaming mode In non-streaming mode (streaming=False), contentBlockStart events were only emitted for toolUse content blocks. Text, reasoning, and citation content blocks went straight to contentBlockDelta without a preceding contentBlockStart event. This broke parity with streaming mode where Bedrock itself sends contentBlockStart for every content block type, and caused consumers iterating stream_async events to miss contentBlockStart events for non-tool-use content. Now emit contentBlockStart with contentBlockIndex for all content block types (text, reasoningContent, citationsContent, toolUse) to match streaming behavior. Fixes strands-agents#1460
cf480f5 to
42dff4b
Compare
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
In non-streaming mode (
streaming=False),contentBlockStartevents are only emitted fortoolUsecontent blocks. Text, reasoning, and citation content blocks go straight tocontentBlockDeltawithout a precedingcontentBlockStartevent.This breaks consumers that iterate over
stream_asyncevents expecting a consistent event sequence matching Bedrock's streaming API:Instead, non-streaming mode produces:
Root Cause
In
_stream_non_streaming(), thecontentBlockStartevent was gated behindif "toolUse" in content. Text, reasoning, and citation blocks skipped this gate and went directly tocontentBlockDelta.Fix
Emit
contentBlockStartwithcontentBlockIndexfor all content block types (text, reasoningContent, citationsContent, toolUse) to match streaming behavior where Bedrock itself sendscontentBlockStartfor every content block.Tests
contentBlockStarteventsFixes #1460