Skip to content

Python: Fix Gemini client support for Gemini API and Vertex AI#5258

Open
eavanvalkenburg wants to merge 4 commits intomicrosoft:mainfrom
eavanvalkenburg:gemini_vertex
Open

Python: Fix Gemini client support for Gemini API and Vertex AI#5258
eavanvalkenburg wants to merge 4 commits intomicrosoft:mainfrom
eavanvalkenburg:gemini_vertex

Conversation

@eavanvalkenburg
Copy link
Copy Markdown
Member

Motivation and Context

This update fixes the Python Gemini connector so it works with both google-genai connection modes: the Gemini Developer API and Vertex AI. It also addresses follow-up issues that showed up in the Gemini samples when switching models and when using Gemini built-in tools.

Description

  • add SDK-aligned Google settings alongside the connector aliases so GeminiChatClient can resolve either Gemini Developer API or Vertex AI configuration
  • make the SDK-style GOOGLE_* values lead when both namespaces are present, including support for GOOGLE_MODEL
  • preserve Gemini thought_signature data across tool-call round trips so tool-enabled conversations continue to work with newer reasoning-capable models
  • resolve the effective service URL from the instantiated google-genai client instead of hardcoding endpoints
  • fix core tool serialization for Gemini built-in tool specs so the samples no longer emit the Can't parse tool. warning
  • refresh Gemini sample docs/comments so the sample set is complete and consistent with the repository guidance

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 18:58
@eavanvalkenburg eavanvalkenburg changed the title Fix Gemini client support for Gemini API and Vertex AI Python: Fix Gemini client support for Gemini API and Vertex AI Apr 14, 2026
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

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the Python Gemini connector to support both google-genai connection modes (Gemini Developer API and Vertex AI), aligns environment variable handling with the SDK-style GOOGLE_* settings, and fixes tool/thinking metadata handling so the samples and tool loops behave correctly with newer Gemini models.

Changes:

  • Add GoogleGeminiSettings and update GeminiChatClient/RawGeminiChatClient to prefer GOOGLE_* settings, support Vertex AI configuration, and resolve the service URL from the instantiated genai.Client.
  • Preserve thought_signature across tool-call round trips and improve tool serialization to handle Pydantic tool models.
  • Refresh tests and sample docs to reflect the new configuration options and behaviors.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
python/packages/gemini/agent_framework_gemini/_chat_client.py Adds Google/Vertex settings, service URL resolution, Vertex AI options, and thought signature preservation in tool calls.
python/packages/gemini/agent_framework_gemini/init.py Exports GoogleGeminiSettings from the package.
python/packages/gemini/tests/test_gemini_client.py Adds env precedence and Vertex AI tests; updates integration-test skipping logic; adds thought_signature regression test.
python/packages/core/agent_framework/_tools.py Extends tool serialization to support Pydantic BaseModel specs via model_dump().
python/packages/core/tests/core/test_tools.py Adds a regression test covering Pydantic tool spec serialization.
python/packages/gemini/samples/*.py Updates sample prerequisites/comments and adds inline “Sample output” blocks.
python/packages/gemini/samples/README.md Documents both Gemini Developer API and Vertex AI environment variable options and how to run samples.
python/packages/gemini/README.md Documents both auth modes and corresponding env vars.
python/packages/gemini/AGENTS.md Updates package description and lists GoogleGeminiSettings.
python/packages/gemini/samples/init.py Adds copyright header.

Comment thread python/packages/gemini/agent_framework_gemini/_chat_client.py Outdated
Comment thread python/packages/gemini/agent_framework_gemini/_chat_client.py
Comment thread python/packages/gemini/agent_framework_gemini/_chat_client.py Outdated
Comment thread python/packages/gemini/agent_framework_gemini/_chat_client.py Outdated
Comment thread python/packages/gemini/tests/test_gemini_client.py Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonbox3 moonbox3 added the documentation Improvements or additions to documentation label Apr 14, 2026
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Apr 14, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _tools.py9508790%190–191, 364, 366, 379, 404–406, 414, 432, 446, 453, 460, 483, 485, 492, 500, 539, 583, 587, 619–621, 623, 629, 674–676, 678, 701, 727, 731, 769–771, 775, 797, 912–918, 954, 966, 968, 970, 973–976, 997, 1001, 1005, 1019–1021, 1362, 1384, 1471–1477, 1606, 1610, 1656, 1717–1718, 1833, 1853, 1855, 1911, 1974, 2146–2147, 2167, 2223–2224, 2362–2363, 2430, 2435, 2442
packages/gemini/agent_framework_gemini
   _chat_client.py331199%375
TOTAL27724320188% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5602 20 💤 0 ❌ 0 🔥 1m 33s ⏱️

Comment thread python/packages/gemini/samples/README.md Outdated
Comment thread python/packages/gemini/agent_framework_gemini/_chat_client.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants