Skip to content

Commit

Permalink
Merge branch 'main' into joslat-demo-reasoning-models
Browse files Browse the repository at this point in the history
  • Loading branch information
joslat authored Feb 19, 2025
2 parents e5d09c5 + b6e4e66 commit 665d958
Show file tree
Hide file tree
Showing 117 changed files with 4,839 additions and 1,677 deletions.
1,770 changes: 1,770 additions & 0 deletions docs/decisions/0065-realtime-api-clients.md

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.0" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.5.1" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.12.19" />
<PackageVersion Include="Handlebars.Net.Helpers" Version="2.4.6" />
<PackageVersion Include="Handlebars.Net.Helpers" Version="2.4.10" />
<PackageVersion Include="Handlebars.Net" Version="2.1.6" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.72" />
<PackageVersion Include="JsonSchema.Net" Version="5.4.2" />
Expand All @@ -45,18 +45,18 @@
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="8.0.1" />
<PackageVersion Include="Microsoft.Identity.Client" Version="4.67.2" />
<PackageVersion Include="Microsoft.ML.OnnxRuntime" Version="1.20.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.8.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Npgsql" Version="8.0.6" />
<PackageVersion Include="OllamaSharp" Version="4.0.17" />
<PackageVersion Include="OllamaSharp" Version="5.0.7" />
<PackageVersion Include="OpenAI" Version="[2.2.0-beta.1]" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageVersion Include="PdfPig" Version="0.1.9" />
<PackageVersion Include="Pinecone.NET" Version="2.1.1" />
<PackageVersion Include="Prompty.Core" Version="0.0.23-alpha" />
<PackageVersion Include="PuppeteerSharp" Version="20.0.5" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.1" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.2" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />
<PackageVersion Include="System.IO.Packaging" Version="8.0.1" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
Expand All @@ -68,10 +68,10 @@
<PackageVersion Include="Microsoft.DeepDev.TokenizerLib" Version="1.3.3" />
<PackageVersion Include="SharpToken" Version="2.0.3" />
<!-- Microsoft.Extensions.* -->
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.1.0-preview.1.25064.3" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.1.0-preview.1.25064.3" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.1.0-preview.1.25064.3" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.1.0-preview.1.25064.3" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
Expand Down Expand Up @@ -115,7 +115,7 @@
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.22" />
<PackageVersion Include="Microsoft.OpenApi.ApiManifest" Version="0.5.6-preview" />
<PackageVersion Include="Microsoft.Plugins.Manifest" Version="1.0.0-rc3" />
<PackageVersion Include="Google.Apis.CustomSearchAPI.v1" Version="1.60.0.3001" />
<PackageVersion Include="Google.Apis.CustomSearchAPI.v1" Version="1.68.0.3520" />
<PackageVersion Include="Grpc.Net.Client" Version="2.66.0" />
<PackageVersion Include="protobuf-net" Version="3.2.45" />
<PackageVersion Include="protobuf-net.Reflection" Version="3.2.12" />
Expand Down
56 changes: 7 additions & 49 deletions dotnet/samples/Concepts/Agents/AzureAIAgent_FileManipulation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics;
using Azure.AI.Projects;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
Expand All @@ -13,19 +12,16 @@ namespace Agents;
/// <summary>
/// Demonstrate using code-interpreter to manipulate and generate csv files with <see cref="AzureAIAgent"/> .
/// </summary>
public class AzureAIAgent_FileManipulation(ITestOutputHelper output) : BaseAgentsTest(output)
public class AzureAIAgent_FileManipulation(ITestOutputHelper output) : BaseAzureAgentTest(output)
{
[Fact]
public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
{
AzureAIClientProvider clientProvider = this.GetAzureProvider();
AgentsClient client = clientProvider.Client.GetAgentsClient();

await using Stream stream = EmbeddedResource.ReadStream("sales.csv")!;
AgentFile fileInfo = await client.UploadFileAsync(stream, AgentFilePurpose.Agents, "sales.csv");
AgentFile fileInfo = await this.AgentsClient.UploadFileAsync(stream, AgentFilePurpose.Agents, "sales.csv");

// Define the agent
Agent definition = await client.CreateAgentAsync(
Agent definition = await this.AgentsClient.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
tools: [new CodeInterpreterToolDefinition()],
toolResources:
Expand All @@ -36,7 +32,7 @@ public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
FileIds = { fileInfo.Id },
}
});
AzureAIAgent agent = new(definition, clientProvider);
AzureAIAgent agent = new(definition, this.AgentsClient);

// Create a chat for agent interaction.
AgentGroupChat chat = new();
Expand All @@ -50,8 +46,8 @@ public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
}
finally
{
await client.DeleteAgentAsync(agent.Id);
await client.DeleteFileAsync(fileInfo.Id);
await this.AgentsClient.DeleteAgentAsync(agent.Id);
await this.AgentsClient.DeleteFileAsync(fileInfo.Id);
await chat.ResetAsync();
}

Expand All @@ -65,45 +61,7 @@ async Task InvokeAgentAsync(string input)
await foreach (ChatMessageContent response in chat.InvokeAsync(agent))
{
this.WriteAgentChatMessage(response);
await this.DownloadContentAsync(client, response);
}
}
}

private async Task DownloadContentAsync(AgentsClient client, ChatMessageContent message)
{
foreach (KernelContent item in message.Items)
{
if (item is AnnotationContent annotation)
{
await this.DownloadFileAsync(client, annotation.FileId!);
}
}
}

private async Task DownloadFileAsync(AgentsClient client, string fileId, bool launchViewer = false)
{
AgentFile fileInfo = client.GetFile(fileId);
if (fileInfo.Purpose == AgentFilePurpose.AgentsOutput)
{
string filePath = Path.Combine(Path.GetTempPath(), Path.GetFileName(fileInfo.Filename));
if (launchViewer)
{
filePath = Path.ChangeExtension(filePath, ".png");
}

BinaryData content = await client.GetFileContentAsync(fileId);
File.WriteAllBytes(filePath, content.ToArray());
Console.WriteLine($" File #{fileId} saved to: {filePath}");

if (launchViewer)
{
Process.Start(
new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C start {filePath}"
});
await this.DownloadContentAsync(response);
}
}
}
Expand Down
26 changes: 10 additions & 16 deletions dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Agents;
/// <summary>
/// Demonstrate consuming "streaming" message for <see cref="AzureAIAgent"/>.
/// </summary>
public class AzureAIAgent_Streaming(ITestOutputHelper output) : BaseAgentsTest(output)
public class AzureAIAgent_Streaming(ITestOutputHelper output) : BaseAzureAgentTest(output)
{
[Fact]
public async Task UseStreamingAgentAsync()
Expand All @@ -20,17 +20,15 @@ public async Task UseStreamingAgentAsync()
const string AgentInstructions = "Repeat the user message in the voice of a pirate and then end with a parrot sound.";

// Define the agent
AzureAIClientProvider clientProvider = this.GetAzureProvider();
AgentsClient client = clientProvider.Client.GetAgentsClient();
Agent definition = await client.CreateAgentAsync(
Agent definition = await this.AgentsClient.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
AgentName,
null,
AgentInstructions);
AzureAIAgent agent = new(definition, clientProvider);
AzureAIAgent agent = new(definition, this.AgentsClient);

// Create a thread for the agent conversation.
AgentThread thread = await client.CreateThreadAsync(metadata: AssistantSampleMetadata);
AgentThread thread = await this.AgentsClient.CreateThreadAsync(metadata: SampleMetadata);

// Respond to user input
await InvokeAgentAsync(agent, thread.Id, "Fortune favors the bold.");
Expand All @@ -48,14 +46,12 @@ public async Task UseStreamingAssistantAgentWithPluginAsync()
const string AgentInstructions = "Answer questions about the menu.";

// Define the agent
AzureAIClientProvider clientProvider = this.GetAzureProvider();
AgentsClient client = clientProvider.Client.GetAgentsClient();
Agent definition = await client.CreateAgentAsync(
Agent definition = await this.AgentsClient.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
AgentName,
null,
AgentInstructions);
AzureAIAgent agent = new(definition, clientProvider)
AzureAIAgent agent = new(definition, this.AgentsClient)
{
Kernel = new Kernel(),
};
Expand All @@ -65,7 +61,7 @@ public async Task UseStreamingAssistantAgentWithPluginAsync()
agent.Kernel.Plugins.Add(plugin);

// Create a thread for the agent conversation.
AgentThread thread = await client.CreateThreadAsync(metadata: AssistantSampleMetadata);
AgentThread thread = await this.AgentsClient.CreateThreadAsync(metadata: SampleMetadata);

// Respond to user input
await InvokeAgentAsync(agent, thread.Id, "What is the special soup and its price?");
Expand All @@ -82,21 +78,19 @@ public async Task UseStreamingAssistantWithCodeInterpreterAsync()
const string AgentInstructions = "Solve math problems with code.";

// Define the agent
AzureAIClientProvider clientProvider = this.GetAzureProvider();
AgentsClient client = clientProvider.Client.GetAgentsClient();
Agent definition = await client.CreateAgentAsync(
Agent definition = await this.AgentsClient.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
AgentName,
null,
AgentInstructions,
[new CodeInterpreterToolDefinition()]);
AzureAIAgent agent = new(definition, clientProvider)
AzureAIAgent agent = new(definition, this.AgentsClient)
{
Kernel = new Kernel(),
};

// Create a thread for the agent conversation.
AgentThread thread = await client.CreateThreadAsync(metadata: AssistantSampleMetadata);
AgentThread thread = await this.AgentsClient.CreateThreadAsync(metadata: SampleMetadata);

// Respond to user input
await InvokeAgentAsync(agent, thread.Id, "Is 191 a prime number?");
Expand Down
31 changes: 11 additions & 20 deletions dotnet/samples/Concepts/Agents/DeclarativeAgents.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Text;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.ChatCompletion;
Expand All @@ -9,11 +8,13 @@ namespace Agents;

public class DeclarativeAgents(ITestOutputHelper output) : BaseAgentsTest(output)
{
[InlineData("SchedulingAssistant.json", "Read the body of my last five emails, if any contain a meeting request for today, check that it's already on my calendar, if not, call out which email it is.")]
[InlineData(
"SchedulingAssistant.json",
"Read the body of my last five emails, if any contain a meeting request for today, check that it's already on my calendar, if not, call out which email it is.")]
[Theory]
public async Task LoadsAgentFromDeclarativeAgentManifestAsync(string agentFileName, string input)
{
var kernel = CreateKernel();
var kernel = this.CreateKernelWithChatCompletion();
kernel.AutoFunctionInvocationFilters.Add(new ExpectedSchemaFunctionFilter());
var manifestLookupDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "Resources", "DeclarativeAgents");
var manifestFilePath = Path.Combine(manifestLookupDirectory, agentFileName);
Expand All @@ -30,9 +31,8 @@ public async Task LoadsAgentFromDeclarativeAgentManifestAsync(string agentFileNa
Assert.NotNull(agent.Instructions);
Assert.NotEmpty(agent.Instructions);

ChatMessageContent message = new(AuthorRole.User, input);
ChatHistory chatHistory = [message];
StringBuilder sb = new();
ChatHistory chatHistory = [new ChatMessageContent(AuthorRole.User, input)];

var kernelArguments = new KernelArguments(new PromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(
Expand All @@ -42,23 +42,14 @@ public async Task LoadsAgentFromDeclarativeAgentManifestAsync(string agentFileNa
}
)
});
await foreach (ChatMessageContent response in agent.InvokeAsync(chatHistory, kernelArguments))
{
chatHistory.Add(response);
sb.Append(response.Content);
}
Assert.NotEmpty(chatHistory.Skip(1));
}
private Kernel CreateKernel()
{
IKernelBuilder builder = Kernel.CreateBuilder();

base.AddChatCompletionToKernel(builder);

return builder.Build();
var responses = await agent.InvokeAsync(chatHistory, kernelArguments).ToArrayAsync();
Assert.NotEmpty(responses);
}

private sealed class ExpectedSchemaFunctionFilter : IAutoFunctionInvocationFilter
{//TODO: this eventually needs to be added to all CAP or DA but we're still discussing where should those facilitators live
{
//TODO: this eventually needs to be added to all CAP or DA but we're still discussing where should those facilitators live
public async Task OnAutoFunctionInvocationAsync(AutoFunctionInvocationContext context, Func<AutoFunctionInvocationContext, Task> next)
{
await next(context);
Expand Down
23 changes: 12 additions & 11 deletions dotnet/samples/Concepts/Agents/MixedChat_Agents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using Microsoft.SemanticKernel.Agents.Chat;
using Microsoft.SemanticKernel.Agents.OpenAI;
using Microsoft.SemanticKernel.ChatCompletion;
using OpenAI.Assistants;

namespace Agents;
/// <summary>
/// Demonstrate that two different agent types are able to participate in the same conversation.
/// In this case a <see cref="ChatCompletionAgent"/> and <see cref="OpenAIAssistantAgent"/> participate.
/// </summary>
public class MixedChat_Agents(ITestOutputHelper output) : BaseAgentsTest(output)
public class MixedChat_Agents(ITestOutputHelper output) : BaseAssistantTest(output)
{
private const string ReviewerName = "ArtDirector";
private const string ReviewerInstructions =
Expand Down Expand Up @@ -44,16 +45,16 @@ public async Task ChatWithOpenAIAssistantAgentAndChatCompletionAgentAsync()
Kernel = this.CreateKernelWithChatCompletion(),
};

OpenAIAssistantAgent agentWriter =
await OpenAIAssistantAgent.CreateAsync(
clientProvider: this.GetClientProvider(),
definition: new OpenAIAssistantDefinition(this.Model)
{
Instructions = CopyWriterInstructions,
Name = CopyWriterName,
Metadata = AssistantSampleMetadata,
},
kernel: new Kernel());
// Define the assistant
Assistant assistant =
await this.AssistantClient.CreateAssistantAsync(
this.Model,
name: CopyWriterName,
instructions: CopyWriterInstructions,
metadata: SampleMetadata);

// Create the agent
OpenAIAssistantAgent agentWriter = new(assistant, this.AssistantClient);

// Create a chat for agent interaction.
AgentGroupChat chat =
Expand Down
Loading

0 comments on commit 665d958

Please sign in to comment.