Semantic Kernel Agent A2A Protocol Example
21by Jordiag
Semantic Kernel A2A protocol and A2A Discovery Service Example
Getting Started
README
Semantic Kernel A2A protocol and A2A Discovery Service Example
This repository showcases a playful yet practical conversation between two autonomous agents using the a2a‑dotnet SDK and Semantic Kernel. It demonstrates how agents can discover each other, exchange JSON‑RPC messages, and stream results back in real time — all while keeping the code simple and transparent.
✨ What makes it cool?
- Agents locate one another through a lightweight discovery service.
- Messages hop over either a local named pipe or Azure Service Bus.
- Semantic Kernel powers text transformations such as reversing or upper‑casing.
- The sample is small enough to grok in minutes yet flexible enough to extend.
Repository layout
The solution is split into several projects to keep responsibilities clear:
| Folder | Description |
|---|---|
Agent2AgentProtocol.Discovery.Service |
Minimal web API that registers agent capabilities and resolves them to endpoints. |
Semantic.Kernel.Agent2AgentProtocol.Example.Agent1 |
Console app that discovers a capability and sends a task. |
Semantic.Kernel.Agent2AgentProtocol.Example.Agent2 |
Console app that registers capabilities and processes incoming tasks. |
Semantic.Kernel.Agent2AgentProtocol.Example.Core |
Shared helpers for A2A messages, transports, and Semantic Kernel functions. |
Each project targets .NET 8 and uses the latest a2a-dotnet packages.
Prerequisites
- .NET 8.0 SDK
- Optional: An Azure Service Bus connection string if you want to see the agents communicate through the cloud rather than a named pipe.
Running the demo
Visual Studio, set all prject to run at the same time:
Command line
-
Build the solution
dotnet build -
Start the discovery service
Agents query this lightweight API to find where other agents are listening.
dotnet run --project Agent2AgentProtocol.Discovery.Service -
Start Agent 2 (the responder)
Agent 2 registers the
reverseanduppercapabilities and waits for work.dotnet run --project Semantic.Kernel.Agent2AgentProtocol.Example.Agent2 -
Start Agent 1 (the initiator)
Agent 1 asks the discovery service for an endpoint that can handle a reverse command and then sends a task message.
dotnet run --project Semantic.Kernel.Agent2AgentProtocol.Example.Agent1 -
Watch the conversation
The terminal output shows Agent 2 reversing text and streaming the response back to Agent 1. Try editing the request in
Agent1.csto sendupper:instead ofreverse:.
Switching to Azure Service Bus
Want to see the agents chat over the cloud?
- Create a Service Bus namespace and queue.
- Set the environment variable
SERVICEBUS_CONNECTIONSTRINGwith a connection string that has Send and Listen rights. - In
appsettings.jsonfor both agents, changeUseAzureServiceBustotrueor modify theTransportOptionsinAgent2to setUseAzure = true. - Run the steps above; messages now traverse Service Bus instead of a named pipe.
The transport implementation is abstracted behind IMessagingTransport, so you can substitute other mechanisms (web sockets, HTTP, etc.) with minimal changes.
Architecture overview
Agent 2 exposes skills via Semantic Kernel functions. When it receives a task that begins with reverse: or upper:, it invokes the appropriate function and replies with the result. The agents can easily be extended with additional skills by updating TextProcessingFunction.cs and registering new capabilities.
Extending the sample
- Add new text transformations by creating Semantic Kernel functions and listing them in
BuildCapabilitiesCard. - Replace the transports with your preferred messaging system by implementing
IMessagingTransport. - Integrate a real discovery mechanism or directory service for more sophisticated routing.
- Use the
TaskManagerprovided bya2a-dotnetto track long‑running jobs or to stream incremental progress.
Contributing and feedback
Pull requests and issues are welcome! This repository is intentionally lightweight; ideas for additional skills, transports, or polish are encouraged.
Resources
License
Licensed under the MIT License.