Skip to content

fix(gemini): support Gemini 3/3.5 thinking config, thought separation, and reasoning token usage - #418

Open
zchryst wants to merge 1 commit into
andrewyng:mainfrom
zchryst:fix/gemini-3-5-thinking-and-usage
Open

zchryst wants to merge 1 commit into
andrewyng:mainfrom
zchryst:fix/gemini-3-5-thinking-and-usage

Conversation

@zchryst

@zchryst zchryst commented Oct 2, 2026

Copy link
Copy Markdown

Summary

Fixes three Gemini 3 / 3.5 thinking, context caching, and usage metadata issues in GeminiProvider (aisuite/providers/gemini_provider.py) and GoogleProvider (aisuite/providers/google_provider.py):

  1. ThinkingConfig Routing, cached_content Passthrough, and Thought Separation:
    • Added "thinking_config" and "cached_content" to CONFIG_KEYS in aisuite/providers/gemini_provider.py.
    • Added GeminiProvider._build_thinking_config() to translate reasoning_effort, thinking, thinking_level, thinking_budget, and include_thoughts kwargs into google.genai.types.ThinkingConfig, routing thinking_level for Gemini 3+ Flash/Pro (with "minimal" on Flash and "low" minimum on Pro) and thinking_budget for Gemini 2.5 (with regional prefix normalization such as au.gemini-3.5-flash).
    • Updated GeminiMessageConverter.parse_candidate() and convert_response() so thought parts (part.thought == True) are separated into Message.reasoning_content instead of being concatenated into Message.content.
    • Updated DEFAULT_TEMPERATURE in aisuite/providers/google_provider.py to None instead of forcing 0.7 on Gemini 3+ models.
  2. Usage Metadata (thoughts_token_count / reasoning_tokens):
    • Updated GeminiMessageConverter.get_completion_usage() to extract thoughts_token_count into CompletionTokensDetails(reasoning_tokens=...) and include (thoughts or 0) in the fallback total_tokens calculation.

Testing

  • Added unit tests in tests/providers/test_gemini_provider.py and tests/providers/test_google_provider.py covering thinking_config and cached_content routing across Gemini 3.5 Flash/Pro (including regional prefixes) and Gemini 2.5, thought part separation into reasoning_content, thoughts_token_count usage details, and default temperature.
  • Verified formatting with black --check and ran pytest (36 passed).

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