Skip to content

Conversation

@codxse
Copy link

@codxse codxse commented Dec 16, 2025

Fixes #521

Gemini 3 Pro models require thought_signature to be preserved and returned during multi-turn function calling conversations. Without this, the API returns an error:

"Function call is missing a thought_signature in functionCall parts."

Changes:

  • Add thought_signature attribute to ToolCall class
  • Extract thoughtSignature from Gemini API responses in extract_tool_calls
  • Include thoughtSignature in functionCall parts via format_tool_call
  • Include thoughtSignature in functionResponse parts via format_tool_result
  • Update MessageFormatter to store and pass signature metadata

This is backward compatible - works with Gemini 2.5 (where signatures are optional) and other providers (which don't use thought signatures).

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

What this does

Adds support for Gemini 3's thoughtSignature feature in function calling. Thought signatures are encrypted representations of the model's internal thought process that must be preserved across multi-turn conversations when using tools.

The implementation:

  1. Captures thoughtSignature from Gemini API responses when extracting tool calls
  2. Stores the signature in the ToolCall object
  3. Includes it back in functionCall parts when replaying conversation history
  4. Includes it in functionResponse parts when returning tool results

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

New: ToolCall#thought_signature attribute (optional, defaults to nil)

Related issues

Fixes #521

…ling

Fixes crmne#521

Gemini 3 Pro models require thought_signature to be preserved and
returned during multi-turn function calling conversations. Without
this, the API returns an error:

"Function call is missing a thought_signature in functionCall parts."

Changes:
- Add thought_signature attribute to ToolCall class
- Extract thoughtSignature from Gemini API responses in extract_tool_calls
- Include thoughtSignature in functionCall parts via format_tool_call
- Include thoughtSignature in functionResponse parts via format_tool_result
- Update MessageFormatter to store and pass signature metadata

This is backward compatible - works with Gemini 2.5 (where signatures
are optional) and other providers (which don't use thought signatures).

See: https://ai.google.dev/gemini-api/docs/thought-signatures
@codxse codxse marked this pull request as draft December 16, 2025 14:30
@codxse codxse marked this pull request as ready for review December 16, 2025 20:20
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.

[BUG] Gemini-3-Pro-Preview: Function call missing thought_signature

1 participant