Skip to content

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
giulio-leone:fix/content-block-start-all-types-1460
Open

fix(bedrock): emit contentBlockStart for all content block types in non-streaming mode#1849
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/content-block-start-all-types-1460

Conversation

@giulio-leone
Copy link
Contributor

Problem

In non-streaming mode (streaming=False), contentBlockStart events are only emitted for toolUse content blocks. Text, reasoning, and citation content blocks go straight to contentBlockDelta without a preceding contentBlockStart event.

This breaks consumers that iterate over stream_async events expecting a consistent event sequence matching Bedrock's streaming API:

messageStart → contentBlockStart → contentBlockDelta(s) → contentBlockStop → ... → messageStop

Instead, non-streaming mode produces:

messageStart →

Root Cause

In _stream_non_streaming(), the contentBlockStart event was gated behind if "toolUse" in content. Text, reasoning, and citation blocks skipped this gate and went directly to contentBlockDelta.

Fix

Emit contentBlockStart with contentBlockIndex for all content block types (text, reasoningContent, citationsContent, toolUse) to match streaming behavior where Bedrock itself sends contentBlockStart for every content block.

Tests

  • Updated 7 existing non-streaming tests to expect the new contentBlockStart events
  • All 123 Bedrock tests pass
  • Lint clean

Fixes #1460

@github-actions github-actions bot added the size/s label Mar 7, 2026
@giulio-leone giulio-leone force-pushed the fix/content-block-start-all-types-1460 branch from 8759c3d to cf480f5 Compare March 8, 2026 22:07
@github-actions github-actions bot added size/s and removed size/s labels Mar 8, 2026
@giulio-leone
Copy link
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
@giulio-leone giulio-leone force-pushed the fix/content-block-start-all-types-1460 branch from cf480f5 to 42dff4b Compare March 9, 2026 20:50
@github-actions github-actions bot added size/s and removed size/s labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] contentBlockStart event not fired for first contentBlock in event loop

1 participant