fix: preserve reasoning content signature from LiteLLM thinking models#1789
fix: preserve reasoning content signature from LiteLLM thinking models#1789giulio-leone wants to merge 5 commits intostrands-agents:mainfrom
Conversation
When streaming responses from thinking models (e.g., Gemini) via LiteLLM, the reasoning content signature was silently dropped. The LiteLLM adapter's _process_choice_content only emitted reasoning text from delta.reasoning_content but never captured the signature from delta.thinking.signature. This patch adds a check for the thinking.signature attribute on each streaming delta and emits a contentBlockDelta with reasoningContent.signature so the event loop can accumulate and store the signature in the final content block. An isinstance(sig, str) guard prevents unittest.mock.Mock objects from triggering false positives during testing. Fixes strands-agents#1764 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
All CI checks pass. Ready for review. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
zastrowm
left a comment
There was a problem hiding this comment.
Is this something we could have an integ test for? Would help prove out that it works against a live model
|
Assessment: Approve ✅ Clean fix that correctly preserves reasoning signatures from LiteLLM's Review Details
Thanks for the well-documented PR description - the root cause analysis was particularly helpful! |
|
Hi! Gentle ping — this PR is rebased, CI passes, and ready for review. Happy to address any feedback. Thanks! |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
275b75d
|
@zastrowm Good point — I can add an integration test that exercises the |
I was thinking more of an litellm integ test integ test that ensures that reasoning and signatures are included in responses - does that fit into an existing test and/or something we can test for? |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add parametrized integration test (streaming + non-streaming) that verifies reasoning content and signatures are preserved in model responses when extended thinking is enabled via the LiteLLM adapter. Addresses review feedback from zastrowm on PR strands-agents#1789. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@zastrowm Good suggestion — I've added a litellm integration test in |
…raint When thinking is enabled with tools, Bedrock requires thinking blocks in assistant messages on subsequent turns. Since this test only needs to verify reasoning + signature preservation, tools are not needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Problem
When streaming responses from thinking models (e.g., Gemini) via LiteLLM, the reasoning content signature is silently dropped. The LiteLLM adapter's
_process_choice_contentonly emits reasoning text fromdelta.reasoning_contentbut never captures the signature fromdelta.thinking.signature.The event loop in
streaming.pyalready correctly handlesreasoningContent.signaturedeltas (lines 240-248, 314-315), but the LiteLLM model provider never emits them.Root Cause
LiteLLM provides reasoning signatures via a separate
thinkingattribute on stream deltas (delta.thinking.signature), distinct fromdelta.reasoning_content(which only contains the text). The LiteLLM model provider's_process_choice_contentmethod only processedreasoning_contenttext, never checking for thethinking.signatureattribute.Fix
Added a check in
_process_choice_content()for thethinking.signatureattribute on each streaming delta. When a valid string signature is found, acontentBlockDeltawithreasoningContent.signatureis emitted so the event loop can accumulate and store it in the final content block.An
isinstance(sig, str)guard prevents false positives from unittest.mock.Mock objects that auto-create attributes.Testing
test_stream_preserves_thinking_signaturethat simulates a 3-chunk streaming response with reasoning text and signatureFixes #1764