Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

Motivation and Context

Google.GenAI 0.11.0 now ships with an official IChatClient implementation via Client.AsIChatClient(modelId). This eliminates the need for our custom polyfill.

Description

  • Updated Google.GenAI package from 0.6.0 to 0.11.0
  • Removed custom GoogleGenAIChatClient.cs polyfill (~700 LOC)
  • Simplified extension methods to use the official API
// Before: Custom polyfill wrapper
services.AddSingleton<IChatClient>(new GoogleGenAIChatClient(googleClient, modelId));

// After: Official SDK method
services.AddSingleton<IChatClient>(googleClient.AsIChatClient(modelId));

Contribution Checklist

Original prompt

I need to add a new ChatClient service into the Google connector using a reference to the Google.GenAI library.

this implementation should use internal a polyfill of the IChatClient implementation, similar how was done in the sample from Microsoft Agent Framework here:

https://github.com/microsoft/agent-framework/blob/main/dotnet/samples/GettingStarted/AgentProviders/Agent_With_GoogleGemini/GeminiChatClient.cs

and here:

https://github.com/microsoft/agent-framework/blob/main/dotnet/samples/GettingStarted/AgentProviders/Agent_With_GoogleGemini/GoogleGenAIExtensions.cs

Also take note that I need to add some extra Extension methods similiar to the AddGoogleChatCompletion, which in this case will be AddGoogleChatClient extensions to both the IServiceCollection and IKernelBuilder.

Ensure this new extension methods are unit test covered.

One extra observation, Google.GenAI currently is only available to NET 8 and there's not support for NetStandard, so this new extensions should only be available for the NET 8+ targets with proper csproj conditionals and #if NET checks.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add ChatClient service to Google connector Add Google.GenAI ChatClient support with IChatClient polyfill Dec 3, 2025
Copilot AI requested a review from rogerbarreto December 3, 2025 12:45
@rogerbarreto
Copy link
Member

@copilot the Google.GenAI.Client type accepts bool vertexAI, I think we should also expose this argument in the extension methods that don't take the client directly.

Directory.Packages.Props should also consider the $(TargetFramework) == net9.0, as we also build for this.

Google.GenAI is already in the version 0.6.0, please update to the latest.

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot the Google.GenAI.Client type accepts bool vertexAI, I think we should also expose this argument in the extension methods that don't take the client directly.

Directory.Packages.Props sho...

Addressed in 1586f0e:

  • Added vertexAI parameter (default false) to AddGoogleAIChatClient extension methods that take apiKey directly
  • Updated Google.GenAI package to version 0.6.0 in Directory.Packages.props
  • Added net9.0 to the conditional package reference in Connectors.Google.csproj

@rogerbarreto
Copy link
Member

@copilot Remove any added [Experimental("SKEXP0070")] flag as this package is an alpha pre-release package and experimental API's are not needed to be flagged.

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot Remove any added [Experimental("SKEXP0070")] flag as this package is an alpha pre-release package and experimental API's are not needed to be flagged.

Removed all [Experimental("SKEXP0070")] attributes from the extension methods and tests in 238fcde.

@rogerbarreto
Copy link
Member

@copilot Now I need you to add similar set of unit tests in here GoogleAIGeminiChatCompletionServiceTests targeting the new GoogleChatClient, with name like GoogleGeminiChatClientTests

as well as integration tests similar targeting the new ChatClientService.
So basically for the IT, we need new GeminiChatClientTests.cs and a new GeminiFunctionCAllingChatClientTests.cs targeting the new client.

Keep in mind for the integration tests, Facts should be Theories accepting the IsVertexAI argument which will use the VertexAI API, otherwise would use the GenAI API.

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot Now I need you to add similar set of unit tests in here GoogleAIGeminiChatCompletionServiceTests targeting the new GoogleChatClient, with name like GoogleGeminiChatClientTests

as well as...

Added in 4f6c91c:

  • Unit tests: GoogleGeminiChatClientTests.cs in Connectors.Google.UnitTests/Services/
  • Integration tests: GeminiChatClientTests.cs and GeminiFunctionCallingChatClientTests.cs in IntegrationTests/Connectors/Google/Gemini/

All integration tests use [RetryTheory] with [InlineData(false)] and [InlineData(true)] for the isVertexAI parameter. Updated TestsBase.cs with GetChatClient(bool isVertexAI) method that uses the vertexAI parameter.

@rogerbarreto
Copy link
Member

@copilot I need to change a bit the strategy, actually the VertexAI and GenAI should be distinct extensions where the GenAI requires the ApiKey, VertexAI endpoint will expect instead of an apiKey an optional Google.Auth.ICredential? that if not provided, it passes as null to the Google.GenAI.Client that will use it's internal discovery impl to get from the environment.

Extension methods that accepts directly the Google.GenAI.Client don't need to change.

Suggested prefixes.
AddGoogleAIChatClient - extension methods that accepts the client as argument.
AddGoogleGenAIChatClient - extension methods that accepts the apiKey be prefixed as
AddGoogleVertexAIChatClient - extension methods that accepts (ICredential)

Update the unit tests accordingly, the integration tests can now be specific separate classes for each.

Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot I need to change a bit the strategy, actually the VertexAI and GenAI should be distinct extensions where the GenAI requires the ApiKey, VertexAI endpoint will expect instead of an apiKey an...

Addressed in c8be251:

Extension methods split:

  • AddGoogleGenAIChatClient - accepts apiKey for Google GenAI
  • AddGoogleVertexAIChatClient - accepts project, location, and optional Google.Apis.Auth.OAuth2.ICredential? for Vertex AI
  • AddGoogleAIChatClient - accepts Google.GenAI.Client directly (unchanged)

Unit tests updated with separate tests for each extension type.

Integration tests split into separate classes:

  • GeminiGenAIChatClientTests.cs / GeminiGenAIFunctionCallingChatClientTests.cs for GenAI
  • GeminiVertexAIChatClientTests.cs / GeminiVertexAIFunctionCallingChatClientTests.cs for VertexAI

@moonbox3 moonbox3 added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Dec 8, 2025
@github-actions github-actions bot changed the title Add Google.GenAI ChatClient support with IChatClient polyfill .Net: Add Google.GenAI ChatClient support with IChatClient polyfill Dec 8, 2025
@rogerbarreto
Copy link
Member

@copilot Please update the current polyfill Google.GenAI ChatClient implementation using the latest updates made to the ChatClient in here:

https://raw.githubusercontent.com/stephentoub/dotnet-genai/41d6cc2d3938e43b72faae5f5be6f99287486783/Google.GenAI/GoogleGenAIChatClient.cs

Copy link
Contributor Author

Copilot AI commented Dec 8, 2025

@copilot Please update the current polyfill Google.GenAI ChatClient implementation using the latest updates made to the ChatClient in here:

https://raw.githubusercontent.com/stephentoub/dotnet-gena...

Updated the GoogleGenAIChatClient polyfill with the latest implementation in 4f24c7a.

Key enhancements:

  • Added thought signature handling (s_skipThoughtValidation) for agentic scenarios
  • Added TextReasoningContent support for reasoning/thought content
  • Added hosted tools: HostedCodeInterpreterTool, HostedFileSearchTool, HostedWebSearchTool
  • Enhanced FunctionResultContent handling (AIContent, IEnumerable, TextContent)
  • Added CodeInterpreterToolCallContent and CodeInterpreterToolResultContent support
  • Added citation metadata handling with CitationAnnotation and TextSpanAnnotatedRegion
  • Added RawRepresentation handling for Part objects
  • Added DisplayName support for DataContent

@rogerbarreto rogerbarreto marked this pull request as ready for review December 10, 2025 18:29
@rogerbarreto rogerbarreto requested a review from a team as a code owner December 10, 2025 18:29
Copilot AI changed the title .Net: Add Google.GenAI ChatClient support with IChatClient polyfill .Net: Use official Google.GenAI IChatClient implementation Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants