Skip to content

.Net: Bug: Sample fails after switching to AddGoogleAIGeminiChatCompletion #11629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bradyoo12 opened this issue Apr 17, 2025 · 0 comments
Open
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@bradyoo12
Copy link

bradyoo12 commented Apr 17, 2025

Describe the bug
I was following https://devblogs.microsoft.com/semantic-kernel/integrating-model-context-protocol-tools-with-semantic-kernel-a-step-by-step-guide/.
kernel.Plugins.AddFromFunctions("GitHub", tools.Select(aiFunction => aiFunction.AsKernelFunction()));
worked well until I change AddOpenAIChatCompletion to AddGoogleAIGeminiChatCompletion and its parameter values.
With AddGoogleAIGeminiChatCompletion, the response that should be about the latest commits on Github is about those commited about one year ago. It is not calling a function but just making up using the data in LLM.

To Reproduce
Steps to reproduce the behavior:

  1. Install the followings in Nuget package: ModelContextProtocol (0.1.0-preview.10), Microsoft.SemanticKernel (1.47.0), Microsoft.SemanticKernel.Connectors.Google (1.47.0-alpha)
  2. Run the followings
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Google;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol.Transport;

#pragma warning disable SKEXP0070
#pragma warning disable SKEXP0001

// Prepare and build kernel
var builder = Kernel.CreateBuilder();
#region AzureOpenAI
/*
builder.Services.AddAzureOpenAIChatCompletion(
    deploymentName: Credential.AzureOpenAI.ModelId,
    endpoint: Credential.AzureOpenAI.Endpoint,
    apiKey: Credential.AzureOpenAI.ApiKey);
OpenAIPromptExecutionSettings executionSettings = new()
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(options: new() { RetainArgumentTypes = true })
};
*/
#endregion

#region GoogleAIGemini
builder.Services.AddGoogleAIGeminiChatCompletion(
    Credential.GoogleAIGemini.ModelId,
    Credential.GoogleAIGemini.ApiKey
);
GeminiPromptExecutionSettings executionSettings = new()
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(options: new() { RetainArgumentTypes = true }), // shows '2024 commits'
    //ToolCallBehavior = GeminiToolCallBehavior.AutoInvokeKernelFunctions // 400 bad request
};
#endregion

Kernel kernel = builder.Build();


// Create an MCPClient for the GitHub server
await using IMcpClient mcpClient = await McpClientFactory.CreateAsync(new StdioClientTransport(new()
{
    Name = "GitHub",
    Command = "npx",
    Arguments = ["-y", "@modelcontextprotocol/server-github"],
}));

var tools = await mcpClient.ListToolsAsync().ConfigureAwait(false);
kernel.Plugins.AddFromFunctions("GitHub", tools.Select(aiFunction => aiFunction.AsKernelFunction()));

var prompt = "Summarize the last four commits to the microsoft/semantic-kernel repository?";
var result = await kernel.InvokePromptAsync(prompt, new(executionSettings)).ConfigureAwait(false);
Console.WriteLine($"\n\n{prompt}\n{result}");
Console.ReadLine();

Expected behavior
A response should include the latest 4 commits of microsoft/semantic-kernel repository.

Screenshots

Image

Platform

  • Language: C#
  • Source: dotnet add package Microsoft.SemanticKernel.Connectors.Google, dotnet add package ModelContextProtocol --prerelease
  • AI model: gemini-2.5-pro-preview-03-25
  • IDE: Visual Studio 2022
  • OS: Windows
@bradyoo12 bradyoo12 added the bug Something isn't working label Apr 17, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Apr 17, 2025
@github-actions github-actions bot changed the title Bug: .Net: Bug: Apr 17, 2025
@markwallace-microsoft markwallace-microsoft changed the title .Net: Bug: .Net: Bug: Sample fails after switching to AddGoogleAIGeminiChatCompletion Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Bug
Development

No branches or pull requests

3 participants