A2A Client
A Rust HTTP client for calling remote A2A (Agent-to-Agent) protocol compliant agents.
Version Compatibility
| Crate Version | A2A Protocol Version | Notes |
|---|---|---|
| 0.1.0 | 0.3.0 | Initial implementation with full protocol support |
See the A2A Protocol Releases for the specification.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.1.1"
Quick Start
Basic Usage
use A2AClient;
use ;
async
Streaming Messages
use StreamExt;
use A2AClient;
use ;
async
Custom HTTP Client (Advanced)
For advanced use cases like custom timeouts, proxies, retry logic, or auth flows, provide your own reqwest::Client:
use A2AClient;
use ;
use Duration;
async
API Reference
Client Construction
A2AClient::from_card_url(base_url)
Create a client by fetching the agent card from {base_url}/.well-known/agent-card.json:
let client = from_card_url.await?;
A2AClient::from_card_url_with_client(base_url, http_client)
Create a client with a custom reqwest::Client:
let http_client = builder
.timeout
.build?;
let client = from_card_url_with_client.await?;
A2AClient::from_card(agent_card)
Create a client directly from a pre-fetched agent card:
let agent_card = /* ... fetch or construct AgentCard ... */;
let client = from_card?;
A2AClient::from_card_with_client(agent_card, http_client)
Create a client from an agent card with a custom HTTP client:
let http_client = builder
.timeout
.build?;
let client = from_card_with_client?;
with_auth_token(token)
Add bearer token authentication (builder pattern):
let client = from_card_url
.await?
.with_auth_token;
Core Methods
Message Sending
// Non-streaming
let response = client.send_message.await?;
// Streaming (returns a Stream)
let stream = client.send_streaming_message.await?;
Task Management
// Get a specific task
let task = client.get_task.await?;
// Cancel a task
let cancelled_task = client.cancel_task.await?;
// Resubscribe to a task's event stream (for reconnection)
let stream = client.resubscribe_task.await?;
// List tasks (commonly implemented, not official A2A spec)
let tasks = client.list_tasks.await?;
Push Notification Configuration
use ;
// Set push notification config
let config = client.set_task_push_notification_config.await?;
// Get push notification config
let config = client.get_task_push_notification_config.await?;
// List all push notification configs for a task
let configs = client.list_task_push_notification_config.await?;
// Delete a push notification config
client.delete_task_push_notification_config.await?;
Extension Methods
Call custom agent extension methods:
let response: CustomResponse = client
.call_extension_method
.await?;
Agent Card Access
// Get cached agent card
let card = client.agent_card;
// Fetch a fresh agent card
let card = client.fetch_agent_card.await?;
Error Handling
The client uses A2AError for error reporting:
use ;
match client.send_message.await
Compatibility
- A2A Protocol Version: 0.3.0
- Rust Edition: 2024
- MSRV: 1.70+
Testing
# Run unit tests
# Run with output
# Run specific test
Contributing
Contributions are welcome! Please ensure:
- Code follows Rust best practices
- All tests pass
- New features include tests
- Documentation is updated
License
MIT