AgentClient
July 23, 2025 · View on GitHub
A collection of samples demonstrating how to interact with A2A (Agent-to-Agent) framework agents using the A2A .NET client library.
Overview
The AgentClient samples show how to communicate with A2A agents in different scenarios:
- Agent Discovery: Retrieving agent capabilities and metadata
- Message-based Communication: Direct, stateless messaging with immediate responses
- Task-based Communication: Creating and managing persistent agent tasks
Available Samples
1. GetAgentDetailsSample
Purpose: Demonstrates how to discover and retrieve agent capabilities using the agent card.
What it shows:
- Using
A2ACardResolverto retrieve agent metadata - Accessing agent capabilities, supported modalities, and skills
Key APIs:
A2ACardResolver.GetAgentCardAsync()AgentCardproperties and metadata
2. MessageBasedCommunicationSample
Purpose: Shows stateless, immediate communication with agents - perfect for simple chat-style interactions.
What it shows:
- Sending messages directly to agents
- Both streaming and non-streaming communication
- Immediate responses without task management
- Simple query-response patterns
Key APIs:
A2AClient.SendMessageAsync()(non-streaming)A2AClient.SendMessageStreamAsync()(streaming with Server-Sent Events)Messageclass for user messages
3. TaskBasedCommunicationSample
Purpose: Demonstrates creating and managing persistent agent tasks.
What it shows:
- Creating agent tasks
- Handling both short-lived and long-running tasks
Key APIs:
A2AClient.SendMessageAsync()(returnsAgentTask)A2AClient.GetTaskAsync()A2AClient.CancelTaskAsyncMessageclass for user messagesAgentTaskclass for agent tasks
Code Structure
samples/AgentClient/
├── Program.cs # Main entry point
├── AgentServerUtils.cs # Utility for managing agent servers
├── Samples/
│ ├── GetAgentDetailsSample.cs # Agent discovery sample
│ ├── MessageBasedCommunicationSample.cs # Direct messaging sample
│ └── TaskBasedCommunicationSample.cs # Task management sample
└── README.md # This file
Building and Running
Prerequisites
- .NET 9 SDK or later
- Visual Studio 2022 or VS Code (optional)
Command Line
# Build the project
cd samples/AgentClient
dotnet build
# Run all samples
dotnet run
Visual Studio
- Open the solution in Visual Studio
- Set
AgentClientas the startup project - Press F5 or click the green play button
VS Code
- Open the workspace in VS Code
- Open the Debug panel (Ctrl+Shift+D)
- Press F5 to start debugging
Running Individual Samples
To run individual samples, modify the Program.cs file to comment out the samples you don't want to run.