GitHub - a2aproject/a2a-dotnet: C#/.NET SDK for A2A Protocol (original) (raw)

License NuGet Version

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:

Protocol Compatibility

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_3

Installation

Core A2A Library

ASP.NET Core Extensions

dotnet add package A2A.AspNetCore

Overview

alt text

Library: A2A

This library contains the core A2A protocol implementation. It includes the following key classes:

Client Classes

Server Classes

Core Models

Library: A2A.AspNetCore

This library provides ASP.NET Core integration for hosting A2A agents. It includes the following key classes:

Extension Methods

Getting Started

1. Create an Agent Server

using A2A; using A2A.AspNetCore;

var builder = WebApplication.CreateBuilder(args); var app = builder.Build();

var store = new InMemoryTaskStore(); var taskManager = new TaskManager(store);

taskManager.OnSendMessage = async (request, ct) => { var text = request.Message.Parts.FirstOrDefault()?.Text ?? ""; return new SendMessageResponse { Message = new Message { MessageId = Guid.NewGuid().ToString("N"), Role = Role.Agent, Parts = [Part.FromText($"Echo: {text}")] } }; };

var agentCard = new AgentCard { Name = "Echo Agent", Description = "Echoes messages back to the user", Version = "1.0.0", SupportedInterfaces = [new AgentInterface { Url = "http://localhost:5000/echo", 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"] }], };

app.MapA2A(taskManager, "/echo"); app.MapWellKnownAgentCard(agentCard); app.Run();

2. Connect with A2AClient

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; }

Samples

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.

Agent Client Samples

samples/AgentClient/

Comprehensive collection of client-side samples showing how to interact with A2A agents:

Agent Server Samples

samples/AgentServer/

Server-side examples demonstrating how to build A2A-compatible agents:

Semantic Kernel Integration

samples/SemanticKernelAgent/

Advanced sample showing integration with Microsoft Semantic Kernel:

Command Line Interface

samples/A2ACli/

Command-line tool for interacting with A2A agents:

Quick Start with Client Samples

  1. Clone and build the repository:
    git clone https://github.com/a2aproject/a2a-dotnet.git
    cd a2a-dotnet
    dotnet build
  2. Run the client samples:
    cd samples/AgentClient
    dotnet run

For detailed instructions and advanced scenarios, see the individual README files linked above.

Further Reading

To learn more about the A2A protocol, explore these additional resources:

Acknowledgements

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.

License

This project is licensed under the Apache 2.0 License.