[spring-ai] Wrapping ChatModels without getOptions() override fail with ClassCastException when ADK tools are attached
メンテナーはふだん 1 日以内に返信
@hirematha がすでに取り組んでいます。
2026年10月30日 から。
評価
この issue はまだ評価されていません。
説明
Describe the Bug
When the configured ChatModel is a delegating/wrapping implementation that does not override getOptions() (the interface default returns an empty DefaultChatOptions), any ADK request with tools fails with a bare ClassCastException deep inside the provider model.
Chain:
SpringAI.resolveDefaultOptions()returns the model'sgetOptions()— for wrappers, the interface default: an emptyDefaultChatOptions, not null, so the existing null handling never engages;MessageConverter.buildChatOptions(...)sees defaults that are notToolCallingChatOptionsand falls into thehasToolsbranch, building provider-neutralToolCallingChatOptions;- Provider models that cast
Prompt.getOptions()to their own type — e.g.OpenAiChatModel.createRequest(...)casting toOpenAiChatOptions— throwClassCastException: DefaultToolCallingChatOptions cannot be cast to OpenAiChatOptions.
The failure surfaces several frames away from the cause and gives no hint that the wrapper's getOptions() is the origin. We hit this in production with a failover wrapper (2026-09-28): the non-streaming fallback path died on its first call.
Note the related hardening in resolveDefaultOptions() (avoiding the same cast by using the model's own options) covers the "options available" half; this report is the "defaults are the empty interface default" half.
To Reproduce
// Any delegating wrapper that forgets to override getOptions()
class ForgettingWrapper implements ChatModel, StreamingChatModel {
private final ChatModel delegate;
// call()/stream() delegate; getOptions() intentionally NOT overridden
}
SpringAI springAI = new SpringAI(new ForgettingWrapper(openAiChatModel));
springAI.generateContent(
LlmRequest.builder()
.contents(List.of(userContent("hello")))
.tools(Map.of("ping", pingTool)) // any ADK tool
.build(),
false);
// -> RuntimeException wrapping ClassCastException:
// DefaultToolCallingChatOptions cannot be cast to org.springframework.ai.openai.OpenAiChatOptions
(Verified with a probe test on current main: the wrapper's getOptions() returns DefaultChatOptions@..., instanceof ToolCallingChatOptions is false, and the cast fails exactly as above.)
Expected behavior
At minimum, an actionable warning/error at the bridge level naming the actual cause ("the wrapping model's getOptions() returns non-provider options; delegate it to the underlying model's options"), instead of a bare ClassCastException from inside the provider. Fail-fast would also be reasonable, except that dummy/test models legitimately use the same default — so we prototyped a WARN in MessageConverter.buildChatOptions (branch: https://github.com/google/adk-java/compare/main...caps-xia:adk-java:fix/wrapper-chatmodel-options-cce, 307 tests green) and are happy to open a PR if the direction sounds right.
Environment
- google/adk-java main (post the
resolveDefaultOptionshardening) - Spring AI 2.0.1, spring-ai-openai
Additional context
Wrapping/decorating ChatModels (failover, retry, caching, audit) are a common Spring AI pattern; any of them without an explicit getOptions() override hits this the moment ADK tools are attached. A one-line doc note in the SpringAI README ("wrappers must delegate getOptions()") would also help.
- 主要言語
- Java
- スター
- 1.8k
- フォーク
- 442
- 平均マージ
- 3日 13時間
- マージ済み PR(30日)
- 95
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/adk-java のほかの issue
-
InMemorySessionService.appendEvent recreates a deleted session対応中かも @hirematha が 5 日前に担当しました。 オープンneeds review
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
google/adk-java#1697 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Runner drops callbackContextData written in onUserMessageCallback when it resumes an invocation対応中かも @hirematha が 5 日前に担当しました。 オープンneeds review
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google/adk-java#1695 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
AgentExecutor ignores the A2A contextId when creating a session, so multi-turn conversations start over every turn対応中かも @hirematha が 3 日前に担当しました。 オープンneeds review
google/adk-java#1718 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
McpToolset hangs silently for ~5 minutes per retry (3 retries) when stdio command is an npm shim ("npx") on Windows対応中かも @hemasekhar-p が 9 日前に担当しました。 オープンneeds review
google/adk-java#1686 · コメント 4 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
runLive passes partial events to appendEvent and never aggregates text chunks, unlike ADK Python対応中かも @hemasekhar-p が 18 日前に担当しました。 オープンneeds review
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
google/adk-java#1648 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
google/adk-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
build
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
MetricsHub/metricshub-community#1472 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsException対応中かも @jiteshkhatri11 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
javapathfinder/jpf-core#660 · コメント 1 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信