fix: preserve Gemini thought_signature in LiteLLM multi-turn tool calls#2129
fix: preserve Gemini thought_signature in LiteLLM multi-turn tool calls#2129opieter-aws merged 1 commit intostrands-agents:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Assessment: Comment Clean, well-structured bugfix that correctly preserves Gemini thought signatures through the LiteLLM multi-turn tool call pipeline. The dual extraction strategy (structured field + ID-based fallback) is a pragmatic approach given the dependency on LiteLLM internals. Review Details
Well-documented code with thorough unit tests covering extraction, encoding, double-encode prevention, and round-trip scenarios. |
|
Assessment: Comment Well-scoped bugfix that correctly preserves Gemini Review Details
Test coverage is thorough — 8 unit tests covering extraction, encoding, double-encode prevention, and full round-trip, plus a well-guarded integration test. |
Closes strands-agents#1764 Co-authored-by: giulio-leone <giulio-leone@users.noreply.github.com>
|
Assessment: Comment Well-scoped bugfix with solid test coverage and clean integration with the existing Review Details
The dual extraction strategy, double-encode prevention, and round-trip test give good confidence in the fix. |
Closes #1764
Co-authored-by: giulio-leone giulio-leone@users.noreply.github.com
Description
Supersedes #1982, which was accidentally closed after a bad rebase wiped the commit history.
Preserves Gemini
thought_signaturethrough multi-turn tool calls when using the LiteLLM model provider. LiteLLM encodes the signature into the tool call ID using a__thought__separator; this PR extracts it intoreasoningSignatureon inbound chunks and re-encodes it on outbound request messages.Changes to
src/strands/models/litellm.py:format_chunkto extract thought signatures from tool call content_start eventsformat_request_message_tool_callto re-encodereasoningSignatureback into the tool call ID_extract_thought_signaturestatic helperRelated Issues
Documentation PR
N/A — bugfix with no public API changes.
Type of Change
Bug fix
Testing
8 new unit tests covering signature extraction, encoding, double-encode prevention, and full round-trip
1 new integration test for Gemini thinking model tool calls (requires
GOOGLE_API_KEY)All 48 existing litellm unit tests pass
I ran
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.