Skip to content

Preserve OpenAI tool call additional properties#6365

Closed
ultramancode wants to merge 1 commit into
spring-projects:mainfrom
ultramancode:fix/openai-tool-call-additional-properties
Closed

Preserve OpenAI tool call additional properties#6365
ultramancode wants to merge 1 commit into
spring-projects:mainfrom
ultramancode:fix/openai-tool-call-additional-properties

Conversation

@ultramancode

Copy link
Copy Markdown
Contributor

Fixes #6364

OpenAiChatModel currently drops additional properties attached to assistant tool calls while converting OpenAI SDK responses into Spring AI AssistantMessage.ToolCalls.

That breaks Gemini OpenAI-compatible tool-calling flows for models that require provider metadata such as:

tool_calls[].extra_content.google.thought_signature

to be sent back on the follow-up model call after tool execution. Without it, Gemini 3.x models can fail with:

Function call is missing a thought_signature in functionCall parts.

The OpenAI Java SDK already keeps these provider fields in _additionalProperties(). This PR carries the root tool-call additional properties through AssistantMessage metadata and restores them on the OpenAI SDK request object when conversation history is replayed.

I also checked several Gemini OpenAI-compatible response shapes, including gemini-2.5-flash-lite and gemini-3.5-flash, covering responses with and without thought_signature. When no additional properties are present, nothing extra is replayed.

There is no Gemini-specific handling here.
Spring AI only replays additional fields that were already present in the provider response.

Signed-off-by: Taewoong Kim <ktw2172@gmail.com>
@ultramancode ultramancode force-pushed the fix/openai-tool-call-additional-properties branch from 7b3f30b to 9e71de2 Compare June 9, 2026 16:18
@sdeleuze

Copy link
Copy Markdown
Contributor

@ultramancode Please add a related integration test that fails when the fix is not present.

@ilayaperumalg ilayaperumalg self-assigned this Jun 10, 2026
@tzolov

tzolov commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@ultramancode , can you point us to where the OpenAI API spec defines additionalProperties: https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create ?
If it is not part of the OpenAI Spec then it is an issue with the Google OpenAI support i guess not with Spring AI

@ultramancode

Copy link
Copy Markdown
Contributor Author

I replied with more context in #6364.

If this still seems like the right direction, I can add the requested integration test.

@tzolov tzolov self-assigned this Jun 10, 2026
tzolov added a commit that referenced this pull request Jun 10, 2026
Additional properties from each tool-call object are serialised to
a JSON string (keyed by `tool_call_id`) and stored in `AssistantMessage`
metadata.
When the conversation is replayed, the properties are deserialised and
restored via `putAllAdditionalProperties` on the SDK request builder.
The fix is provider-neutral and covers both sync and streaming paths.
Reference doc is updated and tests are added

Fixes #6364

Signed-off-by: Taewoong Kim <ktw2172@gmail.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
@tzolov

tzolov commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Thanks @ultramancode , I've made some optimizations and merged it

@tzolov

tzolov commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

rebased, optimized, squashed and merged at 798d433

@tzolov tzolov closed this Jun 10, 2026
@tzolov tzolov added this to the 2.0.0 milestone Jun 10, 2026
@ultramancode

Copy link
Copy Markdown
Contributor Author

Thanks for taking care of this!

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.

OpenAiChatModel drops tool-call additional properties, causing Gemini thought_signature 400

4 participants