Skip to content

Commit 11cdd33

Browse files
.Net: Update A2A agent to use the latest A2A .NET SDK (#12877)
This PR updates the SK A2A agent to the latest A2A .NET SDK.
1 parent d56574f commit 11cdd33

17 files changed

+68
-73
lines changed

dotnet/Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
<PackageVersion Include="System.Text.Json" Version="8.0.6" />
9393
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
9494
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
95-
<PackageVersion Include="SharpA2A.Core" Version="0.2.1-preview.1" />
96-
<PackageVersion Include="SharpA2A.AspNetCore" Version="0.2.1-preview.1" />
95+
<PackageVersion Include="A2A" Version="0.1.0-preview.2" />
96+
<PackageVersion Include="A2A.AspNetCore" Version="0.1.0-preview.2" />
9797
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
9898
<!-- Tokenizers -->
9999
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="1.0.2" />

dotnet/samples/Demos/A2AClientServer/A2AClient/A2AClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="SharpA2A.Core" />
13+
<PackageReference Include="A2A" />
1414
<PackageReference Include="System.CommandLine" />
1515
<PackageReference Include="Microsoft.Extensions.Hosting" />
1616
</ItemGroup>

dotnet/samples/Demos/A2AClientServer/A2AClient/HostClientAgent.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.SemanticKernel;
55
using Microsoft.SemanticKernel.Agents;
66
using Microsoft.SemanticKernel.Agents.A2A;
7-
using SharpA2A.Core;
87

98
namespace A2A;
109

@@ -61,14 +60,14 @@ internal async Task InitializeAgentAsync(string modelId, string apiKey, string[]
6160

6261
private async Task<A2AAgent> CreateAgentAsync(string agentUri)
6362
{
63+
var url = new Uri(agentUri);
6464
var httpClient = new HttpClient
6565
{
66-
BaseAddress = new Uri(agentUri),
6766
Timeout = TimeSpan.FromSeconds(60)
6867
};
6968

70-
var client = new A2AClient(httpClient);
71-
var cardResolver = new A2ACardResolver(httpClient);
69+
var client = new A2AClient(url, httpClient);
70+
var cardResolver = new A2ACardResolver(url, httpClient);
7271
var agentCard = await cardResolver.GetAgentCardAsync();
7372

7473
return new A2AAgent(client, agentCard!);

dotnet/samples/Demos/A2AClientServer/A2AServer/A2AServer.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="SharpA2A.Core" />
14-
<PackageReference Include="SharpA2A.AspNetCore" />
13+
<PackageReference Include="A2A.AspNetCore" />
1514
</ItemGroup>
1615

1716
<ItemGroup>

dotnet/samples/Demos/A2AClientServer/A2AServer/HostAgentFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
using A2A;
34
using Azure.AI.Agents.Persistent;
45
using Azure.Identity;
56
using Microsoft.SemanticKernel;
67
using Microsoft.SemanticKernel.Agents;
78
using Microsoft.SemanticKernel.Agents.A2A;
89
using Microsoft.SemanticKernel.Agents.AzureAI;
9-
using SharpA2A.Core;
1010

1111
namespace A2AServer;
1212

dotnet/samples/Demos/A2AClientServer/A2AServer/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
using A2A;
3+
using A2A.AspNetCore;
34
using A2AServer;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.SemanticKernel;
89
using Microsoft.SemanticKernel.Agents.A2A;
9-
using SharpA2A.AspNetCore;
1010

1111
string agentId = string.Empty;
1212
string agentType = string.Empty;
@@ -96,6 +96,6 @@ You specialize in handling queries related to logistics.
9696
throw new ArgumentException("Either A2AServer:ApiKey or A2AServer:ConnectionString & agentId must be provided");
9797
}
9898

99-
app.MapA2A(hostAgent!.TaskManager!, "");
99+
app.MapA2A(hostAgent!.TaskManager!, "/");
100100

101101
await app.RunAsync();

dotnet/samples/GettingStartedWithAgents/A2A/Step01_A2AAgent.cs

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

33
using System.Text.Json;
4+
using A2A;
45
using Microsoft.SemanticKernel;
56
using Microsoft.SemanticKernel.Agents;
67
using Microsoft.SemanticKernel.Agents.A2A;
7-
using SharpA2A.Core;
88

99
namespace GettingStarted.A2A;
1010

@@ -18,9 +18,10 @@ public class Step01_A2AAgent(ITestOutputHelper output) : BaseAgentsTest(output)
1818
public async Task UseA2AAgent()
1919
{
2020
// Create an A2A agent instance
21+
var url = TestConfiguration.A2A.AgentUrl;
2122
using var httpClient = CreateHttpClient();
22-
var client = new A2AClient(httpClient);
23-
var cardResolver = new A2ACardResolver(httpClient);
23+
var client = new A2AClient(url, httpClient);
24+
var cardResolver = new A2ACardResolver(url, httpClient);
2425
var agentCard = await cardResolver.GetAgentCardAsync();
2526
Console.WriteLine(JsonSerializer.Serialize(agentCard, s_jsonSerializerOptions));
2627
var agent = new A2AAgent(client, agentCard);
@@ -36,9 +37,10 @@ public async Task UseA2AAgent()
3637
public async Task UseA2AAgentStreaming()
3738
{
3839
// Create an A2A agent instance
40+
var url = TestConfiguration.A2A.AgentUrl;
3941
using var httpClient = CreateHttpClient();
40-
var client = new A2AClient(httpClient);
41-
var cardResolver = new A2ACardResolver(httpClient);
42+
var client = new A2AClient(url, httpClient);
43+
var cardResolver = new A2ACardResolver(url, httpClient);
4244
var agentCard = await cardResolver.GetAgentCardAsync();
4345
Console.WriteLine(JsonSerializer.Serialize(agentCard, s_jsonSerializerOptions));
4446
var agent = new A2AAgent(client, agentCard);
@@ -56,16 +58,10 @@ private HttpClient CreateHttpClient()
5658
if (this.EnableLogging)
5759
{
5860
var handler = new LoggingHandler(new HttpClientHandler(), this.Output);
59-
return new HttpClient(handler)
60-
{
61-
BaseAddress = TestConfiguration.A2A.AgentUrl
62-
};
61+
return new HttpClient(handler);
6362
}
6463

65-
return new HttpClient()
66-
{
67-
BaseAddress = TestConfiguration.A2A.AgentUrl
68-
};
64+
return new HttpClient();
6965
}
7066

7167
private static readonly JsonSerializerOptions s_jsonSerializerOptions = new() { WriteIndented = true };

dotnet/samples/GettingStartedWithAgents/GettingStartedWithAgents.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
<PackageReference Include="Azure.AI.Projects" />
1919
<PackageReference Include="Azure.Identity" />
2020
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" />
21-
<PackageReference Include="Microsoft.Extensions.Configuration" VersionOverride="9.0.1" />
22-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.1" />
21+
<PackageReference Include="Microsoft.Extensions.Configuration" VersionOverride="9.0.7" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.7" />
2323
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
24-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" VersionOverride="9.0.1" />
25-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" VersionOverride="9.0.1" />
26-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" VersionOverride="9.0.5" />
27-
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.1" />
24+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" VersionOverride="9.0.7" />
25+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" VersionOverride="9.0.7" />
26+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" VersionOverride="9.0.7" />
27+
<PackageReference Include="Microsoft.Extensions.Http" VersionOverride="9.0.7" />
2828
<PackageReference Include="Microsoft.Extensions.Http.Resilience" VersionOverride="9.1.0" />
29-
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="9.0.5" />
29+
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="9.0.7" />
3030
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
3131
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
3232
<PackageReference Include="OpenTelemetry.Exporter.Console" />

dotnet/src/Agents/A2A/A2AAgent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System.Runtime.CompilerServices;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using A2A;
910
using Microsoft.SemanticKernel.ChatCompletion;
10-
using SharpA2A.Core;
1111

1212
namespace Microsoft.SemanticKernel.Agents.A2A;
1313

@@ -175,7 +175,7 @@ private async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> InvokeAgen
175175
}
176176
};
177177

178-
A2AResponse response = await this.Client.SendMessageAsync(messageSendParams).ConfigureAwait(false);
178+
A2AResponse response = await this.Client.SendMessageAsync(messageSendParams, cancellationToken).ConfigureAwait(false);
179179
if (response is AgentTask agentTask)
180180
{
181181
if (agentTask.Artifacts != null && agentTask.Artifacts.Count > 0)

dotnet/src/Agents/A2A/A2AAgentThread.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using SharpA2A.Core;
6+
using A2A;
77

88
namespace Microsoft.SemanticKernel.Agents.A2A;
99

0 commit comments

Comments
 (0)