[spring-ai] Wrapping ChatModels without getOptions() override fail with ClassCastException when ADK tools are attached
I maintainer di solito rispondono entro 1 giorno
@hirematha ci sta già lavorando.
Dal 30/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 1.8k
- Fork
- 442
- Merge medio
- 3g 13h
- PR unite (30g)
- 95
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/adk-java
-
InMemorySessionService.appendEvent recreates a deleted sessionForse già presa @hirematha l’ha presa 5 giorni fa. Apertaneeds review
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
google/adk-java#1697 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Runner drops callbackContextData written in onUserMessageCallback when it resumes an invocationForse già presa @hirematha l’ha presa 5 giorni fa. Apertaneeds review
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
google/adk-java#1695 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
AgentExecutor ignores the A2A contextId when creating a session, so multi-turn conversations start over every turnForse già presa @hirematha l’ha presa 3 giorni fa. Apertaneeds review
google/adk-java#1718 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
McpToolset hangs silently for ~5 minutes per retry (3 retries) when stdio command is an npm shim ("npx") on WindowsForse già presa @hemasekhar-p l’ha presa 8 giorni fa. Apertaneeds review
google/adk-java#1686 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
runLive passes partial events to appendEvent and never aggregates text chunks, unlike ADK PythonForse già presa @hemasekhar-p l’ha presa 18 giorni fa. Apertaneeds review
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
google/adk-java#1648 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google/adk-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsExceptionForse già presa @jiteshkhatri11 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
javapathfinder/jpf-core#660 · 1 commento ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
breaking change bug needs human review not ready priority medium size S
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
martin-francois/symphony-trello#1193 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno