Skip to content

Commit e313723

Browse files
markwallace-microsoftrogerbarreto
authored andcommitted
.Net: Extend sample to show how to use MCP Tools from an Agent (microsoft#11361)
### Motivation and Context Extend the sample to show how to use MCP Tools from an Agent. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Roger Barreto <[email protected]>
1 parent 76294a5 commit e313723

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

dotnet/samples/Demos/ModelContextProtocolPlugin/ModelContextProtocolPlugin.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<ProjectReference Include="..\..\..\src\Agents\Abstractions\Agents.Abstractions.csproj" />
23+
<ProjectReference Include="..\..\..\src\Agents\Core\Agents.Core.csproj" />
2224
<ProjectReference Include="..\..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />
2325
<ProjectReference Include="..\..\..\src\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
2426
<ProjectReference Include="..\..\..\src\SemanticKernel.Core\SemanticKernel.Core.csproj" />

dotnet/samples/Demos/ModelContextProtocolPlugin/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Logging;
66
using Microsoft.SemanticKernel;
7+
using Microsoft.SemanticKernel.Agents;
78
using Microsoft.SemanticKernel.Connectors.OpenAI;
89
using ModelContextProtocol;
910
using ModelContextProtocol.Client;
@@ -70,3 +71,16 @@
7071
var prompt = "Summarize the last four commits to the microsoft/semantic-kernel repository?";
7172
var result = await kernel.InvokePromptAsync(prompt, new(executionSettings)).ConfigureAwait(false);
7273
Console.WriteLine($"\n\n{prompt}\n{result}");
74+
75+
// Define the agent
76+
ChatCompletionAgent agent = new()
77+
{
78+
Instructions = "Answer questions about GitHub repositories.",
79+
Name = "GitHubAgent",
80+
Kernel = kernel,
81+
Arguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
82+
};
83+
84+
// Respond to user input, invoking functions where appropriate.
85+
ChatMessageContent response = await agent.InvokeAsync("Summarize the last four commits to the microsoft/semantic-kernel repository?").FirstAsync();
86+
Console.WriteLine($"\n\nResponse from GitHubAgent:\n{response.Content}");

0 commit comments

Comments
 (0)