Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

[spring-ai] Wrapping ChatModels without getOptions() override fail with ClassCastException when ADK tools are attached

未關閉
#1,731 0 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 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:

  1. SpringAI.resolveDefaultOptions() returns the model's getOptions() — for wrappers, the interface default: an empty DefaultChatOptions, not null, so the existing null handling never engages;
  2. MessageConverter.buildChatOptions(...) sees defaults that are not ToolCallingChatOptions and falls into the hasTools branch, building provider-neutral ToolCallingChatOptions;
  3. Provider models that cast Prompt.getOptions() to their own type — e.g. OpenAiChatModel.createRequest(...) casting to OpenAiChatOptions — throw ClassCastException: 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 resolveDefaultOptions hardening)
  • 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 小時
30 天內合併 PR
95

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

google/adk-java 的其他 Issue

查看 google/adk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。