Skip to content

fix(provider): serialize Gemini thinking levels correctly - #9899

Open
JosephTian876 wants to merge 1 commit into
AstrBotDevs:masterfrom
JosephTian876:fix/gemini-thinking-config
Open

fix(provider): serialize Gemini thinking levels correctly#9899
JosephTian876 wants to merge 1 commit into
AstrBotDevs:masterfrom
JosephTian876:fix/gemini-thinking-config

Conversation

@JosephTian876

@JosephTian876 JosephTian876 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Gemini 3 thinking levels are currently assigned through a class-level fallback on types.ThinkingConfig. On the first request this can leave the Pydantic instance without a serialized thinking_level, while also mutating SDK class state for later requests. In addition, Gemini 3.7 Flash does not accept MINIMAL and should use its supported MEDIUM fallback.

Modifications / 改动点

  • Pass types.ThinkingLevel directly to the ThinkingConfig constructor so every request serializes its own value.

  • Keep case-insensitive validation for Gemini 3 models.

  • Use MEDIUM when Gemini 3.7 receives MINIMAL or another unsupported value; retain the existing HIGH fallback for other Gemini 3 variants.

  • Add regressions proving two consecutive requests both serialize HIGH and Gemini 3.7 maps MINIMAL to MEDIUM.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

# Locked project SDK: google-genai 2.20.0
pytest tests/test_gemini_source.py
9 passed

# Declared minimum SDK compatibility: google-genai 1.56.0
uv run --with google-genai==1.56.0 --no-sync \
  python -m pytest tests/test_gemini_source.py
9 passed

ruff format --check .
502 files already formatted

ruff check .
All checks passed!

No dependency or API-schema change is introduced. This PR intentionally does not add a Gemini-local retry for empty STOP responses: #7104 already handles empty model output in the shared runner, and another provider-local retry would multiply retry attempts.


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc. / Not applicable: this is a bug fix and adds no user-facing feature.
  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 My changes do not introduce malicious code.

Summary by Sourcery

Fix Gemini thinking-level serialization and validation across supported Gemini 3 models.

Bug Fixes:

  • Serialize Gemini thinking levels independently for every request and apply model-specific fallbacks, including mapping unsupported Gemini 3.7 Flash values to MEDIUM.

Tests:

  • Add regression coverage for repeated HIGH-level serialization and Gemini 3.7 MINIMAL fallback behavior.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant