Skip to content

Conversation

@shibu-web
Copy link
Contributor

Summary

  • Fix Gemini thought_signature not being preserved in multi-turn conversations with tool calls
  • Prioritize per-tool-call providerMetadata over overall response metadata in both streaming and non-streaming modes

Related Issues

Problem

When using Gemini models with thinking/reasoning enabled (e.g., gemini-3.0-pro-preview) through the AI SDK integration, the thought_signature field was not preserved across agent
loop iterations, causing subsequent API calls to fail with:

Function call is missing a thought_signature in functionCall parts.

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

Root Cause

  • Non-streaming mode: providerData was set to result.providerMetadata (overall response metadata containing usageMetadata, safetyRatings, etc.) instead of
    toolCall.providerMetadata (per-tool-call metadata containing thoughtSignature)
  • Streaming mode: providerData was not captured at all from tool-call parts

Changes

  • Non-streaming mode (aiSdk.ts ~line 714): Prioritize toolCall.providerMetadata with fallback to result.providerMetadata
  • Streaming mode (aiSdk.ts ~line 921): Capture part.providerMetadata as providerData

Test Plan

  • Tested with Gemini 3.0 Pro Preview
  • Verified multi-turn conversation with tool calls works correctly
  • Both streaming and non-streaming modes tested

When using Gemini models with thinking/reasoning enabled through the
  AI SDK integration, the thought_signature was not preserved across
  multi-turn conversations with tool calls.

  The issue was that providerData was using result.providerMetadata
  (overall response metadata) instead of toolCall.providerMetadata
  (per-tool-call metadata containing thoughtSignature).

  Changes:
  - Non-streaming mode: Prioritize toolCall.providerMetadata over
    result.providerMetadata for function_call outputs
  - Streaming mode: Capture part.providerMetadata and include it
    as providerData in function_call outputs

  Reference: https://ai.google.dev/gemini-api/docs/thought-signatures
  Related: openai/openai-agents-python#2137
@changeset-bot
Copy link

changeset-bot bot commented Dec 2, 2025

🦋 Changeset detected

Latest commit: 130ff1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openai/agents-extensions Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Thanks for sending this patch. The changes should be good to go. Can you add the following changes as well?

  • run pnpm changeset and create a changeset file with patch version bump
  • add new unit test cases covering the scenario to prevent future regressions

@seratch seratch added this to the 0.3.x milestone Dec 2, 2025
  - Add changeset for @openai/agents-extensions patch version bump
  - Add unit tests for per-tool-call providerMetadata preservation:
    - Non-streaming: prioritizes toolCall.providerMetadata
    - Non-streaming: falls back to result.providerMetadata
    - Streaming: captures part.providerMetadata as providerData
    - Streaming: omits providerData when not present
@seratch seratch added the enhancement New feature or request label Dec 2, 2025
@seratch seratch merged commit 870cc20 into openai:main Dec 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants