Skip to content

Conversation

@trapezoid
Copy link

@trapezoid trapezoid commented Nov 27, 2025

From Gemini 3.0 onwards, it will be mandatory to assign thought signatures when performing function calls.

https://ai.google.dev/gemini-api/docs/thought-signatures#how_it_works

This poses a significant problem as thought signatures are lost in Google_GenerativeAI.Microsoft.
Consequently, we have implemented a solution whereby thought signatures are set within the AdditionalProperties of AIContent.

Summary by CodeRabbit

  • New Features

    • Enhanced metadata preservation during content transformations to ensure thought signature information is maintained throughout the processing pipeline.
  • Tests

    • Added comprehensive unit tests validating metadata propagation in content conversions.

✏️ Tip: You can customize this high-level summary in your review settings.

google-labs-jules bot and others added 3 commits November 27, 2025 04:10
Maps Part.ThoughtSignature to FunctionCallContent.AdditionalProperties (and TextContent) to enable bidirectional conversion of thought signatures.
Maps Part.ThoughtSignature to FunctionCallContent.AdditionalProperties (and TextContent) to enable bidirectional conversion of thought signatures.
Includes unit tests.
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes extend content conversion methods in the Microsoft Generative AI extension to propagate ThoughtSignature metadata. The ToPart method now extracts ThoughtSignature from content's AdditionalProperties and assigns it to the returned Part object. The ToAiContents method reciprocally stores ThoughtSignature from Part objects back into AI content's AdditionalProperties for TextContent and FunctionCallContent.

Changes

Cohort / File(s) Summary
ThoughtSignature propagation in conversions
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs
Modified ToPart to extract and assign ThoughtSignature from content.AdditionalProperties to the returned Part. Modified ToAiContents to propagate ThoughtSignature from Part objects into AI content's AdditionalProperties (TextContent and FunctionCallContent paths).
Metadata propagation test coverage
tests/GenerativeAI.Microsoft.Tests/MicrosoftExtension_Tests.cs
Added unit tests validating ThoughtSignature propagation: ToPart/ToAiContents conversion paths for FunctionCall and Text content types, ensuring AdditionalProperties correctly preserve and restore ThoughtSignature metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Areas requiring attention:
    • Verify ThoughtSignature key naming consistency across both conversion directions
    • Validate null-safety handling for AdditionalProperties when ThoughtSignature is absent
    • Confirm test coverage captures both presence and absence of ThoughtSignature metadata

Possibly related PRs

Poem

🐰 A signature in thought must flow and stay,
Through content's form, then back to Part's array,
Metadata hopping, preserved with care,
Round-trip conversions—thoughts travel there!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for thought signatures in Microsoft.Extensions.AI, which aligns with all modifications across the codebase.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d69b67 and 634f1b5.

📒 Files selected for processing (1)
  • src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (3 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/GenerativeAI.Microsoft.Tests/MicrosoftExtension_Tests.cs (1)

313-407: Consider adding edge case tests (optional).

The current tests provide good coverage of the main scenarios. For even more robust testing, you might consider adding tests for:

  • Null or empty ThoughtSignature values
  • Multiple properties in AdditionalProperties alongside ThoughtSignature
  • Parts with no ThoughtSignature (ensuring AdditionalProperties isn't created unnecessarily)

However, the current implementation handles these cases correctly, so this is more of a nice-to-have for comprehensive test coverage.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d804d26 and 7d69b67.

📒 Files selected for processing (3)
  • src/GenerativeAI.Microsoft/AdditionalPropertyKeys.cs (1 hunks)
  • src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (3 hunks)
  • tests/GenerativeAI.Microsoft.Tests/MicrosoftExtension_Tests.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (3)
src/GenerativeAI.Microsoft/AdditionalPropertyKeys.cs (1)
  • AdditionalPropertiesKeys (6-32)
src/GenerativeAI/Extensions/GenerateContentResponseExtensions.cs (2)
  • Text (18-46)
  • FunctionCall (53-71)
src/GenerativeAI/Types/ContentGeneration/Tools/FunctionCalling/FunctionCall.cs (3)
  • FunctionCall (12-48)
  • FunctionCall (38-41)
  • FunctionCall (46-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (9.0.x)
🔇 Additional comments (9)
src/GenerativeAI.Microsoft/AdditionalPropertyKeys.cs (1)

27-31: LGTM! Clean addition of ThoughtSignature constant.

The new constant follows the established pattern and is properly documented.

src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (4)

147-187: LGTM! Proper null-safe propagation of ThoughtSignature.

The implementation correctly extracts ThoughtSignature from content.AdditionalProperties and assigns it to part.ThoughtSignature with appropriate null checks.


580-589: LGTM! Clean propagation of ThoughtSignature to TextContent.

The implementation properly checks for null and initializes AdditionalProperties only when needed.


591-601: LGTM! Consistent ThoughtSignature propagation for FunctionCallContent.

The implementation follows the same pattern as TextContent, ensuring consistency across content types.


603-607: Based on the official Gemini API documentation, I can now provide a definitive rewritten review comment:


FunctionResultContent correctly does not propagate ThoughtSignature.

The Gemini API documentation clarifies that ThoughtSignature is an encrypted token returned by the model exclusively with model-generated functionCall parts. It must be passed back in subsequent requests to maintain continuity. However, functionResponse (user-provided function results) is not model-generated content and therefore should not include ThoughtSignature. The current implementation is correct: FunctionCallContent propagates ThoughtSignature (model output), while FunctionResultContent does not (user input).

tests/GenerativeAI.Microsoft.Tests/MicrosoftExtension_Tests.cs (4)

313-336: LGTM! Comprehensive test for FunctionCallContent ThoughtSignature propagation.

The test properly verifies that ThoughtSignature flows from Part to FunctionCallContent through AdditionalProperties.


338-362: LGTM! Proper verification of reverse conversion.

This test correctly verifies that ThoughtSignature flows from FunctionCallContent.AdditionalProperties back to Part.ThoughtSignature.


364-387: LGTM! Good coverage for TextContent ThoughtSignature propagation.

The test ensures ThoughtSignature is correctly propagated for text responses.


389-407: LGTM! Complete round-trip coverage for TextContent.

This test verifies the reverse conversion, ensuring ThoughtSignature is properly preserved in both directions.

@gunpal5 gunpal5 merged commit 2689062 into gunpal5:main Dec 5, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants