Skip to content

Commit f976643

Browse files
authored
.Net Agents - Update Azure Foundry Agent SDK (#12027)
### Motivation and Context As part of going GA with Foundry Agents, Azure team has split `Azure.AI.Projects` into two packages: `Azure.AI.Projects` & `Azure.AI.Agents.Persistent` In addition, connecting to a foundry project will be based on endpoint/credential and connection-string will not be supported. ### Description - Updated package dependency to include: `Azure.AI.Projects.OneDP` & `Azure.AI.Agents.Persistent` - Updated declarative agents to support `endpoint` instead of `connection-string` - Updated tests and samples - Deprecated `OpenAIClientProvider` - Removed `AzureAIClientProvider` ![image](https://github.com/user-attachments/assets/16ba9e4d-86b0-4bbb-a817-dc8bd346ddb0) ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] 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 - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄
1 parent 54519f0 commit f976643

File tree

57 files changed

+473
-790
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+473
-790
lines changed

dotnet/Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<PackageVersion Include="AWSSDK.Extensions.Bedrock.MEAI" Version="4.0.0-preview.16" />
1818
<PackageVersion Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0" />
1919
<PackageVersion Include="AWSSDK.SecurityToken" Version="4.0.0.2" />
20+
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.0.0" />
2021
<PackageVersion Include="Azure.AI.ContentSafety" Version="1.0.0" />
21-
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.2" />
22+
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.5" />
2223
<PackageVersion Include="Azure.AI.OpenAI" Version="[2.2.0-beta.4]" />
23-
<PackageVersion Include="Azure.AI.Projects" Version="[1.0.0-beta.8]" />
2424
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
2525
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
2626
<PackageVersion Include="Azure.Search.Documents" Version="11.6.0" />

dotnet/nuget.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<packageSources>
55
<clear />
6-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
77
</packageSources>
88

99
<packageSourceMapping>

dotnet/samples/Concepts/Agents/AzureAIAgent_FileManipulation.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (c) Microsoft. All rights reserved.
2-
using Azure.AI.Projects;
2+
using Azure.AI.Agents.Persistent;
33
using Microsoft.SemanticKernel;
44
using Microsoft.SemanticKernel.Agents.AzureAI;
55
using Microsoft.SemanticKernel.ChatCompletion;
66
using Resources;
7-
using Agent = Azure.AI.Projects.Agent;
87

98
namespace Agents;
109

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

2221
// Define the agent
23-
Agent definition = await this.AgentsClient.CreateAgentAsync(
22+
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
2423
TestConfiguration.AzureAI.ChatModelId,
2524
tools: [new CodeInterpreterToolDefinition()],
2625
toolResources:
@@ -31,8 +30,8 @@ public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
3130
FileIds = { fileInfo.Id },
3231
}
3332
});
34-
AzureAIAgent agent = new(definition, this.AgentsClient);
35-
AzureAIAgentThread thread = new(this.AgentsClient);
33+
AzureAIAgent agent = new(definition, this.Client);
34+
AzureAIAgentThread thread = new(this.Client);
3635

3736
// Respond to user input
3837
try
@@ -44,8 +43,8 @@ public async Task AnalyzeCSVFileUsingAzureAIAgentAsync()
4443
finally
4544
{
4645
await thread.DeleteAsync();
47-
await this.AgentsClient.DeleteAgentAsync(agent.Id);
48-
await this.AgentsClient.DeleteFileAsync(fileInfo.Id);
46+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
47+
await this.Client.Files.DeleteFileAsync(fileInfo.Id);
4948
}
5049

5150
// Local function to invoke agent and display the conversation messages.

dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
using System.ComponentModel;
3-
using Azure.AI.Projects;
3+
using Azure.AI.Agents.Persistent;
44
using Microsoft.SemanticKernel;
55
using Microsoft.SemanticKernel.Agents;
66
using Microsoft.SemanticKernel.Agents.AzureAI;
77
using Microsoft.SemanticKernel.ChatCompletion;
8-
using Agent = Azure.AI.Projects.Agent;
98

109
namespace Agents;
1110

@@ -21,23 +20,30 @@ public async Task UseStreamingAgentAsync()
2120
const string AgentInstructions = "Repeat the user message in the voice of a pirate and then end with a parrot sound.";
2221

2322
// Define the agent
24-
Agent definition = await this.AgentsClient.CreateAgentAsync(
23+
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
2524
TestConfiguration.AzureAI.ChatModelId,
2625
AgentName,
2726
null,
2827
AgentInstructions);
29-
AzureAIAgent agent = new(definition, this.AgentsClient);
28+
AzureAIAgent agent = new(definition, this.Client);
3029

31-
// Create a thread for the agent conversation.
32-
AzureAIAgentThread agentThread = new(this.AgentsClient, metadata: SampleMetadata);
30+
try
31+
{
32+
// Create a thread for the agent conversation.
33+
AzureAIAgentThread agentThread = new(this.Client, metadata: SampleMetadata);
3334

34-
// Respond to user input
35-
await InvokeAgentAsync(agent, agentThread, "Fortune favors the bold.");
36-
await InvokeAgentAsync(agent, agentThread, "I came, I saw, I conquered.");
37-
await InvokeAgentAsync(agent, agentThread, "Practice makes perfect.");
35+
// Respond to user input
36+
await InvokeAgentAsync(agent, agentThread, "Fortune favors the bold.");
37+
await InvokeAgentAsync(agent, agentThread, "I came, I saw, I conquered.");
38+
await InvokeAgentAsync(agent, agentThread, "Practice makes perfect.");
3839

39-
// Output the entire chat history
40-
await DisplayChatHistoryAsync(agentThread);
40+
// Output the entire chat history
41+
await DisplayChatHistoryAsync(agentThread);
42+
}
43+
finally
44+
{
45+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
46+
}
4147
}
4248

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

4955
// Define the agent
50-
Agent definition = await this.AgentsClient.CreateAgentAsync(
56+
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
5157
TestConfiguration.AzureAI.ChatModelId,
5258
AgentName,
5359
null,
5460
AgentInstructions);
55-
AzureAIAgent agent = new(definition, this.AgentsClient);
61+
AzureAIAgent agent = new(definition, this.Client);
5662

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

6167
// Create a thread for the agent conversation.
62-
AzureAIAgentThread agentThread = new(this.AgentsClient, metadata: SampleMetadata);
68+
AzureAIAgentThread agentThread = new(this.Client, metadata: SampleMetadata);
6369

64-
// Respond to user input
65-
await InvokeAgentAsync(agent, agentThread, "What is the special soup and its price?");
66-
await InvokeAgentAsync(agent, agentThread, "What is the special drink and its price?");
70+
try
71+
{
72+
// Respond to user input
73+
await InvokeAgentAsync(agent, agentThread, "What is the special soup and its price?");
74+
await InvokeAgentAsync(agent, agentThread, "What is the special drink and its price?");
6775

68-
// Output the entire chat history
69-
await DisplayChatHistoryAsync(agentThread);
76+
// Output the entire chat history
77+
await DisplayChatHistoryAsync(agentThread);
78+
}
79+
finally
80+
{
81+
await this.Client.Threads.DeleteThreadAsync(agentThread.Id);
82+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
83+
}
7084
}
7185

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

7892
// Define the agent
79-
Agent definition = await this.AgentsClient.CreateAgentAsync(
93+
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
8094
TestConfiguration.AzureAI.ChatModelId,
8195
AgentName,
8296
null,
8397
AgentInstructions,
8498
[new CodeInterpreterToolDefinition()]);
85-
AzureAIAgent agent = new(definition, this.AgentsClient);
99+
AzureAIAgent agent = new(definition, this.Client);
86100

87101
// Create a thread for the agent conversation.
88-
AzureAIAgentThread agentThread = new(this.AgentsClient, metadata: SampleMetadata);
102+
AzureAIAgentThread agentThread = new(this.Client, metadata: SampleMetadata);
89103

90-
// Respond to user input
91-
await InvokeAgentAsync(agent, agentThread, "Is 191 a prime number?");
92-
await InvokeAgentAsync(agent, agentThread, "Determine the values in the Fibonacci sequence that that are less then the value of 101");
104+
try
105+
{
106+
// Respond to user input
107+
await InvokeAgentAsync(agent, agentThread, "Is 191 a prime number?");
108+
await InvokeAgentAsync(agent, agentThread, "Determine the values in the Fibonacci sequence that that are less then the value of 101");
93109

94-
// Output the entire chat history
95-
await DisplayChatHistoryAsync(agentThread);
110+
// Output the entire chat history
111+
await DisplayChatHistoryAsync(agentThread);
112+
}
113+
finally
114+
{
115+
await this.Client.Threads.DeleteThreadAsync(agentThread.Id);
116+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
117+
}
96118
}
97119

98120
// Local function to invoke agent and display the conversation messages.

dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Threading.Tasks;
7-
using Azure.AI.Projects;
7+
using Azure.AI.Agents.Persistent;
88
using Azure.Identity;
99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.SemanticKernel;
@@ -68,7 +68,7 @@ public static async Task RunAsync()
6868
await response!.Thread.DeleteAsync();
6969

7070
// Delete the agent after use
71-
await agent.Client.DeleteAgentAsync(agent.Id);
71+
await agent.Client.Administration.DeleteAgentAsync(agent.Id);
7272
}
7373

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

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

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

101-
AgentsClient agentsClient = projectClient.GetAgentsClient();
102-
103-
Azure.AI.Projects.Agent agent = await agentsClient.CreateAgentAsync(modelId, name, null, instructions);
101+
PersistentAgent agent = await agentsClient.Administration.CreateAgentAsync(modelId, name, null, instructions);
104102

105103
return new AzureAIAgent(agent, agentsClient)
106104
{

dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step01_AzureAIAgent.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) Microsoft. All rights reserved.
2+
using Azure.AI.Agents.Persistent;
23
using Microsoft.SemanticKernel;
34
using Microsoft.SemanticKernel.Agents;
45
using Microsoft.SemanticKernel.Agents.AzureAI;
@@ -19,11 +20,10 @@ public async Task UseTemplateForAzureAgent()
1920
string generateStoryYaml = EmbeddedResource.Read("GenerateStory.yaml");
2021
PromptTemplateConfig templateConfig = KernelFunctionYaml.ToPromptTemplateConfig(generateStoryYaml);
2122
// Instructions, Name and Description properties defined via the PromptTemplateConfig.
22-
Azure.AI.Projects.Agent definition = await this.AgentsClient.CreateAgentAsync(TestConfiguration.AzureAI.ChatModelId, templateConfig.Name, templateConfig.Description, templateConfig.Template);
23-
23+
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(TestConfiguration.AzureAI.ChatModelId, templateConfig.Name, templateConfig.Description, templateConfig.Template);
2424
AzureAIAgent agent = new(
2525
definition,
26-
this.AgentsClient,
26+
this.Client,
2727
templateFactory: new KernelPromptTemplateFactory(),
2828
templateFormat: PromptTemplateConfig.SemanticKernelTemplateFormat)
2929
{
@@ -35,7 +35,7 @@ public async Task UseTemplateForAzureAgent()
3535
};
3636

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

4040
try
4141
{
@@ -53,7 +53,7 @@ await InvokeAgentAsync(
5353
finally
5454
{
5555
await thread.DeleteAsync();
56-
await this.AgentsClient.DeleteAgentAsync(agent.Id);
56+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
5757
}
5858

5959
// Local function to invoke agent and display the response.

dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step02_AzureAIAgent_Plugins.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) Microsoft. All rights reserved.
2+
using Azure.AI.Agents.Persistent;
23
using Microsoft.SemanticKernel;
34
using Microsoft.SemanticKernel.Agents;
45
using Microsoft.SemanticKernel.Agents.AzureAI;
@@ -23,7 +24,7 @@ public async Task UseAzureAgentWithPlugin()
2324
name: "Host");
2425

2526
// Create a thread for the agent conversation.
26-
AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
27+
AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);
2728

2829
// Respond to user input
2930
try
@@ -36,7 +37,7 @@ public async Task UseAzureAgentWithPlugin()
3637
finally
3738
{
3839
await thread.DeleteAsync();
39-
await this.AgentsClient.DeleteAgentAsync(agent.Id);
40+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
4041
}
4142
}
4243

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

4950
// Create a thread for the agent conversation.
50-
AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
51+
AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);
5152

5253
// Respond to user input
5354
try
@@ -57,20 +58,20 @@ public async Task UseAzureAgentWithPluginEnumParameter()
5758
finally
5859
{
5960
await thread.DeleteAsync();
60-
await this.AgentsClient.DeleteAgentAsync(agent.Id);
61+
await this.Client.Administration.DeleteAgentAsync(agent.Id);
6162
}
6263
}
6364

6465
private async Task<AzureAIAgent> CreateAzureAgentAsync(KernelPlugin plugin, string? instructions = null, string? name = null)
6566
{
6667
// Define the agent
67-
Azure.AI.Projects.Agent definition = await this.AgentsClient.CreateAgentAsync(
68+
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
6869
TestConfiguration.AzureAI.ChatModelId,
6970
name,
7071
null,
7172
instructions);
7273

73-
AzureAIAgent agent = new(definition, this.AgentsClient);
74+
AzureAIAgent agent = new(definition, this.Client);
7475

7576
// Add to the agent's Kernel
7677
if (plugin != null)

dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step03_AzureAIAgent_Chat.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) Microsoft. All rights reserved.
2+
using Azure.AI.Agents.Persistent;
23
using Microsoft.SemanticKernel;
34
using Microsoft.SemanticKernel.Agents;
45
using Microsoft.SemanticKernel.Agents.AzureAI;
56
using Microsoft.SemanticKernel.Agents.Chat;
67
using Microsoft.SemanticKernel.ChatCompletion;
7-
using Agent = Azure.AI.Projects.Agent;
88

99
namespace GettingStarted.AzureAgents;
1010

@@ -39,18 +39,18 @@ Consider suggestions when refining an idea.
3939
public async Task UseGroupChatWithTwoAgents()
4040
{
4141
// Define the agents
42-
Agent reviewerModel = await this.AgentsClient.CreateAgentAsync(
42+
PersistentAgent reviewerModel = await this.Client.Administration.CreateAgentAsync(
4343
TestConfiguration.AzureAI.ChatModelId,
4444
ReviewerName,
4545
null,
4646
ReviewerInstructions);
47-
AzureAIAgent agentReviewer = new(reviewerModel, this.AgentsClient);
48-
Agent writerModel = await this.AgentsClient.CreateAgentAsync(
47+
AzureAIAgent agentReviewer = new(reviewerModel, this.Client);
48+
PersistentAgent writerModel = await this.Client.Administration.CreateAgentAsync(
4949
TestConfiguration.AzureAI.ChatModelId,
5050
CopyWriterName,
5151
null,
5252
CopyWriterInstructions);
53-
AzureAIAgent agentWriter = new(writerModel, this.AgentsClient);
53+
AzureAIAgent agentWriter = new(writerModel, this.Client);
5454

5555
// Create a chat for agent interaction.
5656
AgentGroupChat chat =
@@ -89,6 +89,8 @@ public async Task UseGroupChatWithTwoAgents()
8989
finally
9090
{
9191
await chat.ResetAsync();
92+
await agentReviewer.Client.Administration.DeleteAgentAsync(agentReviewer.Id);
93+
await agentWriter.Client.Administration.DeleteAgentAsync(agentWriter.Id);
9294
}
9395
}
9496

0 commit comments

Comments
 (0)