A .NET library that helps run agentic applications as A2AServers following the Agent2Agent (A2A) Protocol.
The A2A .NET SDK provides a robust implementation of the Agent2Agent (A2A) protocol, enabling seamless communication between AI agents and applications. This library offers both high-level abstractions and fine-grained control, making it easy to build A2A-compatible agents while maintaining flexibility for advanced use cases.
Key features include:
- Agent Capability Discovery: Retrieve agent capabilities and metadata through agent cards
- Message-based Communication: Direct, stateless messaging with immediate responses
- Task-based Communication: Create and manage persistent, long-running agent tasks
- Streaming Support: Real-time communication using Server-Sent Events
- ASP.NET Core Integration: Built-in extensions for hosting A2A agents in web applications
- Cross-platform Compatibility: Supports .NET 8+
This library implements the A2A v1.0 specification. It provides full support for the JSON-RPC binding and HTTP+JSON REST binding, including streaming via Server-Sent Events.
If you're upgrading from the v0.3 SDK, see the Migration Guide for a comprehensive list of breaking changes and before/after code examples. A backward-compatible A2A.V0_3 NuGet package is available during the transition:
dotnet add package A2A.V0_3dotnet add package A2Adotnet add package A2A.AspNetCoreThis library contains the core A2A protocol implementation. It includes the following key classes:
A2AClient: Primary client for making A2A requests to agents. Supports both streaming and non-streaming communication, task management, and push notifications.A2ACardResolver: Resolves agent card information from A2A-compatible endpoints to discover agent capabilities and metadata.
A2AServer: Core server that handles A2A JSON-RPC requests, manages task lifecycle viaTaskProjection, and coordinates streaming/non-streaming responses. ImplementsIA2ARequestHandler.IAgentHandler: Interface that agents implement. ProvidesExecuteAsync()for message handling andCancelAsync()for task cancellation.TaskUpdater: Convenience API for emitting task lifecycle events (Submit, StartWork, AddArtifact, Complete, Fail, Cancel, RequireInput).MessageResponder: Convenience API for stateless message replies without task lifecycle.RequestContext: Pre-resolved context provided to agents, containing the incoming message, task ID, context ID, and helper properties likeUserTextandIsContinuation.AgentEventQueue: Channel-backed queue that agents write events to. The SDK reads from it to build responses.ITaskStore: Interface for task persistence with simple CRUD methods (Get, Save, Delete, List).InMemoryTaskStore: In-memory implementation ofITaskStoresuitable for development and testing.
AgentTask: Represents a task with its status, history, artifacts, and metadata.AgentCard: Contains agent metadata, capabilities, and endpoint information.Message: Represents messages exchanged between agents and clients.
This library provides ASP.NET Core integration for hosting A2A agents. It includes the following key classes:
A2AServiceCollectionExtensions: ProvidesAddA2AAgent<THandler>()for registering an agent, its card, and all A2A services with dependency injection.A2ARouteBuilderExtensions: ProvidesMapA2A()for JSON-RPC endpoints,MapHttpA2A()for HTTP REST endpoints, andMapWellKnownAgentCard()for agent card discovery.
using A2A;
using A2A.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Register the echo agent with DI — this sets up A2AServer, ITaskStore, and all middleware
builder.Services.AddA2AAgent<EchoAgent>(EchoAgent.GetAgentCard("http://localhost:5000/echo"));
var app = builder.Build();
// Map JSON-RPC endpoint for A2A communication
app.MapA2A("/echo");
// Map well-known agent card for discovery
var card = app.Services.GetRequiredService<AgentCard>();
app.MapWellKnownAgentCard(card);
app.Run();
// Define the agent — implement IAgentHandler
public sealed class EchoAgent : IAgentHandler
{
public async Task ExecuteAsync(
RequestContext context,
AgentEventQueue eventQueue,
CancellationToken cancellationToken)
{
var responder = new MessageResponder(eventQueue, context.ContextId);
await responder.ReplyAsync($"Echo: {context.UserText}", cancellationToken);
}
public static AgentCard GetAgentCard(string url) => new()
{
Name = "Echo Agent",
Description = "Echoes messages back to the user",
Version = "1.0.0",
SupportedInterfaces = [new AgentInterface
{
Url = url,
ProtocolBinding = "JSONRPC",
ProtocolVersion = "1.0"
}],
DefaultInputModes = ["text/plain"],
DefaultOutputModes = ["text/plain"],
Capabilities = new AgentCapabilities { Streaming = false },
Skills = [new AgentSkill
{
Id = "echo",
Name = "Echo",
Description = "Echoes back user messages",
Tags = ["echo"]
}],
};
}using A2A;
// Discover agent
var cardResolver = new A2ACardResolver(new Uri("http://localhost:5000/"));
var agentCard = await cardResolver.GetAgentCardAsync();
// Create client using agent's endpoint
var client = new A2AClient(new Uri(agentCard.SupportedInterfaces[0].Url));
// Send message
var response = await client.SendMessageAsync(new SendMessageRequest
{
Message = new Message
{
MessageId = Guid.NewGuid().ToString("N"),
Role = Role.User,
Parts = [Part.FromText("Hello!")]
}
});
// Handle response
switch (response.PayloadCase)
{
case SendMessageResponseCase.Message:
Console.WriteLine(response.Message!.Parts[0].Text);
break;
case SendMessageResponseCase.Task:
Console.WriteLine($"Task created: {response.Task!.Id}");
break;
}The repository includes several sample projects demonstrating different aspects of the A2A protocol implementation. Each sample includes its own README with detailed setup and usage instructions.
Comprehensive collection of client-side samples showing how to interact with A2A agents:
- Agent Capability Discovery: Retrieve agent capabilities and metadata using agent cards
- Message-based Communication: Direct, stateless messaging with immediate responses
- Task-based Communication: Create and manage persistent agent tasks
- Streaming Communication: Real-time communication using Server-Sent Events
Server-side examples demonstrating how to build A2A-compatible agents:
- Echo Agent: Simple agent that echoes messages back to clients
- Echo Agent with Tasks: Task-based version of the echo agent
- Researcher Agent: More complex agent with research capabilities
- HTTP Test Suite: Complete set of HTTP tests for all agent endpoints
Advanced sample showing integration with Microsoft Semantic Kernel:
- Travel Planner Agent: AI-powered travel planning agent
- Semantic Kernel Integration: Demonstrates how to wrap Semantic Kernel functionality in A2A protocol
Command-line tool for interacting with A2A agents:
- Direct command-line access to A2A agents
- Useful for testing and automation scenarios
-
Clone and build the repository:
git clone https://github.com/a2aproject/a2a-dotnet.git cd a2a-dotnet dotnet build -
Run the client samples:
cd samples/AgentClient dotnet run
For detailed instructions and advanced scenarios, see the individual README files linked above.
To learn more about the A2A protocol, explore these additional resources:
- A2A Protocol Documentation - The official documentation for the A2A protocol.
- A2A Protocol Specification - The detailed technical specification of the protocol.
- A2A Topics - An overview of key concepts and features of the A2A protocol.
- A2A Roadmap - A look at the future development plans and upcoming features.
This library builds upon Darrel Miller's sharpa2a project. Thanks to Darrel and all the other contributors for the foundational work that helped shape this SDK.
This project is licensed under the Apache 2.0 License.
