Skip to content

fix: preserve provider ChatOptions type to prevent ClassCastException - #1337

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_944453292
Jul 9, 2026
Merged

fix: preserve provider ChatOptions type to prevent ClassCastException#1337
copybara-service[bot] merged 1 commit into
mainfrom
test_944453292

Conversation

@copybara-service

Copy link
Copy Markdown

fix: preserve provider ChatOptions type to prevent ClassCastException

Spring AI OpenAI 2.0.0 casts Prompt.getOptions() directly to OpenAiChatOptions in createRequest() and only substitutes the model's own options when the prompt options are null. ADK built a provider-neutral DefaultToolCallingChatOptions whenever tools or generation config were present, so tool-enabled (and config-carrying) requests failed at runtime with:
java.lang.ClassCastException: DefaultToolCallingChatOptions cannot be cast to OpenAiChatOptions.

Build the prompt options on top of the model's own default options
(ChatModel.getOptions()) via mutate(), overlaying the ADK tools and generation config. This keeps the concrete provider type the model expects and preserves provider settings such as API key, base URL, and model name. Falls back to the previous provider-neutral behavior when the model's options are unavailable or not tool-calling capable.

@copybara-service
copybara-service Bot force-pushed the test_944453292 branch 2 times, most recently from 327fd0c to 66c1989 Compare July 9, 2026 09:59
Spring AI OpenAI 2.0.0 casts `Prompt.getOptions()` directly to `OpenAiChatOptions` in `createRequest()` and only substitutes the model's own options when the prompt options are null. ADK built a provider-neutral `DefaultToolCallingChatOptions` whenever tools or generation config were present, so tool-enabled (and config-carrying) requests failed at runtime with:
  `java.lang.ClassCastException: DefaultToolCallingChatOptions cannot be cast to OpenAiChatOptions`.

Build the prompt options on top of the model's own default options
(`ChatModel.getOptions()`) via `mutate()`, overlaying the ADK tools and generation config. This keeps the concrete provider type the model expects and preserves provider settings such as API key, base URL, and model name. Falls back to the previous provider-neutral behavior when the model's options are unavailable or not tool-calling capable.

PiperOrigin-RevId: 945007278
@copybara-service
copybara-service Bot merged commit 5c3d328 into main Jul 9, 2026
@copybara-service
copybara-service Bot deleted the test_944453292 branch July 9, 2026 10:07
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