Skip to content

Commit fdc6e68

Browse files
.Net: Semantic Kernel -> Agent Framework - Migration/Samples Update (AF 1.0 Compatible) (#13852)
## Description Updates the SK → Agent Framework migration document, samples, and bridge code from AF preview (`1.0.0-preview.251009.1`) to GA (`1.0.0`). ### Breaking changes addressed | Preview API | AF 1.0 GA | Scope | |---|---|---| | `AgentThread` | `AgentSession` | Core type rename | | `GetNewThread()` | `CreateSessionAsync()` | Now async | | `AgentRunResponse` | `AgentResponse` | Return type rename | | `AgentRunResponseUpdate` | `AgentResponseUpdate` | Streaming type rename | | `CreateAIAgent()` | `AsAIAgent()` | Extension method rename | | `AssistantClient.CreateAIAgentAsync()` | **Removed** | Redirect to Responses API | | `PersistentAgentsClient` | **Obsolete** | Use `AIProjectClient` via `Microsoft.Agents.AI.Foundry` | | `Microsoft.Agents.AI.AzureAI` | `Microsoft.Agents.AI.Foundry` | Package rename | | `InProcessExecution.StreamAsync` | `RunStreamingAsync` | Workflow API | | `AgentRunUpdateEvent` | `AgentResponseUpdateEvent` | Workflow event | | `AIAgent.Id` (virtual) | `IdCore` (protected virtual) | Override pattern | ### Additional discoveries - `using OpenAI.Chat;` required for `ChatClient.AsAIAgent()` extension to resolve - `using OpenAI.Responses;` required for `ResponsesClient.AsAIAgent()` extension to resolve ### What changed **Package versions** (`dotnet/Directory.Packages.props`) - AF packages updated to `1.0.0` - `Microsoft.Agents.AI.AzureAI` → `Microsoft.Agents.AI.Foundry` **Bridge code** (`dotnet/src/Agents/Abstractions/AIAgent/`) - `SemanticKernelAIAgent.cs`: New `Core` method overrides (`CreateSessionCoreAsync`, `RunCoreAsync`, etc.) - `SemanticKernelAIAgentThread` → `SemanticKernelAIAgentSession` (extends `AgentSession`) **31 migration samples** (all compile ✅) - OpenAI/AzureOpenAI: `AsAIAgent`, `CreateSessionAsync`, `using OpenAI.Chat;` - Assistants (8): AF sections rewritten to Responses API - Responses (8): Direct `ResponsesClient.AsAIAgent()` - Foundry (4): `AIProjectClient.AsAIAgent()` via `Microsoft.Agents.AI.Foundry` - Orchestrations (3): `RunStreamingAsync`, `AgentResponseUpdateEvent` **Migration document** (`.github/upgrades/prompts/SemanticKernelToAgentFramework.md`) - All AF preview API references updated to 1.0 GA patterns **Unit/integration tests** (~15 files) - Mechanical renames for `AgentSession`, `AgentResponse`, `CreateSessionAsync` ### Validation 8 standalone console programs were created and executed against AF 1.0.0 NuGet packages with real API keys, validating all migration patterns end-to-end: 1. OpenAI Basics (ChatClient → AsAIAgent, CreateSessionAsync, Run/RunStreaming) 2. OpenAI ToolCall (AIFunctionFactory.Create, tool invocation) 3. OpenAI DI (ServiceProvider registration) 4. OpenAI Responses (ResponsesClient.AsAIAgent) 5. Azure AI Foundry (AIProjectClient.AsAIAgent) 6. Workflows Handoff (HandoffWorkflowBuilder, InProcessExecution.RunStreamingAsync) 7. Session Lifecycle (Create, Serialize, Deserialize, multi-turn) 8. Assistants Migration Path (Responses API as replacement) --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3f0e2d5 commit fdc6e68

63 files changed

Lines changed: 497 additions & 1960 deletions

File tree

Some content is hidden

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

.github/upgrades/prompts/SemanticKernelToAgentFramework.md

Lines changed: 82 additions & 78 deletions
Large diffs are not rendered by default.

dotnet/Directory.Packages.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
<PackageVersion Include="JsonSchema.Net" Version="7.3.4" />
5151
<PackageVersion Include="JsonSchema.Net.Generation" Version="5.0.2" />
5252
<PackageVersion Include="Markdig" Version="0.40.0" />
53-
<PackageVersion Include="Microsoft.Agents.AI.Abstractions" Version="1.0.0-preview.251009.1" />
54-
<PackageVersion Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.251009.1" />
55-
<PackageVersion Include="Microsoft.Agents.AI.AzureAI" Version="1.0.0-preview.251009.1" />
56-
<PackageVersion Include="Microsoft.Agents.AI.Workflows" Version="1.0.0-preview.251009.1" />
53+
<PackageVersion Include="Microsoft.Agents.AI.Abstractions" Version="1.0.0" />
54+
<PackageVersion Include="Microsoft.Agents.AI.Foundry" Version="1.0.0" />
55+
<PackageVersion Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0" />
56+
<PackageVersion Include="Microsoft.Agents.AI.Workflows" Version="1.0.0" />
5757
<PackageVersion Include="Microsoft.Agents.CopilotStudio.Client" Version="1.1.107-beta" />
5858
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13" />
5959
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.14" />
@@ -136,7 +136,7 @@
136136
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.2" />
137137
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.2" />
138138
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.2" />
139-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.4" />
139+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.6" />
140140
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="10.0.2" />
141141
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.2" />
142142
<PackageVersion Include="Microsoft.Extensions.Http" Version="10.0.2" />

dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step01_Concurrent/AgentOrchestrations_Step01_Concurrent.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -11,7 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Agents.AI.Abstractions" />
14-
<PackageReference Include="Microsoft.Agents.AI.AzureAI" />
14+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" />
1515
<PackageReference Include="Microsoft.Agents.AI.Workflows" />
1616
</ItemGroup>
1717

dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step01_Concurrent/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ async Task AFConcurrentAgentWorkflow()
7979
var spanishAgent = GetAFTranslationAgent("Spanish", client);
8080
var concurrentAgentWorkflow = AgentWorkflowBuilder.BuildConcurrent([frenchAgent, spanishAgent]);
8181

82-
await using StreamingRun run = await InProcessExecution.StreamAsync(concurrentAgentWorkflow, "Hello, world!");
82+
await using StreamingRun run = await InProcessExecution.RunStreamingAsync(concurrentAgentWorkflow, "Hello, world!");
8383
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
8484

8585
string? lastExecutorId = null;
8686
await foreach (WorkflowEvent evt in run.WatchStreamAsync().ConfigureAwait(false))
8787
{
88-
if (evt is AgentRunUpdateEvent e)
88+
if (evt is AgentResponseUpdateEvent e)
8989
{
9090
if (string.IsNullOrEmpty(e.Update.Text))
9191
{

dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step02_Sequential/AgentOrchestrations_Step02_Sequential.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -11,7 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Agents.AI.Abstractions" />
14-
<PackageReference Include="Microsoft.Agents.AI.AzureAI" />
14+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" />
1515
<PackageReference Include="Microsoft.Agents.AI.Workflows" />
1616
</ItemGroup>
1717

dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step02_Sequential/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ async Task AFSequentialAgentWorkflow()
8282
var sequentialAgentWorkflow = AgentWorkflowBuilder.BuildSequential(
8383
[frenchAgent, spanishAgent, englishAgent]);
8484

85-
await using StreamingRun run = await InProcessExecution.StreamAsync(sequentialAgentWorkflow, "Hello, world!");
85+
await using StreamingRun run = await InProcessExecution.RunStreamingAsync(sequentialAgentWorkflow, "Hello, world!");
8686
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
8787

8888
string? lastExecutorId = null;
8989
await foreach (WorkflowEvent evt in run.WatchStreamAsync().ConfigureAwait(false))
9090
{
91-
if (evt is AgentRunUpdateEvent e)
91+
if (evt is AgentResponseUpdateEvent e)
9292
{
9393
if (string.IsNullOrEmpty(e.Update.Text))
9494
{

dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step03_Handoff/AgentOrchestrations_Step03_Handoff.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -11,7 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Agents.AI.Abstractions" />
14-
<PackageReference Include="Microsoft.Agents.AI.AzureAI" />
14+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" />
1515
<PackageReference Include="Microsoft.Agents.AI.Workflows" />
1616
</ItemGroup>
1717

dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step03_Handoff/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
#pragma warning disable MAAIW001 // Experimental: HandoffWorkflowBuilder
4+
35
using System.ComponentModel;
46
using System.Text.Json;
57
using Azure.AI.OpenAI;
@@ -207,13 +209,13 @@ async Task AFHandoffAgentWorkflow()
207209
Console.WriteLine($"User: {query}");
208210
messages.Add(new(ChatRole.User, query));
209211

210-
await using var run = await InProcessExecution.StreamAsync(handoffAgentWorkflow, messages);
212+
await using var run = await InProcessExecution.RunStreamingAsync(handoffAgentWorkflow, messages);
211213
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
212214

213215
string? lastExecutorId = null;
214216
await foreach (WorkflowEvent evt in run.WatchStreamAsync().ConfigureAwait(false))
215217
{
216-
if (evt is AgentRunUpdateEvent e)
218+
if (evt is AgentResponseUpdateEvent e)
217219
{
218220
if (string.IsNullOrEmpty(e.Update.Text) && e.Update.Contents.Count == 0)
219221
{

dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step01_Basics/AzureAIFoundry_Step01_Basics.csproj

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

1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.Agents.AI.Abstractions" />
14-
<PackageReference Include="Microsoft.Agents.AI.AzureAI" />
14+
<PackageReference Include="Microsoft.Agents.AI.Foundry" />
1515
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
1616
</ItemGroup>
1717

dotnet/samples/AgentFrameworkMigration/AzureAIFoundry/Step01_Basics/Program.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using Azure.AI.Agents.Persistent;
4+
using Azure.AI.Projects;
45
using Azure.Identity;
56
using Microsoft.Agents.AI;
67
using Microsoft.SemanticKernel;
@@ -67,7 +68,7 @@ async Task SKAgent_As_AFAgentAsync()
6768

6869
#pragma warning restore SKEXP0110 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
6970

70-
var thread = agent.GetNewThread();
71+
var thread = await agent.CreateSessionAsync();
7172
var agentOptions = new ChatClientAgentRunOptions(new() { MaxOutputTokens = 1000 });
7273

7374
var result = await agent.RunAsync(userInput, thread, agentOptions);
@@ -80,9 +81,9 @@ async Task SKAgent_As_AFAgentAsync()
8081
}
8182

8283
// Clean up
83-
if (thread is ChatClientAgentThread chatThread)
84+
if (thread is ChatClientAgentSession chatSession)
8485
{
85-
await azureAgentClient.Threads.DeleteThreadAsync(chatThread.ConversationId);
86+
await azureAgentClient.Threads.DeleteThreadAsync(chatSession.ConversationId);
8687
}
8788
await azureAgentClient.Administration.DeleteAgentAsync(agent.Id);
8889
}
@@ -91,29 +92,23 @@ async Task AFAgentAsync()
9192
{
9293
Console.WriteLine("\n=== AF Agent ===\n");
9394

94-
var azureAgentClient = new PersistentAgentsClient(azureEndpoint, new AzureCliCredential());
95+
// AF 1.0: Use AIProjectClient.AsAIAgent() from Microsoft.Agents.AI.Foundry
96+
var projectClient = new AIProjectClient(new Uri(azureEndpoint), new AzureCliCredential());
9597

96-
var agent = await azureAgentClient.CreateAIAgentAsync(
98+
var agent = projectClient.AsAIAgent(
9799
deploymentName,
98-
name: "GenerateStory",
99-
instructions: "You are good at telling jokes.");
100+
instructions: "You are good at telling jokes.",
101+
name: "GenerateStory");
100102

101-
var thread = agent.GetNewThread();
103+
var session = await agent.CreateSessionAsync();
102104
var agentOptions = new ChatClientAgentRunOptions(new() { MaxOutputTokens = 1000 });
103105

104-
var result = await agent.RunAsync(userInput, thread, agentOptions);
106+
var result = await agent.RunAsync(userInput, session, agentOptions);
105107
Console.WriteLine(result);
106108

107109
Console.WriteLine("---");
108-
await foreach (var update in agent.RunStreamingAsync(userInput, thread, agentOptions))
110+
await foreach (var update in agent.RunStreamingAsync(userInput, session, agentOptions))
109111
{
110112
Console.Write(update);
111113
}
112-
113-
// Clean up
114-
if (thread is ChatClientAgentThread chatThread)
115-
{
116-
await azureAgentClient.Threads.DeleteThreadAsync(chatThread.ConversationId);
117-
}
118-
await azureAgentClient.Administration.DeleteAgentAsync(agent.Id);
119114
}

0 commit comments

Comments
 (0)