a2a-protocol-client
HTTP client for the A2A protocol v1.0 -- async, hyper-backed, with pluggable transports.
Overview
- An async client for A2A v1.0 agents over all four bindings (v0.3-only agents are not reached; see below)
- Built on hyper 1.x with tokio
- Pluggable transport bindings: JSON-RPC 2.0 (default), REST, WebSocket, gRPC
- Interceptor chain for auth, logging, custom middleware
- Automatic retry with jittered exponential backoff
- SSE streaming for real-time events
Quick Start
Every Rust block in this README is compiled as a doctest of the crate; the ones that need a live agent are compiled but not run.
use ClientBuilder;
use ;
#
# async
Key Types
| Type | Purpose |
|---|---|
A2aClient |
Main entry point -- all A2A methods |
ClientBuilder |
Fluent builder for client construction |
EventStream |
Async iterator over streaming events |
RetryPolicy |
Configurable jittered exponential backoff |
CallInterceptor |
Trait for request/response middleware |
AuthInterceptor |
Built-in auth header injection from a CredentialsStore |
BearerAuthInterceptor |
Bearer tokens from a TokenProvider (static, or OAuth2 client credentials) |
ClientError |
The error type; #[non_exhaustive], so matches need a wildcard arm |
A2A Methods
All 11 A2A v1.0 methods are methods of A2aClient:
send_message()/stream_message()-- send, and stream the responsesget_task()/list_tasks()/cancel_task()-- task managementsubscribe_to_task()/subscribe_to_task_from()-- real-time task updates, the second resuming after a known eventset_push_config()/get_push_config()/list_push_configs()/delete_push_config()-- push notificationsget_extended_agent_card()-- the authenticated extended agent card
Features
| Feature | Default | Purpose |
|---|---|---|
tls-rustls |
Yes | HTTPS via rustls (no OpenSSL) |
signing |
No | Forwards a2a-protocol-types/signing; the client signs and verifies nothing on its own |
tracing |
Yes | Structured logging; default-features = false compiles it out |
websocket |
No | WebSocket transport |
grpc |
No | gRPC transport via tonic (plaintext) |
grpc-tls |
No | gRPC over TLS (implies grpc; independent of tls-rustls); bundled roots or a pinned ClientTlsConfig, re-exported from transport::grpc |
testing |
No | A scripted hostile peer (testing::ScriptedPeer) that stalls, cuts off, mis-frames or refuses on each binding, for testing code that calls agents |
Agent Discovery
use ;
#
# async
from_card considers only interfaces for this SDK's protocol major (an agent
that also serves v0.3 is not connected to on that endpoint), in the order of
ClientConfig::preferred_bindings (["JSONRPC"] by default);
ClientBuilder::from_card_preferring takes an order of your own.
Streaming
use ClientBuilder;
use ;
#
# async
Interceptors & Auth
use Arc;
use ;
let session = new;
let store = new;
store.set;
let client = new
.with_interceptor
.with_retry_policy
.build?;
# let _ = client;
# Ok::
Transport Selection
ClientBuilder::from_cardselects from the agent card'ssupportedInterfacesClientBuilder::with_protocol_bindingoverrides it by name:JSONRPC,HTTP+JSON(the legacyRESTis accepted) and, with thegrpcfeature,GRPC; names compare ignoring ASCII case- WebSocket (feature
websocket) is not chosen by name: connect atransport::WebSocketTransportand pass it toClientBuilder::with_custom_transport, which takes anyTransport - JSON-RPC 2.0 is the default when nothing else is chosen
License
Apache-2.0