Skip to content

fix: include reasoning block with empty text and non-empty signature#2150

Open
gaurav71531 wants to merge 2 commits intostrands-agents:mainfrom
gaurav71531:fix-reasoning
Open

fix: include reasoning block with empty text and non-empty signature#2150
gaurav71531 wants to merge 2 commits intostrands-agents:mainfrom
gaurav71531:fix-reasoning

Conversation

@gaurav71531
Copy link
Copy Markdown

@gaurav71531 gaurav71531 commented Apr 17, 2026

Motivation

Some models like Opus 4.7 emit reasoning content blocks that carry only a signature with no accompanying reasoningText. The prior condition in handle_content_block_stop checked only reasoning_text, which evaluated to falsy for an empty string, causing the entire reasoning content block (including the signature) to be silently dropped from the assembled message content.

Public API Changes

No public API changes. This is an internal streaming assembly fix.

Change

The condition in handle_content_block_stop is broadened from:

elif reasoning_text:

to:

elif reasoning_text or "signature" in state:

This ensures that reasoning blocks carrying only a signature are preserved in the output content, matching the behavior models like Opus 4.7 expect.

Testing

Added two tests covering the signature-only reasoning scenario:

  • A parametrized case in test_handle_content_block_stop for empty reasoningText with a signature present
  • An end-to-end test_process_stream_with_signature_only that simulates the Opus 4.7 streaming pattern (signature-only reasoning block followed by a text response)

@poshinchen
Copy link
Copy Markdown
Contributor

/strands

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@poshinchen poshinchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add / update the unit tests so we know what the expected behaviors are?

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.

2 participants