Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Amazon Bedrock integration to correctly handle and preserve signed reasoning blocks that contain empty text (e.g., when Claude signs an empty thinking block at the start of a tool-use turn). This is handled in both the converters and stream processing modules, and corresponding unit tests have been added to verify the round-trip behavior and streaming scenarios. I have no feedback to provide as there are no review comments.
|
@huangjeff5 could you take a look when you have a moment? Bedrock was dropping signed reasoning blocks that came back with empty text, so this keeps and replays them. Same fix as #6839 for Anthropic. |
… empty text Claude on Bedrock can return a reasoning block with empty text and a valid signature. The streaming path dropped it because it only kept blocks with text or redacted content, and the request side dropped it again because it required both text and a signature. With thinking enabled, a tool-use turn has to start with that block, so the next request in a tool loop could fail. Keep signed blocks when streaming, as the non-streaming path already does, and send signed reasoning back even when its text is empty. Unsigned reasoning is still dropped.
4c94aa9 to
5ce80fd
Compare
|
Closing as subsumed: the Amazon Bedrock signed reasoning changes here were folded directly into #6839. |
Same bug as #6798 / #6839, Bedrock flavor.
Claude can return a reasoning block with empty text and a valid signature, mostly on the turn after a tool call. On Bedrock that block was lost in two places:
_blocks_to_partsonly kept a reasoning block if it had text or redacted content, so a signature-only block disappeared (the non-streaming_reasoning_block_to_partalready keeps it)_reasoning_part_to_blocksrequiredtext and signature, so even a non-streamed part was dropped on replayWith thinking enabled, a tool-use turn has to start with its thinking block, so the next request in the tool loop can fail.
Now streaming keeps the block when it has a signature, and the request side sends
reasoningText {text: '', signature}when there's a signature. Unsigned reasoning is still dropped, and a redacted-only part still only sendsredactedContent.One thing I couldn't check: I don't have AWS access set up, so I haven't confirmed live that Converse accepts
reasoningText.textas an empty string. Anthropic's own API accepts the empty thinking block it produced, and Bedrock hands it back to the same model, so I expect it to work, but it'd be great if someone with Bedrock access could run a thinking + tool call turn against it.Tests:
reasoningTextwithtext: ''; a response with[reasoning(''), toolUse]round trips to the request with the reasoning block first; unsigned empty reasoning is still droppeduv run pytest packages/genkit-amazon-bedrock/testspasses (477 passed, 24 skipped), ruff, pyright and ty are clean.