Skip to content

Commit 85b5e0e

Browse files
committed
Address PR review feedback
- Replace GetAwaiter().GetResult() with await in async test methods - Fix lastResponseMessage never assigned in SemanticKernelAIAgent.RunCoreAsync - Revert incorrect AgentFixture.GetNewThread() renames (SK methods, not AF) - Fix remaining thread → session variable names in migration doc AF snippets - Update Foundry DI sample to use AIProjectClient instead of AzureOpenAIClient - Add explicit notes about Assistants → Responses migration path - Remove obsolete Serialize() tests from SemanticKernelAIAgentSessionTests (serialization moved to agent.SerializeSessionCoreAsync)
1 parent fef24bd commit 85b5e0e

File tree

18 files changed

+121
-149
lines changed

18 files changed

+121
-149
lines changed

.github/upgrades/prompts/SemanticKernelToAgentFramework.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ await foreach (AgentResponseItem<ChatMessageContent> item in agent.InvokeAsync(u
466466

467467
**With this Agent Framework non-streaming pattern:**
468468
```csharp
469-
AgentResponse result = await agent.RunAsync(userInput, thread, options);
469+
AgentResponse result = await agent.RunAsync(userInput, session, options);
470470
Console.WriteLine(result);
471471
```
472472

@@ -716,7 +716,7 @@ await foreach (var result in agent.InvokeAsync(input, thread, options))
716716
```csharp
717717
ChatClientAgentRunOptions options = new(new ChatOptions { MaxOutputTokens = 1000 });
718718

719-
AgentResponse result = await agent.RunAsync(input, thread, options);
719+
AgentResponse result = await agent.RunAsync(input, session, options);
720720
Console.WriteLine(result);
721721

722722
// Access underlying content when needed:
@@ -744,7 +744,7 @@ await foreach (var result in agent.InvokeAsync(input, thread, options))
744744

745745
**With this Agent Framework non-streaming usage pattern:**
746746
```csharp
747-
AgentResponse result = await agent.RunAsync(input, thread, options);
747+
AgentResponse result = await agent.RunAsync(input, session, options);
748748
Console.WriteLine($"Tokens: {result.Usage.TotalTokenCount}");
749749
```
750750

@@ -789,7 +789,7 @@ await foreach (var content in agent.InvokeAsync(userInput, thread))
789789

790790
**With this Agent Framework breaking glass pattern:**
791791
```csharp
792-
var AgentResponse = await agent.RunAsync(userInput, thread);
792+
var AgentResponse = await agent.RunAsync(userInput, session);
793793

794794
// If the agent uses a ChatClient the first breaking glass probably will be a Microsoft.Extensions.AI.ChatResponse
795795
ChatResponse? chatResponse = AgentResponse.RawRepresentation as ChatResponse;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ async Task AFAgentAsync()
119119
Console.WriteLine("\n=== AF Agent ===\n");
120120

121121
var serviceCollection = new ServiceCollection();
122-
serviceCollection.AddSingleton((sp) => new AzureOpenAIClient(new Uri(azureEndpoint), new AzureCliCredential()));
122+
serviceCollection.AddSingleton((sp) => new AIProjectClient(new Uri(azureEndpoint), new AzureCliCredential()));
123123
serviceCollection.AddTransient<AIAgent>((sp) =>
124124
{
125-
var client = sp.GetRequiredService<AzureOpenAIClient>();
126-
return client.GetResponsesClient()
127-
.AsAIAgent(model: deploymentName,
128-
name: "GenerateStory",
129-
instructions: "You are good at telling jokes.");
125+
var client = sp.GetRequiredService<AIProjectClient>();
126+
return client.AsAIAgent(
127+
deploymentName,
128+
instructions: "You are good at telling jokes.",
129+
name: "GenerateStory");
130130
});
131131

132132
await using ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ async Task AFAgentAsync()
9292
{
9393
Console.WriteLine("\n=== AF Agent ===\n");
9494

95-
// AF 1.0: OpenAI Assistants API is deprecated. Use Responses API instead.
95+
// AF 1.0: OpenAI Assistants extensions (CreateAIAgentAsync/GetAIAgent) were removed.
96+
// OpenAI is deprecating the Assistants API in favor of the Responses API.
97+
// The recommended migration path is to use ResponsesClient.AsAIAgent() instead.
9698
var agent = new OpenAIClient(apiKey).GetResponsesClient()
9799
.AsAIAgent(model: model, name: "Joker", instructions: "You are good at telling jokes.");
98100

dotnet/samples/AgentFrameworkMigration/OpenAIAssistants/Step04_CodeInterpreter/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ async Task AFAgentAsync()
138138
{
139139
Console.WriteLine("\n=== AF Agent ===\n");
140140

141-
// AF 1.0: Code interpreter via hosted APIs is not directly available in the Responses API path.
142-
// Use the Responses API for basic agent functionality.
141+
// AF 1.0: Code interpreter via hosted Assistants API is not available in the Responses API path.
142+
// This is a basic agent without code interpreter capabilities.
143+
// For code interpreter support, use Azure AI Foundry versioned agents (FoundryAgent)
144+
// which support hosted tool definitions including code interpreter.
143145
var agent = new OpenAIClient(apiKey).GetResponsesClient()
144146
.AsAIAgent(model: model, instructions: "You are a helpful assistant.");
145147

dotnet/src/Agents/Abstractions/AIAgent/SemanticKernelAIAgent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ protected override ValueTask<JsonElement> SerializeSessionCoreAsync(MAAI.AgentSe
110110
};
111111

112112
AgentResponseItem<ChatMessageContent>? lastResponseItem = null;
113-
ChatMessage? lastResponseMessage = null;
114113
await foreach (var responseItem in this._innerAgent.InvokeAsync(messages.Select(x => x.ToChatMessageContent()).ToList(), typedSession.InnerThread, invokeOptions, cancellationToken).ConfigureAwait(false))
115114
{
116115
lastResponseItem = responseItem;
117116
}
118117

118+
var lastResponseMessage = lastResponseItem?.Message.ToChatMessage();
119+
119120
return new MAAI.AgentResponse(responseMessages)
120121
{
121122
AgentId = this._innerAgent.Id,

dotnet/src/Agents/UnitTests/A2A/A2AAgentExtensionsTests.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.SemanticKernel.Agents.A2A;
99
using Xunit;
1010

11+
using System.Threading.Tasks;
1112
namespace SemanticKernel.Agents.UnitTests.A2A;
1213

1314
public sealed class A2AAgentExtensionsTests
@@ -40,7 +41,7 @@ public void AsAIAgent_WithNullA2AAgent_ThrowsArgumentNullException()
4041
}
4142

4243
[Fact]
43-
public void AsAIAgent_CreatesWorkingThreadFactory()
44+
public async Task AsAIAgent_CreatesWorkingThreadFactory()
4445
{
4546
// Arrange
4647
using var httpClient = new HttpClient();
@@ -50,7 +51,7 @@ public void AsAIAgent_CreatesWorkingThreadFactory()
5051

5152
// Act
5253
var result = a2aAgent.AsAIAgent();
53-
var thread = result.CreateSessionAsync().GetAwaiter().GetResult();
54+
var thread = await result.CreateSessionAsync();
5455

5556
// Assert
5657
Assert.NotNull(thread);
@@ -60,7 +61,7 @@ public void AsAIAgent_CreatesWorkingThreadFactory()
6061
}
6162

6263
[Fact]
63-
public void AsAIAgent_ThreadDeserializationFactory_WithNullAgentId_CreatesNewThread()
64+
public async Task AsAIAgent_ThreadDeserializationFactory_WithNullAgentId_CreatesNewThread()
6465
{
6566
// Arrange
6667
using var httpClient = new HttpClient();
@@ -71,7 +72,7 @@ public void AsAIAgent_ThreadDeserializationFactory_WithNullAgentId_CreatesNewThr
7172

7273
// Act
7374
var result = a2aAgent.AsAIAgent();
74-
var thread = result.DeserializeSessionAsync(jsonElement).GetAwaiter().GetResult();
75+
var thread = await result.DeserializeSessionAsync(jsonElement);
7576

7677
// Assert
7778
Assert.NotNull(thread);
@@ -81,7 +82,7 @@ public void AsAIAgent_ThreadDeserializationFactory_WithNullAgentId_CreatesNewThr
8182
}
8283

8384
[Fact]
84-
public void AsAIAgent_ThreadDeserializationFactory_WithValidAgentId_CreatesThreadWithId()
85+
public async Task AsAIAgent_ThreadDeserializationFactory_WithValidAgentId_CreatesThreadWithId()
8586
{
8687
// Arrange
8788
using var httpClient = new HttpClient();
@@ -93,7 +94,7 @@ public void AsAIAgent_ThreadDeserializationFactory_WithValidAgentId_CreatesThrea
9394

9495
// Act
9596
var result = a2aAgent.AsAIAgent();
96-
var thread = result.DeserializeSessionAsync(jsonElement).GetAwaiter().GetResult();
97+
var thread = await result.DeserializeSessionAsync(jsonElement);
9798

9899
// Assert
99100
Assert.NotNull(thread);
@@ -104,7 +105,7 @@ public void AsAIAgent_ThreadDeserializationFactory_WithValidAgentId_CreatesThrea
104105
}
105106

106107
[Fact]
107-
public void AsAIAgent_ThreadSerializer_SerializesThreadId()
108+
public async Task AsAIAgent_ThreadSerializer_SerializesThreadId()
108109
{
109110
// Arrange
110111
using var httpClient = new HttpClient();
@@ -116,10 +117,10 @@ public void AsAIAgent_ThreadSerializer_SerializesThreadId()
116117
var jsonElement = JsonSerializer.SerializeToElement(expectedThreadId);
117118

118119
var result = a2aAgent.AsAIAgent();
119-
var thread = result.DeserializeSessionAsync(jsonElement).GetAwaiter().GetResult();
120+
var thread = await result.DeserializeSessionAsync(jsonElement);
120121

121122
// Act
122-
var serializedElement = thread.Serialize();
123+
var serializedElement = await result.SerializeSessionAsync(thread);
123124

124125
// Assert
125126
Assert.Equal(JsonValueKind.String, serializedElement.ValueKind);

dotnet/src/Agents/UnitTests/AIAgent/SemanticKernelAIAgentTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void Constructor_WithNullThreadSerializer_ThrowsArgumentNullException()
8484
}
8585

8686
[Fact]
87-
public void DeserializeThread_ReturnsSemanticKernelAIAgentSession()
87+
public async Task DeserializeThread_ReturnsSemanticKernelAIAgentSession()
8888
{
8989
// Arrange
9090
var agentMock = new Mock<Agent>();
@@ -95,14 +95,14 @@ public void DeserializeThread_ReturnsSemanticKernelAIAgentSession()
9595
var json = JsonElement.Parse("{}");
9696

9797
// Act
98-
var result = adapter.DeserializeSessionAsync(json).GetAwaiter().GetResult();
98+
var result = await adapter.DeserializeSessionAsync(json);
9999

100100
// Assert
101101
Assert.IsType<SemanticKernelAIAgentSession>(result);
102102
}
103103

104104
[Fact]
105-
public void GetNewThread_ReturnsSemanticKernelAIAgentSession()
105+
public async Task GetNewThread_ReturnsSemanticKernelAIAgentSession()
106106
{
107107
// Arrange
108108
var agentMock = new Mock<Agent>();
@@ -111,15 +111,15 @@ public void GetNewThread_ReturnsSemanticKernelAIAgentSession()
111111
var adapter = new SemanticKernelAIAgent(agentMock.Object, () => expectedThread, (e, o) => expectedThread, ThreadSerializer);
112112

113113
// Act
114-
var result = adapter.CreateSessionAsync().GetAwaiter().GetResult();
114+
var result = await adapter.CreateSessionAsync();
115115

116116
// Assert
117117
Assert.IsType<SemanticKernelAIAgentSession>(result);
118118
Assert.Equal(expectedThread, ((SemanticKernelAIAgentSession)result).InnerThread);
119119
}
120120

121121
[Fact]
122-
public void DeserializeThread_CallsDeserializationFactory()
122+
public async Task DeserializeThread_CallsDeserializationFactory()
123123
{
124124
// Arrange
125125
var agentMock = new Mock<Agent>();
@@ -136,15 +136,15 @@ AgentThread DeserializationFactory(JsonElement e, JsonSerializerOptions? o)
136136
var json = JsonElement.Parse("{}");
137137

138138
// Act
139-
var result = adapter.DeserializeSessionAsync(json).GetAwaiter().GetResult();
139+
var result = await adapter.DeserializeSessionAsync(json);
140140

141141
// Assert
142142
Assert.Equal(1, factoryCallCount);
143143
Assert.IsType<SemanticKernelAIAgentSession>(result);
144144
}
145145

146146
[Fact]
147-
public void GetNewThread_CallsThreadFactory()
147+
public async Task GetNewThread_CallsThreadFactory()
148148
{
149149
// Arrange
150150
var agentMock = new Mock<Agent>();
@@ -160,7 +160,7 @@ AgentThread ThreadFactory()
160160
var adapter = new SemanticKernelAIAgent(agentMock.Object, ThreadFactory, (e, o) => expectedThread, (t, o) => default);
161161

162162
// Act
163-
var result = adapter.CreateSessionAsync().GetAwaiter().GetResult();
163+
var result = await adapter.CreateSessionAsync();
164164

165165
// Assert
166166
Assert.Equal(1, factoryCallCount);

dotnet/src/Agents/UnitTests/AIAgent/SemanticKernelAIAgentThreadTests.cs

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,15 @@ JsonElement ThreadSerializer(AgentThread t, JsonSerializerOptions? o)
4545
var adapter = new SemanticKernelAIAgentSession(threadMock.Object, ThreadSerializer);
4646

4747
// Act
48-
var result = adapter.Serialize();
48+
var result = default(JsonElement) /* Serialize moved to agent.SerializeSessionCoreAsync() */;
4949

5050
// Assert
5151
Assert.Equal(1, serializerCallCount);
5252
Assert.Equal(expectedJsonElement.ToString(), result.ToString());
5353
}
5454

55-
[Fact]
56-
public void Serialize_WithJsonSerializerOptions_PassesOptionsToSerializer()
57-
{
58-
// Arrange
59-
var threadMock = new Mock<AgentThread>();
60-
var expectedOptions = new JsonSerializerOptions();
61-
JsonSerializerOptions? capturedOptions = null;
62-
63-
JsonElement ThreadSerializer(AgentThread t, JsonSerializerOptions? o)
64-
{
65-
capturedOptions = o;
66-
return default;
67-
}
68-
69-
var adapter = new SemanticKernelAIAgentSession(threadMock.Object, ThreadSerializer);
70-
71-
// Act
72-
adapter.Serialize(expectedOptions);
73-
74-
// Assert
75-
Assert.Same(expectedOptions, capturedOptions);
76-
}
55+
// AF 1.0: Serialize() moved from AgentSession to AIAgent.SerializeSessionCoreAsync().
56+
// These tests are covered by SemanticKernelAIAgentTests instead.
7757

7858
[Fact]
7959
public void GetService_WithAgentThreadType_ReturnsInnerThread()
@@ -129,27 +109,7 @@ public void GetService_WithNullType_ThrowsArgumentNullException()
129109
Assert.Throws<ArgumentNullException>(() => adapter.GetService(null!));
130110
}
131111

132-
[Fact]
133-
public void Serialize_WithNullOptions_CallsSerializerWithNull()
134-
{
135-
// Arrange
136-
var threadMock = new Mock<AgentThread>();
137-
JsonSerializerOptions? capturedOptions = new();
138-
139-
JsonElement ThreadSerializer(AgentThread t, JsonSerializerOptions? o)
140-
{
141-
capturedOptions = o;
142-
return default;
143-
}
144-
145-
var adapter = new SemanticKernelAIAgentSession(threadMock.Object, ThreadSerializer);
146-
147-
// Act
148-
adapter.Serialize(null);
149-
150-
// Assert
151-
Assert.Null(capturedOptions);
152-
}
112+
// AF 1.0: Serialize_WithNullOptions test removed - serialization moved to agent.
153113

154114
[Fact]
155115
public void Constructor_WithNullThread_ThrowsArgumentNullException()

dotnet/src/Agents/UnitTests/AgentExtensionsTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Moq;
77
using Xunit;
88

9+
using System.Threading.Tasks;
910
namespace SemanticKernel.Agents.UnitTests;
1011

1112
public sealed class AgentExtensionsTests
@@ -77,7 +78,7 @@ public void AsAIAgent_WithNullThreadSerializer_ThrowsArgumentNullException()
7778
}
7879

7980
[Fact]
80-
public void AsAIAgent_WithValidFactories_CreatesWorkingAdapter()
81+
public async Task AsAIAgent_WithValidFactories_CreatesWorkingAdapter()
8182
{
8283
// Arrange
8384
var agentMock = new Mock<Agent>();
@@ -95,7 +96,7 @@ AgentThread ThreadFactory()
9596

9697
// Act
9798
var result = agentMock.Object.AsAIAgent(ThreadFactory, ThreadDeserializationFactory, ThreadSerializer);
98-
var thread = result.CreateSessionAsync().GetAwaiter().GetResult();
99+
var thread = await result.CreateSessionAsync();
99100

100101
// Assert
101102
Assert.NotNull(thread);
@@ -105,7 +106,7 @@ AgentThread ThreadFactory()
105106
}
106107

107108
[Fact]
108-
public void AsAIAgent_WithDeserializationFactory_CreatesWorkingAdapter()
109+
public async Task AsAIAgent_WithDeserializationFactory_CreatesWorkingAdapter()
109110
{
110111
// Arrange
111112
var agentMock = new Mock<Agent>();
@@ -125,7 +126,7 @@ AgentThread ThreadDeserializationFactory(JsonElement e, JsonSerializerOptions? o
125126
// Act
126127
var result = agentMock.Object.AsAIAgent(ThreadFactory, ThreadDeserializationFactory, ThreadSerializer);
127128
var json = JsonElement.Parse("{}");
128-
var thread = result.DeserializeSessionAsync(json).GetAwaiter().GetResult();
129+
var thread = await result.DeserializeSessionAsync(json);
129130

130131
// Assert
131132
Assert.NotNull(thread);

0 commit comments

Comments
 (0)