Skip to content

.Net Agents - Update Azure Foundry Agent SDK #12027

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
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d69d74c
Updated
crickman May 12, 2025
7a10397
Fix test
crickman May 12, 2025
e414282
Merge branch 'main' into update-azureaiagents
crickman May 12, 2025
406218a
Namespace
crickman May 12, 2025
98705c2
Namespace
crickman May 12, 2025
6475fdd
Namespace
crickman May 12, 2025
e920a28
Namespace
crickman May 13, 2025
6b53101
Concepts
crickman May 13, 2025
bf7e65d
Stragglers
crickman May 13, 2025
03bdc92
Merge branch 'main' into update-azureaiagents
crickman May 13, 2025
53009d5
Merge and resolve
crickman May 13, 2025
9868e42
Merge branch 'main' into update-azureaiagents
crickman May 13, 2025
ec272fc
Sync suppression
crickman May 13, 2025
2fe54a5
Merge branch 'main' into update-azureaiagents
crickman May 15, 2025
9651a4b
Stage partial result
crickman May 16, 2025
2049635
Updated
crickman May 16, 2025
ac4d84e
Namespace
crickman May 16, 2025
1a3ce3a
Cleanup
crickman May 16, 2025
b9588a5
Merge branch 'main' into update-azureaiagents
crickman May 16, 2025
5c0a1d9
Update foundry processes
crickman May 16, 2025
1285909
Trigger build
crickman May 16, 2025
a8fca77
Merge branch 'main' into update-azureaiagents
crickman May 16, 2025
c5144cb
Sample hygiene
crickman May 16, 2025
835f1d8
Merge branch 'update-azureaiagents' of https://github.com/microsoft/s…
crickman May 16, 2025
3019c34
Rollback Step06 testing edits
crickman May 16, 2025
a04b83f
Update assistant test figure configuration
crickman May 16, 2025
aa75c9c
Merge branch 'main' into update-azureaiagents
crickman May 16, 2025
d255a3b
Update
crickman May 16, 2025
3a7640d
Resolve merge from main
crickman May 16, 2025
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
4 changes: 2 additions & 2 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<PackageVersion Include="AWSSDK.Extensions.Bedrock.MEAI" Version="4.0.0-preview.16" />
<PackageVersion Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0" />
<PackageVersion Include="AWSSDK.SecurityToken" Version="4.0.0.2" />
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.0.0" />
<PackageVersion Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.2" />
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.5" />
<PackageVersion Include="Azure.AI.OpenAI" Version="[2.2.0-beta.4]" />
<PackageVersion Include="Azure.AI.Projects" Version="[1.0.0-beta.8]" />
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
<PackageVersion Include="Azure.Search.Documents" Version="11.6.0" />
Expand Down
2 changes: 1 addition & 1 deletion dotnet/nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>

<packageSourceMapping>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Projects;
using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.ChatCompletion;
using Resources;
using Agent = Azure.AI.Projects.Agent;

namespace Agents;

Expand All @@ -17,10 +16,10 @@ public class AzureAIAgent_FileManipulation(ITestOutputHelper output) : BaseAzure
public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
{
await using Stream stream = EmbeddedResource.ReadStream("sales.csv")!;
AgentFile fileInfo = await this.AgentsClient.UploadFileAsync(stream, AgentFilePurpose.Agents, "sales.csv");
PersistentAgentFileInfo fileInfo = await this.Client.Files.UploadFileAsync(stream, PersistentAgentFilePurpose.Agents, "sales.csv");

// Define the agent
Agent definition = await this.AgentsClient.CreateAgentAsync(
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
tools: [new CodeInterpreterToolDefinition()],
toolResources:
Expand All @@ -31,8 +30,8 @@ public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
FileIds = { fileInfo.Id },
}
});
AzureAIAgent agent = new(definition, this.AgentsClient);
AzureAIAgentThread thread = new(this.AgentsClient);
AzureAIAgent agent = new(definition, this.Client);
AzureAIAgentThread thread = new(this.Client);

// Respond to user input
try
Expand All @@ -44,8 +43,8 @@ public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
finally
{
await thread.DeleteAsync();
await this.AgentsClient.DeleteAgentAsync(agent.Id);
await this.AgentsClient.DeleteFileAsync(fileInfo.Id);
await this.Client.Administration.DeleteAgentAsync(agent.Id);
await this.Client.Files.DeleteFileAsync(fileInfo.Id);
}

// Local function to invoke agent and display the conversation messages.
Expand Down
78 changes: 50 additions & 28 deletions dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
using System.ComponentModel;
using Azure.AI.Projects;
using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.ChatCompletion;
using Agent = Azure.AI.Projects.Agent;

namespace Agents;

Expand All @@ -21,23 +20,30 @@ 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
Agent definition = await this.AgentsClient.CreateAgentAsync(
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
AgentName,
null,
AgentInstructions);
AzureAIAgent agent = new(definition, this.AgentsClient);
AzureAIAgent agent = new(definition, this.Client);

// Create a thread for the agent conversation.
AzureAIAgentThread agentThread = new(this.AgentsClient, metadata: SampleMetadata);
try
{
// Create a thread for the agent conversation.
AzureAIAgentThread agentThread = new(this.Client, metadata: SampleMetadata);

// Respond to user input
await InvokeAgentAsync(agent, agentThread, "Fortune favors the bold.");
await InvokeAgentAsync(agent, agentThread, "I came, I saw, I conquered.");
await InvokeAgentAsync(agent, agentThread, "Practice makes perfect.");
// Respond to user input
await InvokeAgentAsync(agent, agentThread, "Fortune favors the bold.");
await InvokeAgentAsync(agent, agentThread, "I came, I saw, I conquered.");
await InvokeAgentAsync(agent, agentThread, "Practice makes perfect.");

// Output the entire chat history
await DisplayChatHistoryAsync(agentThread);
// Output the entire chat history
await DisplayChatHistoryAsync(agentThread);
}
finally
{
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}

[Fact]
Expand All @@ -47,26 +53,34 @@ public async Task UseStreamingAssistantAgentWithPluginAsync()
const string AgentInstructions = "Answer questions about the menu.";

// Define the agent
Agent definition = await this.AgentsClient.CreateAgentAsync(
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
AgentName,
null,
AgentInstructions);
AzureAIAgent agent = new(definition, this.AgentsClient);
AzureAIAgent agent = new(definition, this.Client);

// Initialize plugin and add to the agent's Kernel (same as direct Kernel usage).
KernelPlugin plugin = KernelPluginFactory.CreateFromType<MenuPlugin>();
agent.Kernel.Plugins.Add(plugin);

// Create a thread for the agent conversation.
AzureAIAgentThread agentThread = new(this.AgentsClient, metadata: SampleMetadata);
AzureAIAgentThread agentThread = new(this.Client, metadata: SampleMetadata);

// Respond to user input
await InvokeAgentAsync(agent, agentThread, "What is the special soup and its price?");
await InvokeAgentAsync(agent, agentThread, "What is the special drink and its price?");
try
{
// Respond to user input
await InvokeAgentAsync(agent, agentThread, "What is the special soup and its price?");
await InvokeAgentAsync(agent, agentThread, "What is the special drink and its price?");

// Output the entire chat history
await DisplayChatHistoryAsync(agentThread);
// Output the entire chat history
await DisplayChatHistoryAsync(agentThread);
}
finally
{
await this.Client.Threads.DeleteThreadAsync(agentThread.Id);
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}

[Fact]
Expand All @@ -76,23 +90,31 @@ public async Task UseStreamingAssistantWithCodeInterpreterAsync()
const string AgentInstructions = "Solve math problems with code.";

// Define the agent
Agent definition = await this.AgentsClient.CreateAgentAsync(
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
AgentName,
null,
AgentInstructions,
[new CodeInterpreterToolDefinition()]);
AzureAIAgent agent = new(definition, this.AgentsClient);
AzureAIAgent agent = new(definition, this.Client);

// Create a thread for the agent conversation.
AzureAIAgentThread agentThread = new(this.AgentsClient, metadata: SampleMetadata);
AzureAIAgentThread agentThread = new(this.Client, metadata: SampleMetadata);

// Respond to user input
await InvokeAgentAsync(agent, agentThread, "Is 191 a prime number?");
await InvokeAgentAsync(agent, agentThread, "Determine the values in the Fibonacci sequence that that are less then the value of 101");
try
{
// Respond to user input
await InvokeAgentAsync(agent, agentThread, "Is 191 a prime number?");
await InvokeAgentAsync(agent, agentThread, "Determine the values in the Fibonacci sequence that that are less then the value of 101");

// Output the entire chat history
await DisplayChatHistoryAsync(agentThread);
// Output the entire chat history
await DisplayChatHistoryAsync(agentThread);
}
finally
{
await this.Client.Threads.DeleteThreadAsync(agentThread.Id);
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}

// Local function to invoke agent and display the conversation messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure.AI.Projects;
using Azure.AI.Agents.Persistent;
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel;
Expand Down Expand Up @@ -68,7 +68,7 @@ public static async Task RunAsync()
await response!.Thread.DeleteAsync();

// Delete the agent after use
await agent.Client.DeleteAgentAsync(agent.Id);
await agent.Client.Administration.DeleteAgentAsync(agent.Id);
}

/// <summary>
Expand All @@ -86,7 +86,7 @@ private static async Task<AzureAIAgent> CreateAzureAIAgentAsync(Kernel kernel, s
.AddEnvironmentVariables()
.Build();

if (config["AzureAI:ConnectionString"] is not { } connectionString)
if (config["AzureAI:Endpoint"] is not { } endpoint)
{
const string Message = "Please provide a valid `AzureAI:ConnectionString` secret to run this sample. See the associated README.md for more details.";
Console.Error.WriteLine(Message);
Expand All @@ -96,11 +96,9 @@ private static async Task<AzureAIAgent> CreateAzureAIAgentAsync(Kernel kernel, s
string modelId = config["AzureAI:ChatModelId"] ?? "gpt-4o-mini";

// Create the Azure AI Agent
AIProjectClient projectClient = AzureAIAgent.CreateAzureAIClient(connectionString, new AzureCliCredential());
PersistentAgentsClient agentsClient = AzureAIAgent.CreateAgentsClient(endpoint, new AzureCliCredential());

AgentsClient agentsClient = projectClient.GetAgentsClient();

Azure.AI.Projects.Agent agent = await agentsClient.CreateAgentAsync(modelId, name, null, instructions);
PersistentAgent agent = await agentsClient.Administration.CreateAgentAsync(modelId, name, null, instructions);

return new AzureAIAgent(agent, agentsClient)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
Expand All @@ -19,11 +20,10 @@ public async Task UseTemplateForAzureAgent()
string generateStoryYaml = EmbeddedResource.Read("GenerateStory.yaml");
PromptTemplateConfig templateConfig = KernelFunctionYaml.ToPromptTemplateConfig(generateStoryYaml);
// Instructions, Name and Description properties defined via the PromptTemplateConfig.
Azure.AI.Projects.Agent definition = await this.AgentsClient.CreateAgentAsync(TestConfiguration.AzureAI.ChatModelId, templateConfig.Name, templateConfig.Description, templateConfig.Template);

PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(TestConfiguration.AzureAI.ChatModelId, templateConfig.Name, templateConfig.Description, templateConfig.Template);
AzureAIAgent agent = new(
definition,
this.AgentsClient,
this.Client,
templateFactory: new KernelPromptTemplateFactory(),
templateFormat: PromptTemplateConfig.SemanticKernelTemplateFormat)
{
Expand All @@ -35,7 +35,7 @@ public async Task UseTemplateForAzureAgent()
};

// Create a thread for the agent conversation.
AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);

try
{
Expand All @@ -53,7 +53,7 @@ await InvokeAgentAsync(
finally
{
await thread.DeleteAsync();
await this.AgentsClient.DeleteAgentAsync(agent.Id);
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}

// Local function to invoke agent and display the response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
Expand All @@ -23,7 +24,7 @@ public async Task UseAzureAgentWithPlugin()
name: "Host");

// Create a thread for the agent conversation.
AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);

// Respond to user input
try
Expand All @@ -36,7 +37,7 @@ public async Task UseAzureAgentWithPlugin()
finally
{
await thread.DeleteAsync();
await this.AgentsClient.DeleteAgentAsync(agent.Id);
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}

Expand All @@ -47,7 +48,7 @@ public async Task UseAzureAgentWithPluginEnumParameter()
AzureAIAgent agent = await CreateAzureAgentAsync(plugin: KernelPluginFactory.CreateFromType<WidgetFactory>());

// Create a thread for the agent conversation.
AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);

// Respond to user input
try
Expand All @@ -57,20 +58,20 @@ public async Task UseAzureAgentWithPluginEnumParameter()
finally
{
await thread.DeleteAsync();
await this.AgentsClient.DeleteAgentAsync(agent.Id);
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}

private async Task<AzureAIAgent> CreateAzureAgentAsync(KernelPlugin plugin, string? instructions = null, string? name = null)
{
// Define the agent
Azure.AI.Projects.Agent definition = await this.AgentsClient.CreateAgentAsync(
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
name,
null,
instructions);

AzureAIAgent agent = new(definition, this.AgentsClient);
AzureAIAgent agent = new(definition, this.Client);

// Add to the agent's Kernel
if (plugin != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.Agents.Chat;
using Microsoft.SemanticKernel.ChatCompletion;
using Agent = Azure.AI.Projects.Agent;

namespace GettingStarted.AzureAgents;

Expand Down Expand Up @@ -39,18 +39,18 @@ Consider suggestions when refining an idea.
public async Task UseGroupChatWithTwoAgents()
{
// Define the agents
Agent reviewerModel = await this.AgentsClient.CreateAgentAsync(
PersistentAgent reviewerModel = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
ReviewerName,
null,
ReviewerInstructions);
AzureAIAgent agentReviewer = new(reviewerModel, this.AgentsClient);
Agent writerModel = await this.AgentsClient.CreateAgentAsync(
AzureAIAgent agentReviewer = new(reviewerModel, this.Client);
PersistentAgent writerModel = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
CopyWriterName,
null,
CopyWriterInstructions);
AzureAIAgent agentWriter = new(writerModel, this.AgentsClient);
AzureAIAgent agentWriter = new(writerModel, this.Client);

// Create a chat for agent interaction.
AgentGroupChat chat =
Expand Down Expand Up @@ -89,6 +89,8 @@ public async Task UseGroupChatWithTwoAgents()
finally
{
await chat.ResetAsync();
await agentReviewer.Client.Administration.DeleteAgentAsync(agentReviewer.Id);
await agentWriter.Client.Administration.DeleteAgentAsync(agentWriter.Id);
}
}

Expand Down
Loading
Loading