Skip to content

Commit 6b57b5f

Browse files
SergeyMenshykhsemenshiCopilot
authored
.NET: Upgrade A2A packages to 1.0.0-preview3 (#9386)
* .NET: Upgrade A2A packages to 1.0.0-preview3 Update A2A hosting API calls, remove obsolete artifact metadata and agent card workarounds, and verify HTTP endpoint mappings. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 964b2dd8-a132-4fd9-95c0-93210fbf9d5e * .NET: Simplify A2A endpoint builder type names Co-authored-by: Copilot App <[email protected]> Copilot-Session: 964b2dd8-a132-4fd9-95c0-93210fbf9d5e --------- Co-authored-by: SergeyMenshykh <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: 964b2dd8-a132-4fd9-95c0-93210fbf9d5e
1 parent 95feea6 commit 6b57b5f

5 files changed

Lines changed: 34 additions & 80 deletions

File tree

‎dotnet/Directory.Packages.props‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120
<PackageVersion Include="Microsoft.Agents.Authentication.Msal" Version="1.9.35-beta" />
121121
<PackageVersion Include="Microsoft.Agents.Hosting.AspNetCore" Version="1.9.35-beta" />
122122
<!-- A2A -->
123-
<PackageVersion Include="A2A" Version="1.0.0-preview2" />
124-
<PackageVersion Include="A2A.AspNetCore" Version="1.0.0-preview2" />
123+
<PackageVersion Include="A2A" Version="1.0.0-preview3" />
124+
<PackageVersion Include="A2A.AspNetCore" Version="1.0.0-preview3" />
125125
<!-- MCP -->
126126
<PackageVersion Include="ModelContextProtocol" Version="2.2.0" />
127127
<PackageVersion Include="ModelContextProtocol.Extensions.Tasks" Version="2.2.0" />

‎dotnet/src/Microsoft.Agents.AI.Hosting.A2A.AspNetCore/A2AEndpointRouteBuilderExtensions.cs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ public static IEndpointConventionBuilder MapA2AHttpJson(this IEndpointRouteBuild
8888
$"No A2AServer is registered for agent '{agentName}'. " +
8989
$"Call services.AddA2AServer(\"{agentName}\") or agentBuilder.AddA2AServer() during service registration to register one.");
9090

91-
// TODO: The stub AgentCard is temporary and will be removed once the A2A SDK either removes the
92-
// agentCard parameter of MapHttpA2A or makes it optional. MapHttpA2A exposes the agent card via a
93-
// GET {path}/card endpoint that is not part of the A2A spec, so it is not expected to be consumed
94-
// by any agent - returning a stub agent card here is safe.
95-
var stubAgentCard = new AgentCard { Name = "A2A Agent" };
96-
97-
IEndpointConventionBuilder endpoint = endpoints.MapHttpA2A(a2aServer, stubAgentCard, path);
91+
IEndpointConventionBuilder endpoint = endpoints.MapHttpA2A(a2aServer, path);
9892
MarkFeatureUsed();
9993
return endpoint;
10094
}

‎dotnet/src/Microsoft.Agents.AI.Hosting.A2A/A2AAgentHandler.cs‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Task ExecuteAsync(RequestContext context, AgentEventQueue eventQueue, Can
7070
public async Task CancelAsync(RequestContext context, AgentEventQueue eventQueue, CancellationToken cancellationToken)
7171
{
7272
var taskUpdater = new TaskUpdater(eventQueue, context.TaskId, context.ContextId);
73-
await taskUpdater.CancelAsync(cancellationToken).ConfigureAwait(false);
73+
await taskUpdater.CancelAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
7474
}
7575

7676
/// <summary>
@@ -154,7 +154,7 @@ private async Task HandleNewMessageAsync(RequestContext context, AgentEventQueue
154154
{
155155
// The server is configured through AgentRunMode to return a task, but the non-streaming client request has
156156
// ReturnImmediately disabled, so collect all updates and return a completed task.
157-
await AggregateTaskUpdatesAsync(updates, taskUpdater, eventQueue, cancellationToken).ConfigureAwait(false);
157+
await AggregateTaskUpdatesAsync(updates, taskUpdater, cancellationToken).ConfigureAwait(false);
158158
}
159159
else
160160
{
@@ -209,7 +209,7 @@ private async Task HandleTaskUpdateAsync(RequestContext context, AgentEventQueue
209209
{
210210
executionFailed = true;
211211
var failUpdater = new TaskUpdater(eventQueue, context.TaskId, contextId);
212-
await failUpdater.FailAsync(message: null, CancellationToken.None).ConfigureAwait(false);
212+
await failUpdater.FailAsync(message: null, cancellationToken: CancellationToken.None).ConfigureAwait(false);
213213
throw;
214214
}
215215
finally
@@ -222,7 +222,7 @@ private async Task HandleTaskUpdateAsync(RequestContext context, AgentEventQueue
222222
// Complete the task with an artifact containing the response.
223223
var taskUpdater = new TaskUpdater(eventQueue, context.TaskId, contextId);
224224
await taskUpdater.AddArtifactAsync(response.Messages.ToParts(), cancellationToken: cancellationToken).ConfigureAwait(false);
225-
await taskUpdater.CompleteAsync(message: null, cancellationToken).ConfigureAwait(false);
225+
await taskUpdater.CompleteAsync(message: null, cancellationToken: cancellationToken).ConfigureAwait(false);
226226
}
227227
else
228228
{
@@ -233,7 +233,7 @@ private async Task HandleTaskUpdateAsync(RequestContext context, AgentEventQueue
233233
? CreateMessageFromResponse(contextId, response)
234234
: null;
235235

236-
await taskUpdater.StartWorkAsync(progressMessage, cancellationToken).ConfigureAwait(false);
236+
await taskUpdater.StartWorkAsync(progressMessage, cancellationToken: cancellationToken).ConfigureAwait(false);
237237
}
238238
}
239239

@@ -318,7 +318,7 @@ private static async Task StreamTaskUpdatesAsync(IAsyncEnumerable<AgentResponseU
318318
var artifactWriter = new ArtifactStreamWriter(updater);
319319

320320
// Emit the task in the Submitted state.
321-
await updater.SubmitAsync(cancellationToken).ConfigureAwait(false);
321+
await updater.SubmitAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
322322

323323
try
324324
{
@@ -339,14 +339,14 @@ private static async Task StreamTaskUpdatesAsync(IAsyncEnumerable<AgentResponseU
339339
{
340340
await artifactWriter.CompleteAsync(CancellationToken.None).ConfigureAwait(false);
341341

342-
await updater.CancelAsync(CancellationToken.None).ConfigureAwait(false);
342+
await updater.CancelAsync(cancellationToken: CancellationToken.None).ConfigureAwait(false);
343343
throw;
344344
}
345345
catch (Exception)
346346
{
347347
await artifactWriter.CompleteAsync(CancellationToken.None).ConfigureAwait(false);
348348

349-
await updater.FailAsync(CreateFailureMessage(updater.ContextId, updater.TaskId), CancellationToken.None).ConfigureAwait(false);
349+
await updater.FailAsync(CreateFailureMessage(updater.ContextId, updater.TaskId), cancellationToken: CancellationToken.None).ConfigureAwait(false);
350350
throw;
351351
}
352352
}
@@ -363,18 +363,17 @@ private static async Task StreamTaskUpdatesAsync(IAsyncEnumerable<AgentResponseU
363363
/// If emitting the result fails after the task has been submitted, the task is transitioned to
364364
/// <c>Canceled</c>/<c>Failed</c> so it is never left in a non-terminal state.
365365
/// </remarks>
366-
private static async Task AggregateTaskUpdatesAsync(IAsyncEnumerable<AgentResponseUpdate> updates, TaskUpdater updater, AgentEventQueue eventQueue, CancellationToken cancellationToken)
366+
private static async Task AggregateTaskUpdatesAsync(IAsyncEnumerable<AgentResponseUpdate> updates, TaskUpdater updater, CancellationToken cancellationToken)
367367
{
368368
AgentResponse response = await updates.ToAgentResponseAsync(cancellationToken).ConfigureAwait(false);
369369

370-
await updater.SubmitAsync(cancellationToken).ConfigureAwait(false);
370+
await updater.SubmitAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
371371

372372
try
373373
{
374374
if (response.Messages.ToParts() is { Count: > 0 } parts)
375375
{
376-
await eventQueue.AddArtifactAsync(
377-
updater,
376+
await updater.AddArtifactAsync(
378377
parts,
379378
metadata: response.AdditionalProperties?.ToA2AMetadata(),
380379
cancellationToken: cancellationToken).ConfigureAwait(false);
@@ -384,12 +383,12 @@ await eventQueue.AddArtifactAsync(
384383
}
385384
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
386385
{
387-
await updater.CancelAsync(CancellationToken.None).ConfigureAwait(false);
386+
await updater.CancelAsync(cancellationToken: CancellationToken.None).ConfigureAwait(false);
388387
throw;
389388
}
390389
catch (Exception)
391390
{
392-
await updater.FailAsync(CreateFailureMessage(updater.ContextId, updater.TaskId), CancellationToken.None).ConfigureAwait(false);
391+
await updater.FailAsync(CreateFailureMessage(updater.ContextId, updater.TaskId), cancellationToken: CancellationToken.None).ConfigureAwait(false);
393392
throw;
394393
}
395394
}

‎dotnet/src/Microsoft.Agents.AI.Hosting.A2A/AgentEventQueueExtensions.cs‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

‎dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/A2AEndpointRouteBuilderExtensionsTests.cs‎

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

33
using System;
4+
using System.Linq;
45
using Microsoft.Agents.AI.Hosting.A2A.UnitTests.Internal;
56
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Routing;
68
using Microsoft.Extensions.AI;
79
using Microsoft.Extensions.DependencyInjection;
810
using Moq;
@@ -57,7 +59,7 @@ private static void AssertFeatureUsed(int featureIndex)
5759
public void MapA2AHttpJson_WithAgentBuilder_NullEndpoints_ThrowsArgumentNullException()
5860
{
5961
// Arrange
60-
AspNetCore.Routing.IEndpointRouteBuilder endpoints = null!;
62+
IEndpointRouteBuilder endpoints = null!;
6163
WebApplicationBuilder builder = WebApplication.CreateBuilder();
6264
IChatClient mockChatClient = new DummyChatClient();
6365
builder.Services.AddKeyedSingleton("chat-client", mockChatClient);
@@ -93,10 +95,10 @@ public void MapA2AHttpJson_WithAgentBuilder_NullAgentBuilder_ThrowsArgumentNullE
9395
}
9496

9597
/// <summary>
96-
/// Verifies that MapA2AHttpJson with IHostedAgentBuilder correctly maps the agent with default configuration.
98+
/// Verifies that MapA2AHttpJson maps protocol endpoints without exposing a stub agent card.
9799
/// </summary>
98100
[Fact]
99-
public void MapA2AHttpJson_WithAgentBuilder_DefaultConfiguration_Succeeds()
101+
public void MapA2AHttpJson_WithAgentBuilder_MapsProtocolEndpoints()
100102
{
101103
// Arrange
102104
WebApplicationBuilder builder = WebApplication.CreateBuilder();
@@ -107,9 +109,19 @@ public void MapA2AHttpJson_WithAgentBuilder_DefaultConfiguration_Succeeds()
107109
builder.Services.AddLogging();
108110
using WebApplication app = builder.Build();
109111

110-
// Act & Assert - Should not throw
112+
// Act
111113
var result = app.MapA2AHttpJson(agentBuilder, "/a2a");
114+
RouteEndpoint[] endpoints = ((IEndpointRouteBuilder)app).DataSources
115+
.SelectMany(source => source.Endpoints)
116+
.OfType<RouteEndpoint>()
117+
.ToArray();
118+
119+
// Assert
112120
Assert.NotNull(result);
121+
Assert.Contains(endpoints, endpoint => endpoint.RoutePattern.RawText == "/a2a/message:send");
122+
Assert.Contains(endpoints, endpoint => endpoint.RoutePattern.RawText == "/a2a/message:stream");
123+
Assert.Contains(endpoints, endpoint => endpoint.RoutePattern.RawText == "/a2a/tasks/{id}");
124+
Assert.DoesNotContain(endpoints, endpoint => endpoint.RoutePattern.RawText == "/a2a/card");
113125
}
114126

115127
/// <summary>
@@ -264,7 +276,7 @@ public void AddA2AServer_WithCustomOptions_Succeeds()
264276
public void MapA2AHttpJson_WithAgentName_NullEndpoints_ThrowsArgumentNullException()
265277
{
266278
// Arrange
267-
AspNetCore.Routing.IEndpointRouteBuilder endpoints = null!;
279+
IEndpointRouteBuilder endpoints = null!;
268280

269281
// Act & Assert
270282
ArgumentNullException exception = Assert.Throws<ArgumentNullException>(() =>
@@ -280,7 +292,7 @@ public void MapA2AHttpJson_WithAgentName_NullEndpoints_ThrowsArgumentNullExcepti
280292
public void MapA2AJsonRpc_WithAgentName_NullEndpoints_ThrowsArgumentNullException()
281293
{
282294
// Arrange
283-
AspNetCore.Routing.IEndpointRouteBuilder endpoints = null!;
295+
IEndpointRouteBuilder endpoints = null!;
284296

285297
// Act & Assert
286298
ArgumentNullException exception = Assert.Throws<ArgumentNullException>(() =>

0 commit comments

Comments
 (0)