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: Feat: adds support for Copilot Agent Plugins in dotnet and other fixes. #9436

Merged
merged 60 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ee3312b
import implementation for TypeB
zengin May 1, 2024
8f9bd38
update the manifest package and address compiler warnings
zengin Jun 17, 2024
987c3bc
address compiler warnings
zengin Jun 18, 2024
b93e6ac
isolate runtimes in error handling
zengin Jun 18, 2024
b1320fe
Merge branch 'main' into chore/zengin-manifest
baywet Oct 22, 2024
177e126
chore: upgrades plugins library version
baywet Oct 22, 2024
99ac5cc
chore: updates api manifest dependency
baywet Oct 22, 2024
0a4fedd
Merge branch 'main' into chore/zengin-manifest
baywet Oct 22, 2024
f2ebca2
chore: formatting
baywet Oct 22, 2024
e33690a
chore: upgrades manifest lib to latest version
baywet Oct 22, 2024
6d462a8
Merge branch 'main' into chore/zengin-manifest
baywet Oct 24, 2024
a379579
ci: adds unit test infrastructure for microsoft manifest plugins
baywet Oct 24, 2024
c77eb72
ci: adds sample microsoft plugins
baywet Oct 24, 2024
20435c6
chore: adds kiota configuration for sample microsoft plugins
baywet Oct 24, 2024
8dd2906
fix: path to microsoft manifest plugin
baywet Oct 24, 2024
11d2391
fix: adds missing copy of microsoft manifests
baywet Oct 24, 2024
2c7cc8c
docs: adds link to microsoft manifest sample
baywet Oct 24, 2024
d47a812
fix: lookup path for the api and microsoft plugins
baywet Oct 24, 2024
c98cbcc
fix: loading of local microsoft manifest file
baywet Oct 24, 2024
529dc0d
fix: stream instead of string to load microsoft plugins
baywet Oct 24, 2024
d98ba29
fix: function name for microsoft plugins test data
baywet Oct 24, 2024
d435b51
fix: authentication for microsoft plugins
baywet Oct 25, 2024
65543ed
Merge branch 'main' into chore/zengin-manifest
baywet Oct 25, 2024
7fa549c
fix: restores wrongly deleted plugin in #6005
baywet Oct 25, 2024
814a45c
feat: adds astronomy plugin to kiota workspace configuration
baywet Oct 25, 2024
a6e9529
feat: adds astronomy plugin definition
baywet Oct 25, 2024
927723d
fix: nasa astronomy simple test
baywet Oct 25, 2024
882ed3b
feat: adds support for multiple microsoft plugins dependencies
baywet Oct 25, 2024
3e0c0c3
docs: adds experimental entry for Microsoft Manifests
baywet Oct 25, 2024
3471e31
fix: aligns experimental code with new numbering for api and microsof…
baywet Oct 25, 2024
2b7d722
chore: skip loading the json document ourselves
baywet Oct 25, 2024
b2c2ee4
fix: o(n) lookup to o(1) for operation ids to exclude
baywet Oct 25, 2024
0707600
fix: disposing response too early
baywet Oct 25, 2024
3b2c3c2
fix: multiple performance issues in API manifest loading
baywet Oct 25, 2024
5fdd657
fix: normalization operation id to avoid . in function names
baywet Oct 25, 2024
8871dcf
chore: linting
baywet Oct 25, 2024
93eb850
fix; netstandard2.0 build
baywet Oct 25, 2024
0fe5fa6
Merge branch 'main' into chore/zengin-manifest
baywet Oct 25, 2024
c8fa5fe
Merge branch 'main' into chore/zengin-manifest
baywet Nov 11, 2024
c554059
fix: wrong merge variable reference
baywet Nov 11, 2024
d571850
chore: post merge update of plugins manifest implementation
baywet Nov 11, 2024
a3650ba
fix: first wave of PR review comments
baywet Nov 11, 2024
43d044b
chore: fixes formatting
baywet Nov 11, 2024
f9d156a
Merge branch 'main' into chore/zengin-manifest
baywet Nov 13, 2024
79a9902
chore: moves kiota generation folder to a sub-directory
baywet Nov 13, 2024
907229b
chore: renames api and microsoft manifest tests
baywet Nov 13, 2024
0f991cc
chore: removes constructor for plugin parameters as per PR review gui…
baywet Nov 13, 2024
ff077f3
chore: updates namespace for api and microsoft manifest extensions
baywet Nov 13, 2024
cd6b2c6
chore: reverts formatting on csproj
baywet Nov 13, 2024
c50c22c
docs: adds doc comments to describe what tests do and how to run them
baywet Nov 13, 2024
5242e10
fix: local copy of nasa description since source is gone
baywet Nov 13, 2024
bfe2983
fix: disposal of response object
baywet Nov 13, 2024
5e4b31e
chore: fixes formatting
baywet Nov 13, 2024
f8b6501
Merge branch 'main' into chore/zengin-manifest
baywet Nov 13, 2024
ecbd60e
Merge branch 'main' into chore/zengin-manifest
baywet Nov 14, 2024
f6bcb2e
chore: replaces kiota workspace by generation instructions
baywet Nov 14, 2024
dd0112e
Merge branch 'main' into chore/zengin-manifest
baywet Nov 14, 2024
23474a3
chore: renames Microsoft Plugins to Copilot Agent Plugins
baywet Nov 14, 2024
bf3e1ec
fix: naming in doc comments
baywet Nov 14, 2024
635b595
Merge branch 'main' into chore/zengin-manifest
baywet Nov 15, 2024
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
2 changes: 1 addition & 1 deletion dotnet/docs/EXPERIMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You can use the following diagnostic IDs to ignore warnings or errors for a part
| SKEXP0040 | Markdown functions |
| SKEXP0040 | OpenAPI functions |
| SKEXP0040 | OpenAPI function extensions - API Manifest |
| SKEXP0040 | OpenAPI function extensions - Microsoft Manifest |
| SKEXP0040 | OpenAPI function extensions - Copilot Agent Plugin |
| SKEXP0040 | Prompty Format support |
| | | | | | | |
| SKEXP0050 | Core plugins |
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/Concepts/Concepts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@
</None>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Plugins\MicrosoftManifestPlugins\**\*.json">
<None Include="Resources\Plugins\CopilotAgentPlugins\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\Plugins\MicrosoftManifestPlugins\**\*.yml">
<None Include="Resources\Plugins\CopilotAgentPlugins\**\*.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Resources\Plugins\RepairServicePlugin\repair-service.json">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace Plugins;
/// <summary>
/// These examples demonstrate how to use MicrosoftManifest plugins to call Microsoft Graph and NASA APIs.
/// Microsoft Manifest plugins are created from the OpenAPI document and the manifest file.
/// These examples demonstrate how to use CopilotAgent plugins to call Microsoft Graph and NASA APIs.
/// Copilot Agent Plugin plugins are created from the OpenAPI document and the manifest file.
baywet marked this conversation as resolved.
Show resolved Hide resolved
/// The manifest file contains the API dependencies and their execution parameters.
/// The manifest file also contains the authentication information for the APIs, however this is not used by the extension method and MUST be setup separately at the moment, which the example demonstrates.
///
/// Important stages being demonstrated:
/// 1. Load MicrosoftManifest plugins
/// 1. Load CopilotAgent plugins
/// 2. Configure authentication for the APIs
/// 3. Call functions from the loaded plugins
///
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Plugins;
///
/// </summary>
/// <param name="output">The output helper to use to the test can emit status information</param>
public class MicrosoftManifestBasedPlugins(ITestOutputHelper output) : BaseTest(output)
public class CopilotAgentBasedPlugins(ITestOutputHelper output) : BaseTest(output)
{
public static readonly IEnumerable<object[]> s_parameters =
[
Expand All @@ -67,11 +67,11 @@ public class MicrosoftManifestBasedPlugins(ITestOutputHelper output) : BaseTest(
["AstronomyPlugin", "apod", new KernelArguments { { "_date", "2022-02-02" } }, "AstronomyPlugin"],
];
[Theory, MemberData(nameof(s_parameters))]
public async Task RunMicrosoftManifestPluginAsync(string pluginToTest, string functionToTest, KernelArguments? arguments, params string[] pluginsToLoad)
public async Task RunCopilotAgentPluginAsync(string pluginToTest, string functionToTest, KernelArguments? arguments, params string[] pluginsToLoad)
{
WriteSampleHeadingToConsole(pluginToTest, functionToTest, arguments, pluginsToLoad);
var kernel = new Kernel();
await AddMicrosoftManifestPluginsAsync(kernel, pluginsToLoad);
await AddCopilotAgentPluginsAsync(kernel, pluginsToLoad);

var result = await kernel.InvokeAsync(pluginToTest, functionToTest, arguments);
Console.WriteLine("--------------------");
Expand All @@ -82,12 +82,12 @@ public async Task RunMicrosoftManifestPluginAsync(string pluginToTest, string fu
private void WriteSampleHeadingToConsole(string pluginToTest, string functionToTest, KernelArguments? arguments, params string[] pluginsToLoad)
{
Console.WriteLine();
Console.WriteLine("======== [MicrosoftManifest Plugins Sample] ========");
Console.WriteLine("======== [CopilotAgent Plugins Sample] ========");
Console.WriteLine($"======== Loading Plugins: {string.Join(" ", pluginsToLoad)} ========");
Console.WriteLine($"======== Calling Plugin Function: {pluginToTest}.{functionToTest} with parameters {arguments?.Select(x => x.Key + " = " + x.Value).Aggregate((x, y) => x + ", " + y)} ========");
Console.WriteLine();
}
private async Task AddMicrosoftManifestPluginsAsync(Kernel kernel, params string[] pluginNames)
private async Task AddCopilotAgentPluginsAsync(Kernel kernel, params string[] pluginNames)
{
#pragma warning disable SKEXP0050
if (TestConfiguration.MSGraph.Scopes is null)
Expand Down Expand Up @@ -123,22 +123,22 @@ private async Task AddMicrosoftManifestPluginsAsync(Kernel kernel, params string
request.RequestUri = uriBuilder.Uri;
});

var apiManifestPluginParameters = new MicrosoftManifestPluginParameters
var apiManifestPluginParameters = new CopilotAgentPluginParameters
{
FunctionExecutionParameters = new()
{
{ "https://graph.microsoft.com/v1.0", graphOpenApiFunctionExecutionParameters },
{ "https://api.nasa.gov/planetary", nasaOpenApiFunctionExecutionParameters }
}
};
var manifestLookupDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "Resources", "Plugins", "MicrosoftManifestPlugins");
var manifestLookupDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "Resources", "Plugins", "CopilotAgentPlugins");

foreach (var pluginName in pluginNames)
{
try
{
#pragma warning disable CA1308 // Normalize strings to uppercase
await kernel.ImportPluginFromMicrosoftManifestAsync(
await kernel.ImportPluginFromCopilotAgentPluginAsync(
pluginName,
Path.Combine(manifestLookupDirectory, pluginName, $"{pluginName[..^6].ToLowerInvariant()}-apiplugin.json"),
apiManifestPluginParameters)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/Concepts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ dotnet test -l "console;verbosity=detailed" --filter "FullyQualifiedName=ChatCom
- [GroundednessChecks](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Plugins/GroundednessChecks.cs)
- [ImportPluginFromGrpc](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Plugins/ImportPluginFromGrpc.cs)
- [TransformPlugin](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Plugins/TransformPlugin.cs)
- [MicrosoftManifestBasedPlugins](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Plugins/MicrosoftManifestBasedPlugins.cs)
- [CopilotAgentBasedPlugins](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Plugins/CopilotAgentBasedPlugins.cs)

### PromptTemplates - Using [`Templates`](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/SemanticKernel.Abstractions/PromptTemplate/IPromptTemplate.cs) with parametrization for `Prompt` rendering

Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
# Microsoft Manifest Plugins
# Copilot Agent Plugins

## Generation

These plugins have been generated thanks to [kiota](https://aka.ms/kiota) and can be regenerated if needed.

```shell
cd dotnet/samples/Concepts/Resources/Plugins/MicrosoftManifestPlugins
cd dotnet/samples/Concepts/Resources/Plugins/CopilotAgentPlugins
```

### Calendar plugin

Microsoft Graph calendar events listing API for the current user.

```shell
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /me/calendar/events#GET -o MicrosoftManifestPlugins/CalendarPlugin
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /me/calendar/events#GET -o CopilotAgentPlugins/CalendarPlugin
```

### Contacts plugin

Microsoft Graph contacts listing API for the current user.

```shell
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /me/contacts#GET -o MicrosoftManifestPlugins/ContactsPlugin
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /me/contacts#GET -o CopilotAgentPlugins/ContactsPlugin
```

### DriveItem plugin

Microsoft Graph download a drive item for the current user.

```shell
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /drive/root/children/{driveItem-id}/content#GET -o MicrosoftManifestPlugins/DriveItemPlugin
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /drive/root/children/{driveItem-id}/content#GET -o CopilotAgentPlugins/DriveItemPlugin
```

### Messages plugin

Microsoft Graph list message and create a draft message for the current user.

```shell
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /me/messages#GET -i /me/messages#POST -o MicrosoftManifestPlugins/MessagesPlugin
kiota plugin add -t APIPlugin -d https://aka.ms/graph/v1.0/openapi.yaml -i /me/messages#GET -i /me/messages#POST -o CopilotAgentPlugins/MessagesPlugin
```

### Astronomy plugin

NASA Astronomy Picture of the day endpoint mixed with Microsoft Graph messages to demonstrate a plugin with multiple APIs.

```shell
kiota plugin add -t APIPlugin -d ..\OpenAPI\NASA\apod.yaml -i /apod#GET -o MicrosoftManifestPlugins/AstronomyPlugin
cp MicrosoftManifestPlugins/MessagesPlugin/messages-openapi.yml MicrosoftManifestPlugins/AstronomyPlugin
kiota plugin add -t APIPlugin -d ../OpenAPI/NASA/apod.yaml -i /apod#GET -o CopilotAgentPlugins/AstronomyPlugin
cp CopilotAgentPlugins/MessagesPlugin/messages-openapi.yml CopilotAgentPlugins/AstronomyPlugin
```

Add this snippet under runtimes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,43 @@ namespace Microsoft.SemanticKernel;
/// <summary>
/// Provides extension methods for the <see cref="Kernel"/> class related to OpenAPI functionality.
/// </summary>
public static class MicrosoftManifestKernelExtensions
public static class CopilotAgentPluginKernelExtensions
{
/// <summary>
/// Imports a plugin from an Microsoft manifest asynchronously.
/// Imports a plugin from an Copilot Agent Plugin asynchronously.
/// </summary>
/// <param name="kernel">The kernel instance.</param>
/// <param name="pluginName">The name of the plugin.</param>
/// <param name="filePath">The file path of the Microsoft manifest.</param>
/// <param name="filePath">The file path of the Copilot Agent Plugin.</param>
/// <param name="pluginParameters">Optional parameters for the plugin setup.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>The imported plugin.</returns>
public static async Task<KernelPlugin> ImportPluginFromMicrosoftManifestAsync(
public static async Task<KernelPlugin> ImportPluginFromCopilotAgentPluginAsync(
this Kernel kernel,
string pluginName,
string filePath,
MicrosoftManifestPluginParameters? pluginParameters = null,
CopilotAgentPluginParameters? pluginParameters = null,
CancellationToken cancellationToken = default)
{
KernelPlugin plugin = await kernel.CreatePluginFromMicrosoftManifestAsync(pluginName, filePath, pluginParameters, cancellationToken).ConfigureAwait(false);
KernelPlugin plugin = await kernel.CreatePluginFromCopilotAgentPluginAsync(pluginName, filePath, pluginParameters, cancellationToken).ConfigureAwait(false);
kernel.Plugins.Add(plugin);
return plugin;
}

/// <summary>
/// Creates a kernel plugin from an Microsoft manifest file asynchronously.
/// Creates a kernel plugin from an Copilot Agent Plugin file asynchronously.
/// </summary>
/// <param name="kernel">The kernel instance.</param>
/// <param name="pluginName">The name of the plugin.</param>
/// <param name="filePath">The file path of the Microsoft manifest.</param>
/// <param name="filePath">The file path of the Copilot Agent Plugin.</param>
/// <param name="pluginParameters">Optional parameters for the plugin setup.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains the created kernel plugin.</returns>
public static async Task<KernelPlugin> CreatePluginFromMicrosoftManifestAsync(
public static async Task<KernelPlugin> CreatePluginFromCopilotAgentPluginAsync(
this Kernel kernel,
string pluginName,
string filePath,
MicrosoftManifestPluginParameters? pluginParameters = null,
CopilotAgentPluginParameters? pluginParameters = null,
CancellationToken cancellationToken = default)
{
Verify.NotNull(kernel);
Expand All @@ -69,15 +69,15 @@ public static async Task<KernelPlugin> CreatePluginFromMicrosoftManifestAsync(

if (!File.Exists(filePath))
{
throw new FileNotFoundException($"MicrosoftManifest file not found: {filePath}");
throw new FileNotFoundException($"CopilotAgent file not found: {filePath}");
}

var loggerFactory = kernel.LoggerFactory;
var logger = loggerFactory.CreateLogger(typeof(MicrosoftManifestKernelExtensions)) ?? NullLogger.Instance;
using var microsoftManifestFileJsonContents = DocumentLoader.LoadDocumentFromFilePathAsStream(filePath,
var logger = loggerFactory.CreateLogger(typeof(CopilotAgentPluginKernelExtensions)) ?? NullLogger.Instance;
using var CopilotAgentFileJsonContents = DocumentLoader.LoadDocumentFromFilePathAsStream(filePath,
logger);

var results = await PluginManifestDocument.LoadAsync(microsoftManifestFileJsonContents, new ReaderOptions
var results = await PluginManifestDocument.LoadAsync(CopilotAgentFileJsonContents, new ReaderOptions
{
ValidationRules = new() // Disable validation rules
}).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Microsoft.SemanticKernel.Plugins.OpenApi.Extensions;

/// <summary>
/// Microsoft manifest plugin parameters.
/// Copilot Agent Plugin plugin parameters.
baywet marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public sealed class MicrosoftManifestPluginParameters
public sealed class CopilotAgentPluginParameters
{
/// <summary>
/// Gets the HTTP client to be used in plugin initialization phase.
Expand Down
Loading