Skip to content

Python: feat: add thinking_level support for Gemini in Python#13959

Open
markmcd wants to merge 4 commits intomicrosoft:mainfrom
markmcd:gemini-thinking
Open

Python: feat: add thinking_level support for Gemini in Python#13959
markmcd wants to merge 4 commits intomicrosoft:mainfrom
markmcd:gemini-thinking

Conversation

@markmcd
Copy link
Copy Markdown

@markmcd markmcd commented May 7, 2026

Motivation and Context

Allow users to exercise control over how much they are willing to spend in terms of response latency and token budgets.

fixes: #13955

Description

Follows the same terminology and structure as used in the upstream API. Users provide an optional thinking_level param that is plumbed through to the genai SDK.

I have not added support for thinking_budget, which takes an integer, as it's not supported by newer models and will not be supported going forward. I have not updated the Vertex code path either as that's marked as deprecated in this library.

This matches the .NET implementation

Contribution Checklist

Copilot AI review requested due to automatic review settings May 7, 2026 09:03
@markmcd markmcd requested a review from a team as a code owner May 7, 2026 09:03
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label May 7, 2026
@github-actions github-actions Bot changed the title feat: add thinking_level support for Gemini in Python Python: feat: add thinking_level support for Gemini in Python May 7, 2026
@markmcd markmcd force-pushed the gemini-thinking branch from c44278d to 973e13c Compare May 7, 2026 09:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for configuring Gemini “thinking level” in the Python Google AI connector by introducing a thinking_level execution setting and mapping it to the GenAI SDK’s expected thinking_config request shape.

Changes:

  • Added thinking_level to GoogleAIPromptExecutionSettings.
  • Overrode prepare_settings_dict() to map thinking_levelthinking_config.thinking_level.
  • Added unit tests covering the new field and the mapping behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
python/semantic_kernel/connectors/ai/google/google_ai/google_ai_prompt_execution_settings.py Adds thinking_level setting and maps it into thinking_config for requests.
python/tests/unit/connectors/ai/google/google_ai/test_google_ai_request_settings.py Adds unit tests for thinking_level storage and mapping into the request dict.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

temperature: Annotated[float | None, Field(ge=0.0, le=2.0)] = None
top_p: float | None = None
top_k: int | None = None
thinking_level: Literal["minimal", "low", "medium", "high"] | str | None = None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Personally I prefer the | str option for forward-compatibility, while still enabling completions from the Literal, but happy to defer to maintainer style on this one.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 81%

✓ Correctness

The PR correctly adds thinking_level support for Google AI by defining the field on the base settings class and overriding prepare_settings_dict to remap it into the thinking_config structure expected by the Google GenAI SDK. The implementation is consistent with how other config fields (like tool_config) are handled in this codebase. No correctness issues found.

✓ Security Reliability

This PR adds a thinking_level field to Google AI settings and overides prepare_settings_dict to map it into the thinking_config structure expected by the Google SDK. The implementation is straightforward and low-risk. The value is passed as a structured parameter to the SDK (not interpolated into strings), so there's no injection risk. The | str in the type annotation disables Pydantic's Literal validation but appears intentional for forward-compatibility with future API levels. No resource leaks, unsafe deserialization, secrets, or unhandled failure modes are introduced.

✓ Test Coverage

The PR adds two unit tests that cover setting thinking_level and verifying the prepare_settings_dict mapping. While these cover the happy path, there are minor gaps: no test for the None/default case in prepare_settings_dict (ensuring thinking_config is absent), and no update to the existing default settings test to verify thinking_level defaults to None. The existing test_create_options implicitly exercises the None path through inheritance but doesn't explicitly assert thinking_config absence.

✓ Design Approach

I did not find a design-level issue that meets the evidence bar. The change introduces thinking_level on the Google AI prompt settings and remaps it into thinking_config at request-construction time, which is consistent with how the Google AI text/chat services consume prepare_settings_dict() before building GenerateContentConfigDict.


Automated review by markmcd's agents

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

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Python: New Feature: Add thinking_level to Gemini connector

3 participants