Skip to content

.Net: Initial check-in for the A2A Agent implementation #12050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
73d2a06
Initial check-in for the A2A Agent implementation
markwallace-microsoft May 14, 2025
1f90951
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft May 14, 2025
21c1858
Fix warning
markwallace-microsoft May 14, 2025
b8b3bf6
Add A2A Client and Server samples
markwallace-microsoft May 14, 2025
0196641
Mark assembly as experimental
markwallace-microsoft May 14, 2025
aba8ada
Fix warnings
markwallace-microsoft May 14, 2025
d1297dd
Fix warnings
markwallace-microsoft May 14, 2025
384de1d
Skip .net8.0 build for A2AClientServer
markwallace-microsoft May 14, 2025
8469ddc
Skip .net8.0 build for A2AClientServer
markwallace-microsoft May 14, 2025
192ebee
Skip .net8.0 build for A2AClientServer
markwallace-microsoft May 14, 2025
908af44
Undo changes
markwallace-microsoft May 14, 2025
f2516dd
Bump package versions and add readme
markwallace-microsoft May 14, 2025
d2ba0d8
Revert to just net8.0
markwallace-microsoft May 14, 2025
4edfb35
Merge Shawn's changes and support ChatCompletion or AzureAI agents
markwallace-microsoft May 17, 2025
7d6ce75
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft May 17, 2025
84acb02
Fix formatting
markwallace-microsoft May 17, 2025
bec3c2d
Fix formatting
markwallace-microsoft May 17, 2025
41a1d31
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft May 19, 2025
7940e93
Rename configu property
markwallace-microsoft May 19, 2025
2244207
Merge branch 'users/markwallace/a2a_agent' of https://github.com/mark…
markwallace-microsoft May 19, 2025
b2439f5
Start work on streaming support
markwallace-microsoft May 19, 2025
2ba30e3
Merge latest from main and resolve merge conflicts
markwallace-microsoft Jun 10, 2025
3898ebe
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft Jun 10, 2025
9458511
Update the .slnx file
markwallace-microsoft Jun 10, 2025
47d7e69
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft Jun 11, 2025
6844e8b
Update to new client API
markwallace-microsoft Jun 11, 2025
bf32517
Upgrade to latest SharpA2A
markwallace-microsoft Jun 19, 2025
bbf19ca
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft Jun 19, 2025
a05b44d
Cleanup samples and test
markwallace-microsoft Jun 19, 2025
ea68957
Update the A2A demo README
markwallace-microsoft Jun 19, 2025
ea42d2e
Add unit tests
markwallace-microsoft Jun 20, 2025
8a4d4ff
Add unit tests
markwallace-microsoft Jun 20, 2025
513d831
Merge branch 'users/markwallace/a2a_agent' of https://github.com/mark…
markwallace-microsoft Jun 20, 2025
059e6eb
Merge branch 'main' into users/markwallace/a2a_agent
markwallace-microsoft Jun 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
<PackageVersion Include="SharpA2A.Core" Version="0.1.0-preview.4" />
<PackageVersion Include="SharpA2A.AspNetCore" Version="0.1.0-preview.4" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<!-- Tokenizers -->
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="1.0.2" />
<PackageVersion Include="Microsoft.DeepDev.TokenizerLib" Version="1.3.3" />
Expand Down
30 changes: 30 additions & 0 deletions dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Runtime.InProcess.UnitTests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectorData.UnitTests", "src\Connectors\VectorData.UnitTests\VectorData.UnitTests.csproj", "{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agents.A2A", "src\Agents\A2A\Agents.A2A.csproj", "{38F1D24F-C7B4-58CC-D104-311D786A73CF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "A2AClientServer", "A2AClientServer", "{5B1ECD1B-3C38-4458-A227-89846AF13760}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A2AClient", "samples\Demos\A2AClientServer\A2AClient\A2AClient.csproj", "{F293D014-97E2-18CB-FA0F-0A0FBE149286}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "A2AServer", "samples\Demos\A2AClientServer\A2AServer\A2AServer.csproj", "{D5324629-DFED-4095-EA74-A0234AC9EB4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1511,6 +1519,24 @@ Global
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}.Publish|Any CPU.Build.0 = Debug|Any CPU
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84}.Release|Any CPU.Build.0 = Release|Any CPU
{38F1D24F-C7B4-58CC-D104-311D786A73CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38F1D24F-C7B4-58CC-D104-311D786A73CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38F1D24F-C7B4-58CC-D104-311D786A73CF}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
{38F1D24F-C7B4-58CC-D104-311D786A73CF}.Publish|Any CPU.Build.0 = Publish|Any CPU
{38F1D24F-C7B4-58CC-D104-311D786A73CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38F1D24F-C7B4-58CC-D104-311D786A73CF}.Release|Any CPU.Build.0 = Release|Any CPU
{F293D014-97E2-18CB-FA0F-0A0FBE149286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F293D014-97E2-18CB-FA0F-0A0FBE149286}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F293D014-97E2-18CB-FA0F-0A0FBE149286}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{F293D014-97E2-18CB-FA0F-0A0FBE149286}.Publish|Any CPU.Build.0 = Release|Any CPU
{F293D014-97E2-18CB-FA0F-0A0FBE149286}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F293D014-97E2-18CB-FA0F-0A0FBE149286}.Release|Any CPU.Build.0 = Release|Any CPU
{D5324629-DFED-4095-EA74-A0234AC9EB4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5324629-DFED-4095-EA74-A0234AC9EB4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5324629-DFED-4095-EA74-A0234AC9EB4E}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{D5324629-DFED-4095-EA74-A0234AC9EB4E}.Publish|Any CPU.Build.0 = Release|Any CPU
{D5324629-DFED-4095-EA74-A0234AC9EB4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5324629-DFED-4095-EA74-A0234AC9EB4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1716,6 +1742,10 @@ Global
{CCC909E4-5269-A31E-0BFD-4863B4B29BBB} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{DA6B4ED4-ED0B-D25C-889C-9F940E714891} = {A70ED5A7-F8E1-4A57-9455-3C05989542DA}
{AAC7B5E8-CC4E-49D0-AF6A-2B4F7B43BD84} = {5A7028A7-4DDF-4E4F-84A9-37CE8F8D7E89}
{38F1D24F-C7B4-58CC-D104-311D786A73CF} = {6823CD5E-2ABE-41EB-B865-F86EC13F0CF9}
{5B1ECD1B-3C38-4458-A227-89846AF13760} = {5D4C0700-BBB5-418F-A7B2-F392B9A18263}
{F293D014-97E2-18CB-FA0F-0A0FBE149286} = {5B1ECD1B-3C38-4458-A227-89846AF13760}
{D5324629-DFED-4095-EA74-A0234AC9EB4E} = {5B1ECD1B-3C38-4458-A227-89846AF13760}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FBDC56A3-86AD-4323-AA0F-201E59123B83}
Expand Down
25 changes: 25 additions & 0 deletions dotnet/samples/Demos/A2AClientServer/A2AClient/A2AClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
<NoWarn>$(NoWarn);CS1591;VSTHRD111;CA2007;SKEXP0110</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpA2A.Core" />
<PackageReference Include="SharpA2A.AspNetCore" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the asp.net package in the client? I would have expected it's only required for the server?

<PackageReference Include="System.CommandLine" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Agents\A2A\Agents.A2A.csproj" />
<ProjectReference Include="..\..\..\..\src\Agents\Core\Agents.Core.csproj" />
<ProjectReference Include="..\..\..\..\src\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.A2A;
using SharpA2A.Core;

namespace A2A;

internal sealed class HostClientAgent
{
internal HostClientAgent(ILogger logger)
{
this._logger = logger;
}
internal async Task InitializeAgentAsync(string modelId, string apiKey, string baseAddress)
{
try
{
this._logger.LogInformation("Initializing Semantic Kernel agent with model: {ModelId}", modelId);

// Connect to the remote agents via A2A
var agentPlugin = KernelPluginFactory.CreateFromFunctions("AgentPlugin",
[
AgentKernelFunctionFactory.CreateFromAgent(await this.CreateAgentAsync($"{baseAddress}/currency/")),
AgentKernelFunctionFactory.CreateFromAgent(await this.CreateAgentAsync($"{baseAddress}/invoice/"))
]);

// Define the TravelPlannerAgent
var builder = Kernel.CreateBuilder();
builder.AddOpenAIChatCompletion(modelId, apiKey);
builder.Plugins.Add(agentPlugin);
var kernel = builder.Build();

this.Agent = new ChatCompletionAgent()
{
Kernel = kernel,
Name = "HostClient",
Instructions =
"""
You specialize in handling queries for users and using your tools to provide answers.
""",
Arguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
};
}
catch (Exception ex)
{
this._logger.LogError(ex, "Failed to initialize HostClientAgent");
throw;
}
}

/// <summary>
/// The associated <see cref="Agent"/>
/// </summary>
public Agent? Agent { get; private set; }

#region private
private readonly ILogger _logger;

private async Task<A2AAgent> CreateAgentAsync(string agentUri)
{
var httpClient = new HttpClient
{
BaseAddress = new Uri(agentUri)
};

var client = new A2AClient(httpClient);
var cardResolver = new A2ACardResolver(httpClient);
var agentCard = await cardResolver.GetAgentCardAsync();

return new A2AAgent(client, agentCard);
}
#endregion
}
99 changes: 99 additions & 0 deletions dotnet/samples/Demos/A2AClientServer/A2AClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright (c) Microsoft. All rights reserved.

using System.CommandLine;
using System.CommandLine.Invocation;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;

namespace A2A;

public static class Program
{
public static async Task<int> Main(string[] args)
{
// Create root command with options
var rootCommand = new RootCommand("A2AClient")
{
s_agentOption,
};

// Replace the problematic line with the following:
rootCommand.SetHandler(RunCliAsync);

// Run the command
return await rootCommand.InvokeAsync(args);
}

public static async System.Threading.Tasks.Task RunCliAsync(InvocationContext context)
{
string agent = context.ParseResult.GetValueForOption<string>(s_agentOption)!;

await RunCliAsync(agent);
}

#region private
private static readonly Option<string> s_agentOption = new(
"--agent",
getDefaultValue: () => "http://localhost:10000",
description: "Agent URL");

private static async System.Threading.Tasks.Task RunCliAsync(string agentUrl)
{
// Set up the logging
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Information);
});
var logger = loggerFactory.CreateLogger("A2AClient");

// Retrieve configuration settings
IConfigurationRoot configRoot = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddUserSecrets(Assembly.GetExecutingAssembly())
.Build();
string apiKey = configRoot["OPENAI_API_KEY"] ?? throw new ArgumentException("OPENAI_API_KEY must be provided");
string modelId = configRoot["OPENAI_CHAT_MODEL_ID"] ?? "gpt-4.1";
string baseAddress = configRoot["AGENT_URL"] ?? "http://localhost:5000";

// Create the Host agent
var hostAgent = new HostClientAgent(logger);
await hostAgent.InitializeAgentAsync(modelId, apiKey, baseAddress);

try
{
while (true)
{
// Get user message
Console.Write("\nUser (:q or quit to exit): ");
string? message = Console.ReadLine();
if (string.IsNullOrWhiteSpace(message))
{
Console.WriteLine("Request cannot be empty.");
continue;
}

if (message == ":q" || message == "quit")
{
break;
}

Console.ForegroundColor = ConsoleColor.Cyan;
await foreach (AgentResponseItem<ChatMessageContent> response in hostAgent.Agent!.InvokeAsync(message))
{
Console.WriteLine($"Agent: {response.Message.Content}");
}
Console.ResetColor();
}
}
catch (Exception ex)
{
logger.LogError(ex, "An error occurred while running the A2AClient");
return;
}
}
#endregion
}
23 changes: 23 additions & 0 deletions dotnet/samples/Demos/A2AClientServer/A2AServer/A2AServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
<NoWarn>$(NoWarn);CS1591;VSTHRD111;CA2007;SKEXP0110</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpA2A.Core" />
<PackageReference Include="SharpA2A.AspNetCore" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\Agents\A2A\Agents.A2A.csproj" />
<ProjectReference Include="..\..\..\..\src\Agents\Core\Agents.Core.csproj" />
<ProjectReference Include="..\..\..\..\src\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions dotnet/samples/Demos/A2AClientServer/A2AServer/A2AServer.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@host = http://localhost:5000

### Query agent card for the invoice agent
GET {{host}}/invoice/.well-known/agent.json

### Send a task to the invoice agent
POST {{host}}/invoice
Content-Type: application/json

{
"id": "1",
"jsonrpc": "2.0",
"method": "task/send",
"params": {
"id": "12345",
"message": {
"role": "user",
"parts": [
{
"type": "text",
"text": "Show me all invoices for Contoso?"
}
]
}
}
}

### Query agent card for the currency agent
GET {{host}}/currency/.well-known/agent.json

### Send a task to the currency agent
POST {{host}}/currency
Content-Type: application/json

{
"id": "1",
"jsonrpc": "2.0",
"method": "task/send",
"params": {
"id": "12345",
"message": {
"role": "user",
"parts": [
{
"type": "text",
"text": "What is the current exchange rather for Dollars to Euro?"
}
]
}
}
}
Loading
Loading