Feature: Support third-party model strings like groq/model-id via a ServiceLoader SPI
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Please make sure you read the contribution guide and file the issues in the right place.
Contribution guide.
🔴 Required Information
Is your feature request related to a specific problem?
Yes. ADK Java has no convention-based way to resolve a model name string to a third-party
backend. The official bridges (contrib/langchain4j, contrib/spring-ai) cover many
providers, but agents receive constructed model objects — the string form
(.model("groq/<model-id>")) does not resolve through them. The only native mechanism for
string resolution today is calling LlmRegistry.registerLlm(pattern, factory) manually in
every application before any agent is built.
Python ADK gets zero-code provider switching via LiteLLM — a model string from config resolves
at runtime. Java has no equivalent, which hurts:
- Multi-agent cost optimization — assigning different models to different agents in one
pipeline (Gemini where its built-in tools are needed, fast hosted models for generation,
local Ollama for lightweight steps) currently requires provider construction code in every
application. - Configuration-driven deployments — the model cannot be swapped via config alone; a code
change and rebuild are required. - Local development — using Ollama offline should be a dependency swap, not code.
There is also a subtle correctness constraint any solution must respect. When an agent is
created with .model("groq/some-model"), that string is not what reaches the provider:
LlmRegistry calls the registered factory with the requested name, and the "model" field in
the outgoing request is whatever name the returned BaseLlm was constructed with
(Basic.java copies it into LlmRequest.model; ChatCompletionsRequest sends it verbatim).
Since providers accept only bare model IDs, pattern-based registration needs a name-aware
factory: build a distinct instance per requested name and strip the routing prefix before
construction, so the backend receives an ID it recognizes rather than "groq/some-model".
Describe the Solution You'd Like
A minimal SPI in ADK core (3 classes, no new dependencies), discovered via the standard
java.util.ServiceLoader mechanism:
ModelProvider— SPI interface:prefix()(routing namespace, e.g.groq) +
createFromBareModelName(name)→BaseLlm. A defaultcreate(name)strips the prefix, so
the backend always receives the bare model ID.ModelProviderRegistry—registerAll()discovers allModelProviderimplementations
on the classpath viaServiceLoaderand registers each with the existingLlmRegistry.
Providers that fail to instantiate are logged and skipped without affecting the rest.OpenAiCompatibleLlm— a thinBaseLlmover ADK's native
ChatCompletionsHttpClientfor anyPOST /v1/chat/completionsendpoint (Groq, Ollama,
OpenRouter, ...). Constructed with the bare model ID, which is what the
backend receives as the wire-format"model"field.
Usage — one explicit opt-in line, then model strings resolve from the classpath:
ModelProviderRegistry.registerAll();
LlmAgent agent =
LlmAgent.builder()
.name("assistant")
.model("groq/some-model") // resolved via the Groq provider JAR
.build();
A provider is a one-class JAR plus a META-INF/services/com.google.adk.models.ModelProvider
entry — no ADK changes needed to add new providers, ever:
public final class GroqModelProvider implements ModelProvider {
@Override public String prefix() { return "groq"; }
@Override public BaseLlm createFromBareModelName(String bareModelName) {
return new OpenAiCompatibleLlm(
bareModelName,
"https://api.groq.com/openai/v1",
Optional.ofNullable(System.getenv("GROQ_API_KEY")));
}
}
Deliberately out of scope (to keep the change small and uncontroversial): bundled provider
implementations, demo modules, and automatic registerAll() inside Runner/AdkWebServer
(explicit opt-in first; auto-registration can be a follow-up discussion).
Impact on your work
Impact Level: Medium
Not a hard blocker — everything here can be done today with manual LlmRegistry.registerLlm
calls. The cost is recurring friction: every ADK Java application re-implements the same
registration and prefix-stripping boilerplate to mix models per agent (Gemini where its
built-in tools are needed, hosted models like Groq/OpenRouter for generation, local Ollama for
lightweight steps).
The main benefit is to the ADK Java ecosystem: convention-based model selection lets Java
developers build multi-agent systems on any mix of hosted, free-tier, and local models by
changing only dependencies and configuration — no provider-specific Java code in the
application — matching the provider switching Python ADK users already get via LiteLLM and
closing a gap between the two SDKs.
Willingness to contribute
Yes — the implementation is complete and ready to submit:
- ✅ 3 core classes as described (no new dependencies; native
ChatCompletionsHttpClientpath) - ✅ 18 unit tests, all passing (
mvn -pl core test), including an end-to-end test that a
registered provider resolvesgroq/-style strings to an LLM carrying the bare model ID - ✅ google-java-format applied; follows existing
com.google.adk.modelsconventions - ✅ Verified end-to-end against live endpoints (Groq, OpenRouter) with external provider
JARs discovered viaServiceLoader, including streaming and tool calling
Can submit the PR immediately.
🟡 Recommended Information
Describe Alternatives You've Considered
- The official bridges —
contrib/langchain4jandcontrib/spring-ai(status quo) —
both solve implementation boilerplate but not discovery: agents receive a
constructed/injected model object, not a resolvable name string. This proposal addresses
the discovery gap for OpenAI-compatible endpoints; the bridges remain the path for other
providers. - Instance-based registration (e.g. the builder +
registerWithPatternconvenience
sketched in #1202) — a pre-built model object is registered directly. This proposal
registers factories instead:LlmRegistrypasses each requested name to the factory,
which strips the prefix and constructs an instance configured for exactly that model — so
any number of models can be used under one prefix (e.g.groq/llama-3.3-70b-versatileand
groq/gemma2-9b-itin the same pipeline) from a single registration. Happy to align the
two efforts in whichever direction maintainers prefer. - Manual
LlmRegistry.registerLlmcalls in each application — ADK's only native mechanism
for string resolution today. It works, but it is exactly the boilerplate this proposal
removes, and each application re-implements prefix stripping (or forgets to).
Additional Context
The native ChatCompletionsHttpClient path became fully viable for strict OpenAI-compatible
providers in ADK 1.6.0, when the JSON Schema serialization fixes landed (#1265/#1266).
- 主要语言
- Java
- 星标
- 1.7k
- 派生
- 433
- 平均合并
- 3 天 9 小时
- 30 天内合并 PR
- 46
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/adk-java 的其他 Issue
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filters可能已有人在做 @hemasekhar-p 于 2 天前认领。 未关闭needs review
难度 2/5 1-3 小时 新手友好度 76/100
google/adk-java#1628 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[spring-ai] ToolConverter silently drops enum and items from tool parameter schemas可能已有人在做 @hirematha 于 5 天前认领。 未关闭needs review
难度 2/5 1-3 小时 新手友好度 76/100
google/adk-java#1609 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[spring-ai] Streaming responses ending with CJK punctuation (。!?) are misclassified as partial and never persisted to the session可能已有人在做 @hirematha 于 5 天前认领。 未关闭needs review
难度 2/5 1-3 小时 新手友好度 84/100
google/adk-java#1608 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
FirestoreSessionService loses event fields on reload, breaking later turns and tool confirmations可能已有人在做 @innoprej 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 22/100
维护者通常 1 天内回复
-
Claude model throws UnsupportedOperationException("Not supported yet.") on thinking blocks from Claude 5 models可能已有人在做 @hemasekhar-p 于 2 天前认领。 未关闭needs review
google/adk-java#1630 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
enhancement good first issue
难度 2/5 半天 新手友好度 66/100
apache/fineract-consumer-facing#175 ·
维护者通常 1 天内回复
-
[BUG] 订单:会员凭订单号即可取消其他会员的待付款订单(取消接口不校验订单归属)可能已有人在做 @dadiyang 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
macrozheng/mall#1016 ·
-
[Bug] The producer summary counts an unreported client version as a second version and warns about a version mix可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
apache/rocketmq-dashboard#6110 ·
维护者通常 4 天内回复
-
Feature:Resolution
难度 2/5 1-3 小时 新手友好度 72/100
intellij-elixir/intellij-elixir#4396 ·
维护者通常 1 天内回复
-
Python 3.15 support可能已有人在做 @amnesiaof 今天认领。 未关闭L: python L: python:uv
难度 2/5 1-3 小时 新手友好度 72/100
dependabot/dependabot-core#16524 · 1 条评论 ·
维护者通常 1 天内回复