From f97664329b31a07bd05ae9959cd2c8af51c686d3 Mon Sep 17 00:00:00 2001
From: Chris <66376200+crickman@users.noreply.github.com>
Date: Mon, 19 May 2025 16:12:21 -0700
Subject: [PATCH] .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`

### Contribution Checklist
- [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 :smile:
---
dotnet/Directory.Packages.props | 4 +-
dotnet/nuget.config | 2 +-
.../Agents/AzureAIAgent_FileManipulation.cs | 15 ++-
.../Concepts/Agents/AzureAIAgent_Streaming.cs | 78 +++++++-----
.../Samples/AzureAIAgentWithMCPToolsSample.cs | 12 +-
.../AzureAIAgent/Step01_AzureAIAgent.cs | 10 +-
.../Step02_AzureAIAgent_Plugins.cs | 13 +-
.../AzureAIAgent/Step03_AzureAIAgent_Chat.cs | 12 +-
.../Step04_AzureAIAgent_CodeInterpreter.cs | 11 +-
.../Step05_AzureAIAgent_FileSearch.cs | 20 +--
.../Step06_AzureAIAgent_OpenAPI.cs | 10 +-
.../Step07_AzureAIAgent_Functions.cs | 9 +-
.../Step08_AzureAIAgent_Declarative.cs | 20 +--
.../Step09_AzureAIAgent_BingGrounding.cs | 41 +++---
.../Step07_Assistant_Declarative.cs | 4 +-
.../Orchestration/Step05_Magentic.cs | 11 +-
.../Step10_MultiAgent_Declarative.cs | 18 +--
.../src/Agents/AzureAI/Agents.AzureAI.csproj | 2 +-
.../AzureAI/AzureAIAgent.ClientFactory.cs | 22 ++--
dotnet/src/Agents/AzureAI/AzureAIAgent.cs | 15 ++-
.../src/Agents/AzureAI/AzureAIAgentThread.cs | 12 +-
dotnet/src/Agents/AzureAI/AzureAIChannel.cs | 6 +-
.../Agents/AzureAI/AzureAIClientProvider.cs | 116 -----------------
.../AzureAI/AzureAIThreadMessageFactory.cs | 2 +-
.../AzureAI/Definition/AzureAIAgentFactory.cs | 11 +-
.../Extensions/AgentDefinitionExtensions.cs | 59 +++------
.../AzureAI/Extensions/AgentRunExtensions.cs | 46 ++++---
.../AgentToolDefinitionExtensions.cs | 24 +---
.../Extensions/KernelFunctionExtensions.cs | 2 +-
.../AzureAI/Internal/AgentMessageFactory.cs | 10 +-
.../AzureAI/Internal/AgentThreadActions.cs | 93 +++++++-------
.../Logging/AgentThreadActionsLogMessages.cs | 2 +-
.../Extensions/AgentDefinitionExtensions.cs | 9 +-
.../src/Agents/OpenAI/OpenAIClientProvider.cs | 1 +
.../AzureAI/AzureAIClientProviderTests.cs | 72 -----------
.../Definition/AzureAIAgentFactoryTests.cs | 14 ++-
.../KernelFunctionExtensionsTests.cs | 2 +-
.../Internal/AgentMessageFactoryTests.cs | 2 +-
.../OpenAIAssistantAgentFactoryTests.cs | 3 +-
.../AssistantClientExtensionsTests.cs | 33 ++---
.../Extensions/OpenAIClientExtensionsTests.cs | 15 +--
.../OpenAI/OpenAIAssistantAgentTests.cs | 16 +--
.../OpenAI/OpenAIAssistantAgentThreadTests.cs | 25 ++--
.../Agents/UnitTests/Yaml/AgentYamlTests.cs | 20 +--
.../Yaml/AzureAIKernelAgentYamlTests.cs | 86 ++-----------
.../Process.Abstractions.csproj | 1 -
.../Process.LocalRuntime.csproj | 1 -
.../Agents/AzureAIAgentTests.cs | 31 +++--
.../AzureAIAgentFixture.cs | 32 ++---
.../Agents/MixedAgentTests.cs | 14 ++-
.../Agents/OpenAIAssistantAgentTests.cs | 119 ++++++++++--------
.../TestSettings/AzureAIConfiguration.cs | 4 +-
.../process/Runtime/AgentThreadFactory.cs | 4 +-
.../samples/AgentUtilities/BaseAgentsTest.cs | 2 +-
.../AgentUtilities/BaseAzureAgentTest.cs | 26 +---
.../samples/AgentUtilities/BaseAzureTest.cs | 21 ++--
.../InternalUtilities/TestConfiguration.cs | 4 +-
57 files changed, 476 insertions(+), 793 deletions(-)
delete mode 100644 dotnet/src/Agents/AzureAI/AzureAIClientProvider.cs
delete mode 100644 dotnet/src/Agents/UnitTests/AzureAI/AzureAIClientProviderTests.cs
diff --git a/dotnet/Directory.Packages.props b/dotnet/Directory.Packages.props
index 3117b8da61..ff391e724d 100644
--- a/dotnet/Directory.Packages.props
+++ b/dotnet/Directory.Packages.props
@@ -17,10 +17,10 @@
+
-
+
-
diff --git a/dotnet/nuget.config b/dotnet/nuget.config
index 1437547185..7d7626e18f 100644
--- a/dotnet/nuget.config
+++ b/dotnet/nuget.config
@@ -3,7 +3,7 @@
-
+
diff --git a/dotnet/samples/Concepts/Agents/AzureAIAgent_FileManipulation.cs b/dotnet/samples/Concepts/Agents/AzureAIAgent_FileManipulation.cs
index 120af82422..6292339d35 100644
--- a/dotnet/samples/Concepts/Agents/AzureAIAgent_FileManipulation.cs
+++ b/dotnet/samples/Concepts/Agents/AzureAIAgent_FileManipulation.cs
@@ -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;
@@ -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:
@@ -31,8 +30,8 @@ public class AzureAIAgent_FileManipulation(ITestOutputHelper output) : BaseAzure
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
@@ -44,8 +43,8 @@ public class AzureAIAgent_FileManipulation(ITestOutputHelper output) : BaseAzure
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.
diff --git a/dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs b/dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs
index d03b223c1c..e01e30f663 100644
--- a/dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs
+++ b/dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs
@@ -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;
@@ -21,23 +20,30 @@ public class AzureAIAgent_Streaming(ITestOutputHelper output) : BaseAzureAgentTe
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]
@@ -47,26 +53,34 @@ public class AzureAIAgent_Streaming(ITestOutputHelper output) : BaseAzureAgentTe
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();
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]
@@ -76,23 +90,31 @@ public class AzureAIAgent_Streaming(ITestOutputHelper output) : BaseAzureAgentTe
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.
diff --git a/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs b/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs
index 843fa00cba..7fd1e1c7fb 100644
--- a/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs
+++ b/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/AzureAIAgentWithMCPToolsSample.cs
@@ -4,7 +4,7 @@ using System;
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;
@@ -68,7 +68,7 @@ internal sealed class AzureAIAgentWithMCPToolsSample : BaseSample
await response!.Thread.DeleteAsync();
// Delete the agent after use
- await agent.Client.DeleteAgentAsync(agent.Id);
+ await agent.Client.Administration.DeleteAgentAsync(agent.Id);
}
///
@@ -86,7 +86,7 @@ internal sealed class AzureAIAgentWithMCPToolsSample : BaseSample
.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);
@@ -96,11 +96,9 @@ internal sealed class AzureAIAgentWithMCPToolsSample : BaseSample
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)
{
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step01_AzureAIAgent.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step01_AzureAIAgent.cs
index 1b3afff467..e348f065eb 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step01_AzureAIAgent.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step01_AzureAIAgent.cs
@@ -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;
@@ -19,11 +20,10 @@ public class Step01_AzureAIAgent(ITestOutputHelper output) : BaseAzureAgentTest(
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)
{
@@ -35,7 +35,7 @@ public class Step01_AzureAIAgent(ITestOutputHelper output) : BaseAzureAgentTest(
};
// Create a thread for the agent conversation.
- AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
+ AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);
try
{
@@ -53,7 +53,7 @@ public class Step01_AzureAIAgent(ITestOutputHelper output) : BaseAzureAgentTest(
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.
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step02_AzureAIAgent_Plugins.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step02_AzureAIAgent_Plugins.cs
index 9089486504..666d2a5b65 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step02_AzureAIAgent_Plugins.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step02_AzureAIAgent_Plugins.cs
@@ -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;
@@ -23,7 +24,7 @@ public class Step02_AzureAIAgent_Plugins(ITestOutputHelper output) : BaseAzureAg
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
@@ -36,7 +37,7 @@ public class Step02_AzureAIAgent_Plugins(ITestOutputHelper output) : BaseAzureAg
finally
{
await thread.DeleteAsync();
- await this.AgentsClient.DeleteAgentAsync(agent.Id);
+ await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}
@@ -47,7 +48,7 @@ public class Step02_AzureAIAgent_Plugins(ITestOutputHelper output) : BaseAzureAg
AzureAIAgent agent = await CreateAzureAgentAsync(plugin: KernelPluginFactory.CreateFromType());
// 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
@@ -57,20 +58,20 @@ public class Step02_AzureAIAgent_Plugins(ITestOutputHelper output) : BaseAzureAg
finally
{
await thread.DeleteAsync();
- await this.AgentsClient.DeleteAgentAsync(agent.Id);
+ await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
}
private async Task 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)
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step03_AzureAIAgent_Chat.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step03_AzureAIAgent_Chat.cs
index c54d9cf788..654ea1d9bf 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step03_AzureAIAgent_Chat.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step03_AzureAIAgent_Chat.cs
@@ -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;
@@ -39,18 +39,18 @@ public class Step03_AzureAIAgent_Chat(ITestOutputHelper output) : BaseAzureAgent
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 =
@@ -89,6 +89,8 @@ public class Step03_AzureAIAgent_Chat(ITestOutputHelper output) : BaseAzureAgent
finally
{
await chat.ResetAsync();
+ await agentReviewer.Client.Administration.DeleteAgentAsync(agentReviewer.Id);
+ await agentWriter.Client.Administration.DeleteAgentAsync(agentWriter.Id);
}
}
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step04_AzureAIAgent_CodeInterpreter.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step04_AzureAIAgent_CodeInterpreter.cs
index 4c36e882d9..ca7558cd6a 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step04_AzureAIAgent_CodeInterpreter.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step04_AzureAIAgent_CodeInterpreter.cs
@@ -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;
@@ -15,13 +16,13 @@ public class Step04_AzureAIAgent_CodeInterpreter(ITestOutputHelper output) : Bas
public async Task UseCodeInterpreterToolWithAgent()
{
// Define the agent
- Azure.AI.Projects.Agent definition = await this.AgentsClient.CreateAgentAsync(
+ PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
- tools: [new Azure.AI.Projects.CodeInterpreterToolDefinition()]);
- AzureAIAgent agent = new(definition, this.AgentsClient);
+ tools: [new CodeInterpreterToolDefinition()]);
+ AzureAIAgent agent = new(definition, this.Client);
// 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
@@ -31,7 +32,7 @@ public class Step04_AzureAIAgent_CodeInterpreter(ITestOutputHelper output) : Bas
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 conversation messages.
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step05_AzureAIAgent_FileSearch.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step05_AzureAIAgent_FileSearch.cs
index 1716c48d1b..9fc515f159 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step05_AzureAIAgent_FileSearch.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step05_AzureAIAgent_FileSearch.cs
@@ -1,5 +1,5 @@
// 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;
@@ -18,12 +18,12 @@ public class Step05_AzureAIAgent_FileSearch(ITestOutputHelper output) : BaseAzur
// Define the agent
await using Stream stream = EmbeddedResource.ReadStream("employees.pdf")!;
- AgentFile fileInfo = await this.AgentsClient.UploadFileAsync(stream, AgentFilePurpose.Agents, "employees.pdf");
- VectorStore fileStore =
- await this.AgentsClient.CreateVectorStoreAsync(
+ PersistentAgentFileInfo fileInfo = await this.Client.Files.UploadFileAsync(stream, PersistentAgentFilePurpose.Agents, "employees.pdf");
+ PersistentAgentsVectorStore fileStore =
+ await this.Client.VectorStores.CreateVectorStoreAsync(
[fileInfo.Id],
metadata: new Dictionary() { { SampleMetadataKey, bool.TrueString } });
- Agent agentModel = await this.AgentsClient.CreateAgentAsync(
+ PersistentAgent agentModel = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
tools: [new FileSearchToolDefinition()],
toolResources: new()
@@ -34,10 +34,10 @@ public class Step05_AzureAIAgent_FileSearch(ITestOutputHelper output) : BaseAzur
}
},
metadata: new Dictionary() { { SampleMetadataKey, bool.TrueString } });
- AzureAIAgent agent = new(agentModel, this.AgentsClient);
+ AzureAIAgent agent = new(agentModel, this.Client);
// Create a thread associated for the agent conversation.
- Microsoft.SemanticKernel.Agents.AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
+ Microsoft.SemanticKernel.Agents.AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);
// Respond to user input
try
@@ -49,9 +49,9 @@ public class Step05_AzureAIAgent_FileSearch(ITestOutputHelper output) : BaseAzur
finally
{
await thread.DeleteAsync();
- await this.AgentsClient.DeleteAgentAsync(agent.Id);
- await this.AgentsClient.DeleteVectorStoreAsync(fileStore.Id);
- await this.AgentsClient.DeleteFileAsync(fileInfo.Id);
+ await this.Client.Administration.DeleteAgentAsync(agent.Id);
+ await this.Client.VectorStores.DeleteVectorStoreAsync(fileStore.Id);
+ await this.Client.Files.DeleteFileAsync(fileInfo.Id);
}
// Local function to invoke agent and display the conversation messages.
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step06_AzureAIAgent_OpenAPI.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step06_AzureAIAgent_OpenAPI.cs
index 194ae7b163..0514069f39 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step06_AzureAIAgent_OpenAPI.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step06_AzureAIAgent_OpenAPI.cs
@@ -1,5 +1,5 @@
// 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;
@@ -24,17 +24,17 @@ public class Step06_AzureAIAgent_OpenAPI(ITestOutputHelper output) : BaseAzureAg
string apiWeather = EmbeddedResource.Read("weather.json");
// Define the agent
- Agent definition = await this.AgentsClient.CreateAgentAsync(
+ PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
tools:
[
new OpenApiToolDefinition("RestCountries", "Retrieve country information", BinaryData.FromString(apiCountries), new OpenApiAnonymousAuthDetails()),
new OpenApiToolDefinition("Weather", "Retrieve weather by location", BinaryData.FromString(apiWeather), new OpenApiAnonymousAuthDetails())
]);
- AzureAIAgent agent = new(definition, this.AgentsClient);
+ AzureAIAgent agent = new(definition, this.Client);
// Create a thread for the agent conversation.
- Microsoft.SemanticKernel.Agents.AgentThread thread = new AzureAIAgentThread(this.AgentsClient, metadata: SampleMetadata);
+ Microsoft.SemanticKernel.Agents.AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);
// Respond to user input
try
@@ -45,7 +45,7 @@ public class Step06_AzureAIAgent_OpenAPI(ITestOutputHelper output) : BaseAzureAg
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 conversation messages.
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step07_AzureAIAgent_Functions.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step07_AzureAIAgent_Functions.cs
index 6eb018aecb..c88da85096 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step07_AzureAIAgent_Functions.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step07_AzureAIAgent_Functions.cs
@@ -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;
@@ -27,19 +28,19 @@ public class Step07_AzureAIAgent_Functions(ITestOutputHelper output) : BaseAzure
KernelPlugin plugin = KernelPluginFactory.CreateFromType();
var tools = plugin.Select(f => f.ToToolDefinition(plugin.Name));
- Azure.AI.Projects.Agent definition = await this.AgentsClient.CreateAgentAsync(
+ PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
model: TestConfiguration.AzureAI.ChatModelId,
name: HostName,
description: null,
instructions: HostInstructions,
tools: tools);
- AzureAIAgent agent = new(definition, this.AgentsClient);
+ AzureAIAgent agent = new(definition, this.Client);
// Add plugin to the agent's Kernel (same as direct Kernel usage).
agent.Kernel.Plugins.Add(plugin);
// 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
@@ -52,7 +53,7 @@ public class Step07_AzureAIAgent_Functions(ITestOutputHelper output) : BaseAzure
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 conversation messages.
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step08_AzureAIAgent_Declarative.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step08_AzureAIAgent_Declarative.cs
index bc09224987..7a50dcf047 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step08_AzureAIAgent_Declarative.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step08_AzureAIAgent_Declarative.cs
@@ -1,5 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
-using Azure.AI.Projects;
using Azure.Core;
using Azure.Identity;
using Microsoft.Extensions.DependencyInjection;
@@ -8,7 +7,6 @@ using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.ChatCompletion;
using Plugins;
-using Agent = Microsoft.SemanticKernel.Agents.Agent;
namespace GettingStarted.AzureAgents;
@@ -37,6 +35,7 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
AzureAIAgentFactory factory = new();
var builder = Kernel.CreateBuilder();
+ builder.Services.AddSingleton(this.Client);
builder.Services.AddSingleton(new AzureCliCredential());
var kernel = builder.Build();
@@ -54,6 +53,8 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
name: MyAgent
description: My helpful agent.
instructions: You are helpful agent.
+ model:
+ id: ${AzureOpenAI:ChatModelId}
""";
AzureAIAgentFactory factory = new();
@@ -190,9 +191,6 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
""";
AzureAIAgentFactory factory = new();
- KernelPlugin plugin = KernelPluginFactory.CreateFromType();
- this._kernel.Plugins.Add(plugin);
-
var agent = await factory.CreateAgentFromYamlAsync(text, new() { Kernel = this._kernel }, TestConfiguration.ConfigurationRoot);
await InvokeAgentAsync(agent!, "What are the key features of the Semantic Kernel?");
@@ -382,7 +380,9 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
AzureAIAgentFactory factory = new();
var promptTemplateFactory = new KernelPromptTemplateFactory();
- var agent = await factory.CreateAgentFromYamlAsync(text, new() { Kernel = this._kernel }, TestConfiguration.ConfigurationRoot);
+ var agent =
+ await factory.CreateAgentFromYamlAsync(text, new() { Kernel = this._kernel }, TestConfiguration.ConfigurationRoot) ??
+ throw new InvalidOperationException("Unable to create agent");
var options = new AgentInvokeOptions()
{
@@ -404,8 +404,8 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
}
finally
{
- var azureaiAgent = agent as AzureAIAgent;
- await azureaiAgent!.Client.DeleteAgentAsync(azureaiAgent.Id);
+ var azureaiAgent = (AzureAIAgent)agent;
+ await azureaiAgent.Client.Administration.DeleteAgentAsync(azureaiAgent.Id);
if (agentThread is not null)
{
@@ -417,7 +417,7 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
public Step08_AzureAIAgent_Declarative(ITestOutputHelper output) : base(output)
{
var builder = Kernel.CreateBuilder();
- builder.Services.AddSingleton(this.Client);
+ builder.Services.AddSingleton(this.Client);
this._kernel = builder.Build();
}
@@ -448,7 +448,7 @@ public class Step08_AzureAIAgent_Declarative : BaseAzureAgentTest
{
var azureaiAgent = agent as AzureAIAgent;
Assert.NotNull(azureaiAgent);
- await azureaiAgent.Client.DeleteAgentAsync(azureaiAgent.Id);
+ await azureaiAgent.Client.Administration.DeleteAgentAsync(azureaiAgent.Id);
if (agentThread is not null)
{
diff --git a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step09_AzureAIAgent_BingGrounding.cs b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step09_AzureAIAgent_BingGrounding.cs
index 71eaae0557..acd085d279 100644
--- a/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step09_AzureAIAgent_BingGrounding.cs
+++ b/dotnet/samples/GettingStartedWithAgents/AzureAIAgent/Step09_AzureAIAgent_BingGrounding.cs
@@ -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;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.ChatCompletion;
-using FoundryAgent = Azure.AI.Projects.Agent;
namespace GettingStarted.AzureAgents;
@@ -17,21 +16,15 @@ public class Step09_AzureAIAgent_BingGrounding(ITestOutputHelper output) : BaseA
public async Task UseBingGroundingToolWithAgent()
{
// Access the BingGrounding connection
- ConnectionsClient connectionsClient = this.Client.GetConnectionsClient();
- ConnectionResponse bingConnection = await connectionsClient.GetConnectionAsync(TestConfiguration.AzureAI.BingConnectionId);
-
- // Define the agent
- ToolConnectionList toolConnections = new()
- {
- ConnectionList = { new ToolConnection(bingConnection.Id) }
- };
- FoundryAgent definition = await this.AgentsClient.CreateAgentAsync(
+ BingGroundingSearchConfiguration bingToolConfiguration = new(TestConfiguration.AzureAI.BingConnectionId);
+ BingGroundingSearchToolParameters bingToolParameters = new([bingToolConfiguration]);
+ PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
- tools: [new BingGroundingToolDefinition(toolConnections)]);
- AzureAIAgent agent = new(definition, this.AgentsClient);
+ tools: [new BingGroundingToolDefinition(bingToolParameters)]);
+ AzureAIAgent agent = new(definition, this.Client);
// Create a thread for the agent conversation.
- AzureAIAgentThread thread = new(this.AgentsClient, metadata: SampleMetadata);
+ AzureAIAgentThread thread = new(this.Client, metadata: SampleMetadata);
// Respond to user input
try
@@ -42,7 +35,7 @@ public class Step09_AzureAIAgent_BingGrounding(ITestOutputHelper output) : BaseA
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 conversation messages.
@@ -62,21 +55,17 @@ public class Step09_AzureAIAgent_BingGrounding(ITestOutputHelper output) : BaseA
public async Task UseBingGroundingToolWithStreaming()
{
// Access the BingGrounding connection
- ConnectionsClient connectionClient = this.Client.GetConnectionsClient();
- ConnectionResponse bingConnectionResponse = await connectionClient.GetConnectionAsync(TestConfiguration.AzureAI.BingConnectionId);
+ BingGroundingSearchConfiguration bingToolConfiguration = new(TestConfiguration.AzureAI.BingConnectionId);
+ BingGroundingSearchToolParameters bingToolParameters = new([bingToolConfiguration]);
// Define the agent
- ToolConnectionList toolConnections = new()
- {
- ConnectionList = { new ToolConnection(bingConnectionResponse.Id) }
- };
- FoundryAgent definition = await this.AgentsClient.CreateAgentAsync(
+ PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
- tools: [new BingGroundingToolDefinition(toolConnections)]);
- AzureAIAgent agent = new(definition, this.AgentsClient);
+ tools: [new BingGroundingToolDefinition(bingToolParameters)]);
+ AzureAIAgent agent = new(definition, this.Client);
// Create a thread for the agent conversation.
- AzureAIAgentThread thread = new(this.AgentsClient, metadata: SampleMetadata);
+ AzureAIAgentThread thread = new(this.Client, metadata: SampleMetadata);
// Respond to user input
try
@@ -96,7 +85,7 @@ public class Step09_AzureAIAgent_BingGrounding(ITestOutputHelper output) : BaseA
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 conversation messages.
diff --git a/dotnet/samples/GettingStartedWithAgents/OpenAIAssistant/Step07_Assistant_Declarative.cs b/dotnet/samples/GettingStartedWithAgents/OpenAIAssistant/Step07_Assistant_Declarative.cs
index f0d193f300..33af885432 100644
--- a/dotnet/samples/GettingStartedWithAgents/OpenAIAssistant/Step07_Assistant_Declarative.cs
+++ b/dotnet/samples/GettingStartedWithAgents/OpenAIAssistant/Step07_Assistant_Declarative.cs
@@ -209,8 +209,8 @@ public class Step07_Assistant_Declarative : BaseAssistantTest
{
if (deleteAgent)
{
- var openaiAgent = agent as OpenAIAssistantAgent;
- await openaiAgent!.Client.DeleteAssistantAsync(openaiAgent.Id);
+ var openaiAgent = (OpenAIAssistantAgent)agent;
+ await openaiAgent.Client.DeleteAssistantAsync(openaiAgent.Id);
}
if (agentThread is not null)
diff --git a/dotnet/samples/GettingStartedWithAgents/Orchestration/Step05_Magentic.cs b/dotnet/samples/GettingStartedWithAgents/Orchestration/Step05_Magentic.cs
index eb30e35e04..e1d6b542a1 100644
--- a/dotnet/samples/GettingStartedWithAgents/Orchestration/Step05_Magentic.cs
+++ b/dotnet/samples/GettingStartedWithAgents/Orchestration/Step05_Magentic.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
+using Azure.AI.Agents.Persistent;
using Azure.Identity;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
@@ -9,7 +10,6 @@ using Microsoft.SemanticKernel.Agents.Orchestration;
using Microsoft.SemanticKernel.Agents.Runtime.InProcess;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;
-using AAIP = Azure.AI.Projects;
namespace GettingStarted.Orchestration;
@@ -40,15 +40,14 @@ public class Step05_Magentic(ITestOutputHelper output) : BaseOrchestrationTest(o
instructions: "You are a Researcher. You find information without additional computation or quantitative analysis.",
kernel: researchKernel);
- AAIP.AIProjectClient projectClient = AzureAIAgent.CreateAzureAIClient(TestConfiguration.AzureAI.ConnectionString, new AzureCliCredential());
- AAIP.AgentsClient agentsClient = projectClient.GetAgentsClient();
- AAIP.Agent definition =
- await agentsClient.CreateAgentAsync(
+ PersistentAgentsClient agentsClient = AzureAIAgent.CreateAgentsClient(TestConfiguration.AzureAI.Endpoint, new AzureCliCredential());
+ PersistentAgent definition =
+ await agentsClient.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
name: "CoderAgent",
description: "Write and executes code to process and analyze data.",
instructions: "You solve questions using code. Please provide detailed analysis and computation process.",
- tools: [new Azure.AI.Projects.CodeInterpreterToolDefinition()]);
+ tools: [new CodeInterpreterToolDefinition()]);
AzureAIAgent coderAgent = new(definition, agentsClient);
// Create a monitor to capturing agent responses (via ResponseCallback)
diff --git a/dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs b/dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs
index 03d13cb3c7..1b816a8663 100644
--- a/dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs
+++ b/dotnet/samples/GettingStartedWithAgents/Step10_MultiAgent_Declarative.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
using System.ClientModel;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Azure.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
@@ -79,7 +79,7 @@ public class Step10_MultiAgent_Declarative : BaseAgentsTest
{
var azureaiAgent = agent as AzureAIAgent;
Assert.NotNull(azureaiAgent);
- await azureaiAgent.Client.DeleteAgentAsync(azureaiAgent.Id);
+ await azureaiAgent.Client.Administration.DeleteAgentAsync(azureaiAgent.Id);
if (agentThread is not null)
{
@@ -97,19 +97,19 @@ public class Step10_MultiAgent_Declarative : BaseAgentsTest
OpenAIAssistantAgent.CreateAzureOpenAIClient(new ApiKeyCredential(this.ApiKey), new Uri(this.Endpoint!)) :
OpenAIAssistantAgent.CreateAzureOpenAIClient(new AzureCliCredential(), new Uri(this.Endpoint!));
- var aiProjectClient = AzureAIAgent.CreateAzureAIClient(TestConfiguration.AzureAI.ConnectionString, new AzureCliCredential());
+ var agentsClient = AzureAIAgent.CreateAgentsClient(TestConfiguration.AzureAI.Endpoint, new AzureCliCredential());
var builder = Kernel.CreateBuilder();
builder.Services.AddSingleton(openaiClient);
- builder.Services.AddSingleton(aiProjectClient);
+ builder.Services.AddSingleton(agentsClient);
AddChatCompletionToKernel(builder);
this._kernel = builder.Build();
- this._kernelAgentFactory = new AggregatorKernelAgentFactory(
- new ChatCompletionAgentFactory(),
- new OpenAIAssistantAgentFactory(),
- new AzureAIAgentFactory()
- );
+ this._kernelAgentFactory =
+ new AggregatorKernelAgentFactory(
+ new ChatCompletionAgentFactory(),
+ new OpenAIAssistantAgentFactory(),
+ new AzureAIAgentFactory());
}
#region private
diff --git a/dotnet/src/Agents/AzureAI/Agents.AzureAI.csproj b/dotnet/src/Agents/AzureAI/Agents.AzureAI.csproj
index 2b0694f699..e448a8f4f2 100644
--- a/dotnet/src/Agents/AzureAI/Agents.AzureAI.csproj
+++ b/dotnet/src/Agents/AzureAI/Agents.AzureAI.csproj
@@ -37,7 +37,7 @@
-
+
diff --git a/dotnet/src/Agents/AzureAI/AzureAIAgent.ClientFactory.cs b/dotnet/src/Agents/AzureAI/AzureAIAgent.ClientFactory.cs
index e3b4e4bfe5..b82b0f0c09 100644
--- a/dotnet/src/Agents/AzureAI/AzureAIAgent.ClientFactory.cs
+++ b/dotnet/src/Agents/AzureAI/AzureAIAgent.ClientFactory.cs
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Net.Http;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Azure.Core;
using Azure.Core.Pipeline;
using Microsoft.SemanticKernel.Http;
@@ -8,32 +8,32 @@ using Microsoft.SemanticKernel.Http;
namespace Microsoft.SemanticKernel.Agents.AzureAI;
///
-/// Provides an for use by .
+/// Provides an for use by .
///
public sealed partial class AzureAIAgent : Agent
{
///
- /// Produces a .
+ /// Produces a .
///
- /// The Azure AI Foundry project connection string, in the form `endpoint;subscription_id;resource_group_name;project_name`.
+ /// The Azure AI Foundry project endpoint.
/// A credential used to authenticate to an Azure Service.
/// A custom for HTTP requests.
- public static AIProjectClient CreateAzureAIClient(
- string connectionString,
+ public static PersistentAgentsClient CreateAgentsClient(
+ string endpoint,
TokenCredential credential,
HttpClient? httpClient = null)
{
- Verify.NotNullOrWhiteSpace(connectionString, nameof(connectionString));
+ Verify.NotNull(endpoint, nameof(endpoint));
Verify.NotNull(credential, nameof(credential));
- AIProjectClientOptions clientOptions = CreateAzureClientOptions(httpClient);
+ PersistentAgentsAdministrationClientOptions clientOptions = CreateAzureClientOptions(httpClient);
- return new AIProjectClient(connectionString, credential, clientOptions);
+ return new PersistentAgentsClient(endpoint, credential, clientOptions);
}
- private static AIProjectClientOptions CreateAzureClientOptions(HttpClient? httpClient)
+ private static PersistentAgentsAdministrationClientOptions CreateAzureClientOptions(HttpClient? httpClient)
{
- AIProjectClientOptions options = new();
+ PersistentAgentsAdministrationClientOptions options = new();
options.AddPolicy(new SemanticKernelHeadersPolicy(), HttpPipelinePosition.PerCall);
diff --git a/dotnet/src/Agents/AzureAI/AzureAIAgent.cs b/dotnet/src/Agents/AzureAI/AzureAIAgent.cs
index 440dd0c74b..c02cff51ea 100644
--- a/dotnet/src/Agents/AzureAI/AzureAIAgent.cs
+++ b/dotnet/src/Agents/AzureAI/AzureAIAgent.cs
@@ -5,13 +5,12 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel.Agents.AzureAI.Internal;
using Microsoft.SemanticKernel.Agents.Extensions;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Diagnostics;
-using AAIP = Azure.AI.Projects;
namespace Microsoft.SemanticKernel.Agents.AzureAI;
@@ -45,7 +44,7 @@ public sealed partial class AzureAIAgent : Agent
///
/// Gets the assistant definition.
///
- public Azure.AI.Projects.Agent Definition { get; private init; }
+ public PersistentAgent Definition { get; private init; }
///
/// Gets the polling behavior for run processing.
@@ -56,13 +55,13 @@ public sealed partial class AzureAIAgent : Agent
/// Initializes a new instance of the class.
///
/// The agent model definition.
- /// An instance.
+ /// An instance.
/// Optional collection of plugins to add to the kernel.
/// An optional factory to produce the for the agent.
/// The format of the prompt template used when "templateFactory" parameter is supplied.
public AzureAIAgent(
- Azure.AI.Projects.Agent model,
- AgentsClient client,
+ PersistentAgent model,
+ PersistentAgentsClient client,
IEnumerable? plugins = null,
IPromptTemplateFactory? templateFactory = null,
string? templateFormat = null)
@@ -95,7 +94,7 @@ public sealed partial class AzureAIAgent : Agent
///
/// The associated client.
///
- public AgentsClient Client { get; }
+ public PersistentAgentsClient Client { get; }
///
/// Adds a message to the specified thread.
@@ -431,7 +430,7 @@ public sealed partial class AzureAIAgent : Agent
this.Logger.LogAzureAIAgentRestoringChannel(nameof(RestoreChannelAsync), nameof(AzureAIChannel), threadId);
- AAIP.AgentThread thread = await this.Client.GetThreadAsync(threadId, cancellationToken).ConfigureAwait(false);
+ PersistentAgentThread thread = await this.Client.Threads.GetThreadAsync(threadId, cancellationToken).ConfigureAwait(false);
this.Logger.LogAzureAIAgentRestoredChannel(nameof(RestoreChannelAsync), nameof(AzureAIChannel), threadId);
diff --git a/dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs b/dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs
index 0965819593..f111a0ca05 100644
--- a/dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs
+++ b/dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs
@@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Azure;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel.Agents.AzureAI.Internal;
namespace Microsoft.SemanticKernel.Agents.AzureAI;
@@ -17,7 +17,7 @@ namespace Microsoft.SemanticKernel.Agents.AzureAI;
///
public sealed class AzureAIAgentThread : AgentThread
{
- private readonly AgentsClient _client;
+ private readonly PersistentAgentsClient _client;
private readonly IEnumerable? _messages;
private readonly ToolResources? _toolResources;
private readonly IReadOnlyDictionary? _metadata;
@@ -34,7 +34,7 @@ public sealed class AzureAIAgentThread : AgentThread
///
/// Metadata to attach to the underlying thread when it is created..
public AzureAIAgentThread(
- AgentsClient client,
+ PersistentAgentsClient client,
IEnumerable? messages = null,
ToolResources? toolResources = null,
IReadOnlyDictionary? metadata = null)
@@ -52,7 +52,7 @@ public sealed class AzureAIAgentThread : AgentThread
///
/// The agents client to use for interacting with threads.
/// The ID of an existing thread to resume.
- public AzureAIAgentThread(AgentsClient client, string id)
+ public AzureAIAgentThread(PersistentAgentsClient client, string id)
{
Verify.NotNull(client);
Verify.NotNull(id);
@@ -78,7 +78,7 @@ public sealed class AzureAIAgentThread : AgentThread
try
{
- var agentThreadResponse = await this._client.CreateThreadAsync(
+ var agentThreadResponse = await this._client.Threads.CreateThreadAsync(
this._messages,
this._toolResources,
this._metadata,
@@ -102,7 +102,7 @@ public sealed class AzureAIAgentThread : AgentThread
try
{
- await this._client.DeleteThreadAsync(this.Id, cancellationToken).ConfigureAwait(false);
+ await this._client.Threads.DeleteThreadAsync(this.Id, cancellationToken).ConfigureAwait(false);
}
catch (RequestFailedException ex) when (ex.Status == 404)
{
diff --git a/dotnet/src/Agents/AzureAI/AzureAIChannel.cs b/dotnet/src/Agents/AzureAI/AzureAIChannel.cs
index fa5991d4ac..e1b57d4ad3 100644
--- a/dotnet/src/Agents/AzureAI/AzureAIChannel.cs
+++ b/dotnet/src/Agents/AzureAI/AzureAIChannel.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel.Agents.AzureAI.Internal;
using Microsoft.SemanticKernel.Agents.Extensions;
using Microsoft.SemanticKernel.Diagnostics;
@@ -12,7 +12,7 @@ namespace Microsoft.SemanticKernel.Agents.AzureAI;
///
/// A specialization for use with .
///
-internal sealed class AzureAIChannel(AgentsClient client, string threadId)
+internal sealed class AzureAIChannel(PersistentAgentsClient client, string threadId)
: AgentChannel
{
///
@@ -53,7 +53,7 @@ internal sealed class AzureAIChannel(AgentsClient client, string threadId)
///
protected override Task ResetAsync(CancellationToken cancellationToken = default)
{
- return client.DeleteThreadAsync(threadId, cancellationToken);
+ return client.Threads.DeleteThreadAsync(threadId, cancellationToken);
}
///
diff --git a/dotnet/src/Agents/AzureAI/AzureAIClientProvider.cs b/dotnet/src/Agents/AzureAI/AzureAIClientProvider.cs
deleted file mode 100644
index 4d9b555151..0000000000
--- a/dotnet/src/Agents/AzureAI/AzureAIClientProvider.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using Azure.AI.Projects;
-using Azure.Core;
-using Azure.Core.Pipeline;
-using Microsoft.SemanticKernel.Http;
-
-namespace Microsoft.SemanticKernel.Agents.AzureAI;
-
-///
-/// Provides an for use by .
-///
-public sealed class AzureAIClientProvider
-{
- private AgentsClient? _agentsClient;
-
- ///
- /// Gets an active client instance.
- ///
- public AIProjectClient Client { get; }
-
- ///
- /// Gets an active assistant client instance.
- ///
- public AgentsClient AgentsClient => this._agentsClient ??= this.Client.GetAgentsClient();
-
- ///
- /// Configuration keys required for management.
- ///
- internal IReadOnlyList ConfigurationKeys { get; }
-
- private AzureAIClientProvider(AIProjectClient client, IEnumerable keys)
- {
- this.Client = client;
- this.ConfigurationKeys = keys.ToArray();
- }
-
- ///
- /// Produces a .
- ///
- /// The Azure AI Foundry project connection string, in the form `endpoint;subscription_id;resource_group_name;project_name`.
- /// A credential used to authenticate to an Azure Service.
- /// A custom for HTTP requests.
- public static AzureAIClientProvider FromConnectionString(
- string connectionString,
- TokenCredential credential,
- HttpClient? httpClient = null)
- {
- Verify.NotNullOrWhiteSpace(connectionString, nameof(connectionString));
- Verify.NotNull(credential, nameof(credential));
-
- AIProjectClientOptions clientOptions = CreateAzureClientOptions(httpClient);
-
- return new(new AIProjectClient(connectionString, credential, clientOptions), CreateConfigurationKeys(connectionString, httpClient));
- }
-
- ///
- /// Provides a client instance directly.
- ///
- public static AzureAIClientProvider FromClient(AIProjectClient client)
- {
- return new(client, [client.GetType().FullName!, client.GetHashCode().ToString()]);
- }
-
- internal static AIProjectClientOptions CreateAzureClientOptions(HttpClient? httpClient)
- {
- AIProjectClientOptions options =
- new()
- {
- Diagnostics = {
- ApplicationId = HttpHeaderConstant.Values.UserAgent,
- }
- };
-
- options.AddPolicy(new SemanticKernelHeadersPolicy(), HttpPipelinePosition.PerCall);
-
- if (httpClient is not null)
- {
- options.Transport = new HttpClientTransport(httpClient);
- // Disable retry policy if and only if a custom HttpClient is provided.
- options.RetryPolicy = new RetryPolicy(maxRetries: 0);
- }
-
- return options;
- }
-
- private static IEnumerable CreateConfigurationKeys(string connectionString, HttpClient? httpClient)
- {
- yield return connectionString;
-
- if (httpClient is not null)
- {
- if (httpClient.BaseAddress is not null)
- {
- yield return httpClient.BaseAddress.AbsoluteUri;
- }
-
- foreach (string header in httpClient.DefaultRequestHeaders.SelectMany(h => h.Value))
- {
- yield return header;
- }
- }
- }
-
- private class SemanticKernelHeadersPolicy : HttpPipelineSynchronousPolicy
- {
- public override void OnSendingRequest(HttpMessage message)
- {
- message.Request.Headers.Add(
- HttpHeaderConstant.Names.SemanticKernelVersion,
- HttpHeaderConstant.Values.GetAssemblyVersion(typeof(AzureAIAgent)));
- }
- }
-}
diff --git a/dotnet/src/Agents/AzureAI/AzureAIThreadMessageFactory.cs b/dotnet/src/Agents/AzureAI/AzureAIThreadMessageFactory.cs
index d37242c522..c5199fb146 100644
--- a/dotnet/src/Agents/AzureAI/AzureAIThreadMessageFactory.cs
+++ b/dotnet/src/Agents/AzureAI/AzureAIThreadMessageFactory.cs
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel.Agents.AzureAI.Internal;
namespace Microsoft.SemanticKernel.Agents.AzureAI;
diff --git a/dotnet/src/Agents/AzureAI/Definition/AzureAIAgentFactory.cs b/dotnet/src/Agents/AzureAI/Definition/AzureAIAgentFactory.cs
index 5bd2213729..b7e169af2d 100644
--- a/dotnet/src/Agents/AzureAI/Definition/AzureAIAgentFactory.cs
+++ b/dotnet/src/Agents/AzureAI/Definition/AzureAIAgentFactory.cs
@@ -3,7 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
namespace Microsoft.SemanticKernel.Agents.AzureAI;
@@ -33,14 +33,13 @@ public sealed class AzureAIAgentFactory : AgentFactory
if (agentDefinition.Type?.Equals(AzureAIAgentType, System.StringComparison.Ordinal) ?? false)
{
- var projectClient = agentDefinition.GetAIProjectClient(kernel);
+ var client = agentDefinition.GetAgentsClient(kernel);
- AgentsClient client = projectClient.GetAgentsClient();
- Azure.AI.Projects.Agent agent;
+ PersistentAgent agent;
if (!string.IsNullOrEmpty(agentDefinition.Id))
{
// Get an existing agent
- agent = await client.GetAgentAsync(
+ agent = await client.Administration.GetAgentAsync(
agentDefinition.Id,
cancellationToken: cancellationToken).ConfigureAwait(false);
@@ -57,7 +56,7 @@ public sealed class AzureAIAgentFactory : AgentFactory
Verify.NotNull(agentDefinition.Model);
Verify.NotNull(agentDefinition.Model.Id);
- agent = await client.CreateAgentAsync(
+ agent = await client.Administration.CreateAgentAsync(
model: agentDefinition.Model.Id,
name: agentDefinition.Name,
description: agentDefinition.Description,
diff --git a/dotnet/src/Agents/AzureAI/Extensions/AgentDefinitionExtensions.cs b/dotnet/src/Agents/AzureAI/Extensions/AgentDefinitionExtensions.cs
index 1f11bc5f02..517266c0fc 100644
--- a/dotnet/src/Agents/AzureAI/Extensions/AgentDefinitionExtensions.cs
+++ b/dotnet/src/Agents/AzureAI/Extensions/AgentDefinitionExtensions.cs
@@ -2,7 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
using Azure.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel.Http;
@@ -20,24 +20,20 @@ internal static class AgentDefinitionExtensions
private const string CodeInterpreterType = "code_interpreter";
private const string FileSearchType = "file_search";
private const string FunctionType = "function";
- private const string MicrosoftFabricType = "fabric_aiskill";
private const string OpenApiType = "openapi";
- private const string SharepointGroundingType = "sharepoint_grounding";
- private static readonly string[] s_validToolTypes = new string[]
- {
+ private static readonly string[] s_validToolTypes =
+ [
AzureAISearchType,
AzureFunctionType,
BingGroundingType,
CodeInterpreterType,
FileSearchType,
FunctionType,
- MicrosoftFabricType,
OpenApiType,
- SharepointGroundingType
- };
+ ];
- private const string ConnectionString = "connection_string";
+ private const string Endpoint = "endpoint";
///
/// Return the Azure AI tool definitions which corresponds with the provided .
@@ -58,9 +54,7 @@ internal static class AgentDefinitionExtensions
CodeInterpreterType => CreateCodeInterpreterToolDefinition(tool),
FileSearchType => CreateFileSearchToolDefinition(tool),
FunctionType => CreateFunctionToolDefinition(tool),
- MicrosoftFabricType => CreateMicrosoftFabricToolDefinition(tool),
OpenApiType => CreateOpenApiToolDefinition(tool),
- SharepointGroundingType => CreateSharepointGroundingToolDefinition(tool),
_ => throw new NotSupportedException($"Unable to create Azure AI tool definition because of unsupported tool type: {tool.Type}, supported tool types are: {string.Join(",", s_validToolTypes)}"),
};
}) ?? [];
@@ -108,11 +102,11 @@ internal static class AgentDefinitionExtensions
}
///
- /// Return the to be used with the specified .
+ /// Return the to be used with the specified .
///
- /// Agent definition which will be used to provide connection for the .
- /// Kernel instance which will be used to resolve a default .
- public static AIProjectClient GetAIProjectClient(this AgentDefinition agentDefinition, Kernel kernel)
+ /// Agent definition which will be used to provide connection for the .
+ /// Kernel instance which will be used to resolve a default .
+ public static PersistentAgentsClient GetAgentsClient(this AgentDefinition agentDefinition, Kernel kernel)
{
Verify.NotNull(agentDefinition);
@@ -120,21 +114,20 @@ internal static class AgentDefinitionExtensions
var connection = agentDefinition?.Model?.Connection;
if (connection is not null)
{
- if (connection.ExtensionData.TryGetValue(ConnectionString, out var value) && value is string connectionString)
+ if (connection.ExtensionData.TryGetValue(Endpoint, out var value) && value is string endpoint)
{
#pragma warning disable CA2000 // Dispose objects before losing scope, not relevant because the HttpClient is created and may be used elsewhere
var httpClient = HttpClientProvider.GetHttpClient(kernel.Services);
#pragma warning restore CA2000 // Dispose objects before losing scope
- AIProjectClientOptions clientOptions = AzureAIClientProvider.CreateAzureClientOptions(httpClient);
var tokenCredential = kernel.Services.GetRequiredService();
- return new(connectionString, tokenCredential, clientOptions);
+ return AzureAIAgent.CreateAgentsClient(endpoint, tokenCredential, httpClient);
}
}
// Return the client registered on the kernel
- var client = kernel.GetAllServices().FirstOrDefault();
- return (AIProjectClient?)client ?? throw new InvalidOperationException("AzureAI project client not found.");
+ var client = kernel.GetAllServices().FirstOrDefault();
+ return (PersistentAgentsClient?)client ?? throw new InvalidOperationException("AzureAI project client not found.");
}
#region private
@@ -184,7 +177,7 @@ internal static class AgentDefinitionExtensions
return null;
}
- private static AzureAISearchResource? GetAzureAISearchResource(this AgentDefinition agentDefinition)
+ private static AzureAISearchToolResource? GetAzureAISearchResource(this AgentDefinition agentDefinition)
{
Verify.NotNull(agentDefinition);
@@ -205,7 +198,7 @@ internal static class AgentDefinitionExtensions
string filter = azureAISearch.GetFilter() ?? string.Empty;
AzureAISearchQueryType? queryType = azureAISearch.GetAzureAISearchQueryType();
- return new AzureAISearchResource(indexConnectionId, indexName, topK, filter, queryType);
+ return new AzureAISearchToolResource(indexConnectionId, indexName, topK, filter, queryType);
}
return null;
@@ -237,9 +230,9 @@ internal static class AgentDefinitionExtensions
{
Verify.NotNull(tool);
- ToolConnectionList bingGrounding = tool.GetToolConnectionList();
+ BingGroundingSearchToolParameters bingToolParameters = new(tool.GetToolConnections().Select(connectionId => new BingGroundingSearchConfiguration(connectionId)));
- return new BingGroundingToolDefinition(bingGrounding);
+ return new BingGroundingToolDefinition(bingToolParameters);
}
private static CodeInterpreterToolDefinition CreateCodeInterpreterToolDefinition(AgentToolDefinition tool)
@@ -270,15 +263,6 @@ internal static class AgentDefinitionExtensions
return new FunctionToolDefinition(name, description, parameters);
}
- private static MicrosoftFabricToolDefinition CreateMicrosoftFabricToolDefinition(AgentToolDefinition tool)
- {
- Verify.NotNull(tool);
-
- ToolConnectionList fabricAiSkill = tool.GetToolConnectionList();
-
- return new MicrosoftFabricToolDefinition(fabricAiSkill);
- }
-
private static OpenApiToolDefinition CreateOpenApiToolDefinition(AgentToolDefinition tool)
{
Verify.NotNull(tool);
@@ -292,14 +276,5 @@ internal static class AgentDefinitionExtensions
return new OpenApiToolDefinition(name, description, spec, auth);
}
-
- private static SharepointToolDefinition CreateSharepointGroundingToolDefinition(AgentToolDefinition tool)
- {
- Verify.NotNull(tool);
-
- ToolConnectionList sharepointGrounding = tool.GetToolConnectionList();
-
- return new SharepointToolDefinition(sharepointGrounding);
- }
#endregion
}
diff --git a/dotnet/src/Agents/AzureAI/Extensions/AgentRunExtensions.cs b/dotnet/src/Agents/AzureAI/Extensions/AgentRunExtensions.cs
index 7334941407..53133baafd 100644
--- a/dotnet/src/Agents/AzureAI/Extensions/AgentRunExtensions.cs
+++ b/dotnet/src/Agents/AzureAI/Extensions/AgentRunExtensions.cs
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
-using Azure.AI.Projects;
+using Azure;
+using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel.Agents.AzureAI.Internal;
namespace Microsoft.SemanticKernel.Agents.AzureAI.Extensions;
@@ -19,24 +19,19 @@ namespace Microsoft.SemanticKernel.Agents.AzureAI.Extensions;
internal static class AgentRunExtensions
{
public static async IAsyncEnumerable GetStepsAsync(
- this AgentsClient client,
- ThreadRun run,
- [EnumeratorCancellation] CancellationToken cancellationToken)
+ this PersistentAgentsClient client,
+ ThreadRun run,
+ [EnumeratorCancellation] CancellationToken cancellationToken)
{
- PageableList? steps = null;
- do
+ AsyncPageable? steps = client.Runs.GetRunStepsAsync(run, cancellationToken: cancellationToken);
+ await foreach (RunStep step in steps.ConfigureAwait(false))
{
- steps = await client.GetRunStepsAsync(run, after: steps?.LastId, cancellationToken: cancellationToken).ConfigureAwait(false);
- foreach (RunStep step in steps)
- {
- yield return step;
- }
+ yield return step;
}
- while (steps?.HasMore ?? false);
}
public static async Task CreateAsync(
- this AgentsClient client,
+ this PersistentAgentsClient client,
string threadId,
AzureAIAgent agent,
string? instructions,
@@ -44,16 +39,16 @@ internal static class AgentRunExtensions
AzureAIInvocationOptions? invocationOptions,
CancellationToken cancellationToken)
{
- TruncationObject? truncationStrategy = GetTruncationStrategy(invocationOptions);
+ Truncation? truncationStrategy = GetTruncationStrategy(invocationOptions);
BinaryData? responseFormat = GetResponseFormat(invocationOptions);
return
- await client.CreateRunAsync(
+ await client.Runs.CreateRunAsync(
threadId,
- agent.Definition.Id,
+ agent.Id,
overrideModelName: invocationOptions?.ModelName,
overrideInstructions: invocationOptions?.OverrideInstructions ?? instructions,
additionalInstructions: invocationOptions?.AdditionalInstructions,
- additionalMessages: AgentMessageFactory.GetThreadMessages(invocationOptions?.AdditionalMessages).ToArray(),
+ additionalMessages: [.. AgentMessageFactory.GetThreadMessages(invocationOptions?.AdditionalMessages)],
overrideTools: tools,
stream: false,
temperature: invocationOptions?.Temperature,
@@ -72,11 +67,12 @@ internal static class AgentRunExtensions
private static BinaryData? GetResponseFormat(AzureAIInvocationOptions? invocationOptions)
{
return invocationOptions?.EnableJsonResponse == true ?
- BinaryData.FromString(ResponseFormat.JsonObject.ToString()) :
+ //BinaryData.FromString(ResponseFormat.JsonObject.ToString()) :
+ BinaryData.FromString("// %%% TODO") :
null;
}
- private static TruncationObject? GetTruncationStrategy(AzureAIInvocationOptions? invocationOptions)
+ private static Truncation? GetTruncationStrategy(AzureAIInvocationOptions? invocationOptions)
{
return invocationOptions?.TruncationMessageCount == null ?
null :
@@ -87,7 +83,7 @@ internal static class AgentRunExtensions
}
public static IAsyncEnumerable CreateStreamingAsync(
- this AgentsClient client,
+ this PersistentAgentsClient client,
string threadId,
AzureAIAgent agent,
string? instructions,
@@ -95,16 +91,16 @@ internal static class AgentRunExtensions
AzureAIInvocationOptions? invocationOptions,
CancellationToken cancellationToken)
{
- TruncationObject? truncationStrategy = GetTruncationStrategy(invocationOptions);
+ Truncation? truncationStrategy = GetTruncationStrategy(invocationOptions);
BinaryData? responseFormat = GetResponseFormat(invocationOptions);
return
- client.CreateRunStreamingAsync(
+ client.Runs.CreateRunStreamingAsync(
threadId,
- agent.Definition.Id,
+ agent.Id,
overrideModelName: invocationOptions?.ModelName,
overrideInstructions: invocationOptions?.OverrideInstructions ?? instructions,
additionalInstructions: invocationOptions?.AdditionalInstructions,
- additionalMessages: AgentMessageFactory.GetThreadMessages(invocationOptions?.AdditionalMessages).ToArray(),
+ additionalMessages: [.. AgentMessageFactory.GetThreadMessages(invocationOptions?.AdditionalMessages)],
overrideTools: tools,
temperature: invocationOptions?.Temperature,
topP: invocationOptions?.TopP,
diff --git a/dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs b/dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs
index e85092fe24..053c8dc52f 100644
--- a/dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs
+++ b/dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs
@@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using Azure.AI.Projects;
+using Azure.AI.Agents.Persistent;
namespace Microsoft.SemanticKernel.Agents.AzureAI;
@@ -75,20 +75,6 @@ internal static class AgentToolDefinitionExtensions
return details;
}
- internal static ToolConnectionList GetToolConnectionList(this AgentToolDefinition agentToolDefinition)
- {
- Verify.NotNull(agentToolDefinition.Options);
-
- var toolConnections = agentToolDefinition.GetToolConnections();
-
- var toolConnectionList = new ToolConnectionList();
- if (toolConnections is not null)
- {
- toolConnectionList.ConnectionList.AddRange(toolConnections);
- }
- return toolConnectionList;
- }
-
internal static BinaryData GetSpecification(this AgentToolDefinition agentToolDefinition)
{
Verify.NotNull(agentToolDefinition.Options);
@@ -121,7 +107,7 @@ internal static class AgentToolDefinitionExtensions
internal static List? GetVectorStoreIds(this AgentToolDefinition agentToolDefinition)
{
- return agentToolDefinition.GetOption>("vector_store_ids")?.Select(id => id.ToString()!).ToList();
+ return agentToolDefinition.GetOption>("vector_store_ids")?.Select(id => $"{id}").ToList();
}
internal static List? GetFileIds(this AgentToolDefinition agentToolDefinition)
@@ -236,13 +222,13 @@ internal static class AgentToolDefinitionExtensions
return null;
}
- private static List GetToolConnections(this AgentToolDefinition agentToolDefinition)
+ internal static List GetToolConnections(this AgentToolDefinition agentToolDefinition)
{
Verify.NotNull(agentToolDefinition.Options);
- var toolConnections = agentToolDefinition.GetRequiredOption>("tool_connections");
+ List