Skip to content

Implement thought_signature preservation in transformations#14

Open
felipebarcelospro wants to merge 1 commit intokiyo-e:mainfrom
felipebarcelospro:feature/gemini-3-thought-signatures
Open

Implement thought_signature preservation in transformations#14
felipebarcelospro wants to merge 1 commit intokiyo-e:mainfrom
felipebarcelospro:feature/gemini-3-thought-signatures

Conversation

@felipebarcelospro
Copy link

This commit adds full support for Gemini 3.0's thought_signature requirement in tool calling.

Changes:

  • Added transformOpenAIResponseToClaude() to capture thought_signature from Gemini responses
  • Added addThoughtSignaturesToToolResults() to inject signatures back into tool results

Problem

When using Gemini 3.0 models (gemini-3-flash-preview, gemini-3-pro-preview) with tool calling through the proxy, requests fail with a 400 error:

API Error: 400 {"error":"Function call is missing a thought_signature in functionCall parts..."}

Gemini 3.0 requires thought_signature to be preserved and returned with tool results for proper function calling flow. The current implementation doesn't capture or re-inject these signatures.

Solution

This PR adds full support for Gemini 3.0's thought_signature requirement:

Changes

  • Added transformOpenAIResponseToClaude(): Captures thought_signature from Gemini responses when tool_calls are present
  • Added addThoughtSignaturesToToolResults(): Injects stored signatures back into tool results before sending to Gemini
  • Signature storage: Uses a Map<string, string> structure (tool_call_id → signature) to preserve signatures across request/response cycles
  • Format handling: Supports both OpenAI format (role='tool') and Claude format (content.type='tool_result')

Testing

Tested with Gemini 3.0 Flash and Pro models with Claude Code using MCP tools. Tool calling now works without 400 errors.

Reference

Breaking Changes

None - these are additive functions that don't affect existing functionality.- Handles both OpenAI format (role='tool') and Claude format (content.type='tool_result')

This fixes the 400 error "Function call is missing a thought_signature" when using Gemini 3.0 models with tool calling.

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

This commit adds full support for Gemini 3.0's thought_signature requirement in tool calling.

Changes:
- Added transformOpenAIResponseToClaude() to capture thought_signature from Gemini responses
- Added addThoughtSignaturesToToolResults() to inject signatures back into tool results
- Signatures are preserved in a Map structure (tool_call_id -> signature)
- Handles both OpenAI format (role='tool') and Claude format (content.type='tool_result')

This fixes the 400 error "Function call is missing a thought_signature" when using Gemini 3.0 models with tool calling.

Reference: https://ai.google.dev/gemini-api/docs/thought-signatures
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.

1 participant