Skip to content
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

.Net: Extend sample to show how to use MCP Tools from an Agent #11361

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Agents\Abstractions\Agents.Abstractions.csproj" />
<ProjectReference Include="..\..\..\src\Agents\Core\Agents.Core.csproj" />
<ProjectReference Include="..\..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />
<ProjectReference Include="..\..\..\src\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
<ProjectReference Include="..\..\..\src\SemanticKernel.Core\SemanticKernel.Core.csproj" />
Expand Down
21 changes: 21 additions & 0 deletions dotnet/samples/Demos/ModelContextProtocolPlugin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using ModelContextProtocol;
using ModelContextProtocol.Client;
Expand Down Expand Up @@ -70,3 +71,23 @@
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}");

// Define the agent
ChatCompletionAgent agent =
new()
{
Instructions = "Answer questions about GitGub repositories.",
Name = "GitHubAgent",
Kernel = kernel,
Arguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
};

/// Create the chat history thread to capture the agent interaction.
AgentThread thread = new ChatHistoryAgentThread();

// Respond to user input, invoking functions where appropriate.
Console.WriteLine("\n\nResponse from GitHubAgent:");
await foreach (ChatMessageContent response in agent.InvokeAsync("Summarize the last four commits to the microsoft/semantic-kernel repository?", thread))
{
Console.WriteLine(response.Content);
}
Loading