Repository navigation
Description
Describe the bug
The Gemini adapter builds ThinkingConfig using only the budget-era shape and sends it without any model awareness, so on newer Gemini versions requests either fail or cannot be configured at all. Three related gaps:
- No tri-state thinking switch in core —
GenerateOptionsonly hasthinkingBudgetandreasoningEffort(which the Gemini formatter ignores). There is no way to expressincludeThoughts: false(disable thinking) or athinkingLevel. - The formatter only emits the budget-era shape —
GeminiChatFormatter.applyOptionssendsincludeThoughts=true + thinkingBudgetwhenever a budget is set. On Gemini 4 models this shape is rejected by the API. - No Gemini 4 model gate — the Gemini module has no
gemini-4-*handling at all, so Gemini 4-specific behavior (thinkingLevelinstead of budget, output-token defaults) is missing.
Official Gemini documentation
- Thinking guide (formerly
ai.google.dev/gemini-api/docs/thinking) - generate-content API reference
Key statements:
thinkingLevel— "Controls the maximum depth of the model's internal reasoning process before it produces a response." / "Recommended for Gemini 3 or later models. Use with earlier models results in an error."thinkingConfig— "An error will be returned if this field is set for models that don't support thinking."includeThoughts— "Indicates whether to include thoughts in the response. If true, thoughts are returned only when available."thinkingBudget— "The number of thoughts tokens that the model should generate."- Thinking guide:
thinking_levelis the main control ("main control over quality, latency, and token use") with valuesminimal/low/medium/high/xhigh;minimalis "Not supported on Gemini 4 models orgemini-3.8-flash";gemini-4-carbon/gemini-4-argondefault tomedium,gemini-4-hydrogentohigh. - Gemini 4 limits:
max_output_tokenscounts thinking tokens and is a hard cutoff (finishes with statusincomplete); Gemini 4 has a shared 1M context window and a foreground default maximum of 65,536 output tokens for streaming (32,768 for Carbon/Argon non-streaming).
The docs do not spell out the budget-era vs Gemini 4 wire split; that behavior is captured by agentscope-python's implementation experience (PR #3523, merged 2026-10-29, for the tri-state switch; PR #3675, commit 3fef100e, for the Gemini 4 gate), which this issue proposes to match.
To Reproduce
On current main (2.1.0-SNAPSHOT):
// 1) Budget against a Gemini 4 model -> the API rejects thinking_budget
GeminiChatModel model = GeminiChatModel.builder()
.apiKey("...")
.modelName("gemini-4-argon")
.defaultOptions(GenerateOptions.builder().thinkingBudget(4096).build())
.build();
model.call(List.of(Msg.builder().role(MsgRole.USER).textContent("hi").build()), null, null);
// -> remote error: thinking_budget is rejected by Gemini 4
// 2) Zero budget against a budget-era model -> the API rejects a zero thinking budget
// (gemini-2.5-pro / gemini-3.1-pro-preview reject thinkingBudget=0; Python PR #3523 finding)
// 3) thinkingLevel cannot be expressed at all on main:
// GenerateOptions has no thinkingLevel field, and reasoningEffort is ignored by the Gemini formatterCurrent behavior (code locations, main @ 5525ac1)
agentscope-core/src/main/java/io/agentscope/core/model/GenerateOptions.java:47-48,244,256— onlythinkingBudget(Integer) andreasoningEffort(String, "o1 models" per its javadoc). NoincludeThoughts, nothinkingLevel.agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini/src/main/java/io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:121-130:
if (thinkingBudget != null) {
thinkingConfigBuilder.includeThoughts(true); // hard-coded
thinkingConfigBuilder.thinkingBudget(thinkingBudget);
configBuilder.thinkingConfig(thinkingConfigBuilder.build());
}- No
gemini-4/argon/carbonreference anywhere in the Gemini module. - The only related test (
GeminiChatModelTest.java:345-358) asserts the builder constructs; there are no wire-levelthinkingConfigassertions, so all of this passes CI. - The bundled google-genai SDK (
2.2.0on current main;1.80.0at the time this issue was first written) already exposesThinkingConfig.thinkingLevel(), so no SDK upgrade is needed.
Expected behavior / Proposed fix (parity with agentscope-python PR #3523 / agentscope-go RFC #164)
Add includeThoughts (Boolean, tri-state: null = omit) and thinkingLevel (String) to GenerateOptions — an additive, backward-compatible public API change — and gate the wire mapping on the model name:
| Case | thinkingConfig sent |
|---|---|
| no thinking option set | omitted entirely (model default) |
| budget-era model, enable | includeThoughts: true, thinkingBudget: <budget or 1024> |
| budget-era model, disable | includeThoughts: false, thinkingBudget: 0 |
| Gemini 4, enable | includeThoughts: true, thinkingLevel: <level> — no budget |
| Gemini 4, disable | includeThoughts: false — no budget, no level |
- Model gate: exactly
gemini-4-argonandgemini-4-carbon, mirroring Python_is_gemini_4. - Level validation: uppercase-normalized
LOW/MEDIUM/HIGH(Python's validated set; the documentedminimal/xhighcan be widened later additively). - Invalid combinations fail fast with a
Chat/ChatStreamerror before dispatch instead of surfacing as an opaque remote error: budget on Gemini 4, level on a budget-era model. - Separate follow-up candidate (out of scope of this issue's core fix): Gemini 4
max_output_tokenscap of 65,536 (Python_prepare_gemini_4_config).
Note on placement: Formatter.applyOptions has no model name (Formatter.java:96-97), so the gate needs to live in GeminiChatModel.buildGenerateContentConfig or the model name must be passed into the formatter.
Verification plan
Wire-fixture tests in the style of the existing Gemini formatter tests (no live API), written to fail on the unfixed base:
applyOptionsoutput asserted on the builtGenerateContentConfigfor each row of the table (nil omits, enable+budget, default 1024, disable, Gemini 4 level path, Gemini 4 disable)- Invalid combinations throw before dispatch (budget on Gemini 4, level on a budget-era model)
- Both buffered and streamed paths build the config through
buildGenerateContentConfig - Run
mvn -T1C -pl agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-gemini -am test, Spotless, and the full check sinceGenerateOptionsis a public contract change.
Related
- agentscope-go RFC [Feature]: MySQL Session IT #164: [RFC] Gemini thinking support end to end (item 12 of #138) agentscope-go#164
- agentscope-python PR 基于仓库的doc生成了一个更易读的学习文档 #3523 (merged 2026-10-29, tri-state
thinking_enable): feat(model): omit Gemini thinking_config unless thinking is explicitly configured agentscope#3523 - agentscope-python PR fix(model): generate unique ids for tool calls the provider sends without one #3675 (merged 2026-11-11, commit
3fef100e, Gemini 4 Argon/Carbon gate): feat(model): add Gemini 4 Argon and Carbon support agentscope#3675 - [Feature]: Gemini Thinking 增强 #2240 "[Feature]: Gemini Thinking 增强" and its open implementation PR feat(gemini): 支持 Gemini Thinking 并持久化 thought signature #2335 add
includeThoughts/thinkingLeveltoGenerateOptions, but feat(gemini): 支持 Gemini Thinking 并持久化 thought signature #2335's formatter has no model gate — budget and level are both sent when both are set, and unknown levels are forwarded with only a warning. This issue's fix should be coordinated with that PR.
Environment
- AgentScope-Java Version:
2.1.0-SNAPSHOT(main @5525ac1aa09e597042a259d581c51807e89bb0f5, 2026-11-16) - Java Version: 17
- OS: macOS (request-shaping bug, platform-independent)
Update (2026-11-17)
All three gaps were re-verified on the latest main (5525ac1aa, google-genai 2.2.0) — the SDK bump does not change them. Implementation is in progress on branch fix/4220-gemini-4-thinking-config based on that commit.
Plan
I will open a PR implementing the fix and the verification tests described above.
Activity
fix(gemini): route thinking config by model generation and fail fast …
fix(gemini): route thinking config by model generation and fail fast …
fix(gemini): route thinking config by model generation (agentscope-ai…