Expand description
§a2a-client
Reusable Rust library for building web-based frontends for A2A (Agent-to-Agent) Protocol agents.
§Overview
This library provides components and utilities for creating web applications that interact
with A2A protocol agents. It wraps the lower-level a2a-rs clients
with a web-friendly API and includes ready-to-use components for common use cases.
§Features
- Unified Client API - Single interface for both HTTP and WebSocket transports
- SSE Streaming - Server-Sent Events with automatic fallback to HTTP polling
- View Models - Ready-to-use view models for tasks and messages
- Auto-reconnection - Resilient WebSocket connections with retry logic
- Type-safe - Leverages Rust’s type system for protocol correctness
§Quick Start
§Basic HTTP Client
use a2a_client::WebA2AClient;
use a2a_rs::domain::{Message, SendCompletion};
use a2a_rs::Transport;
// Create a client connected to your A2A agent
let client = WebA2AClient::new_http("http://localhost:8080".to_string());
// Send a message
let message = Message::user_text("Hello, agent!".to_string(), "msg-1".to_string());
// `WhenSettled` is the A2A default: the server holds the response until the
// task finishes, so `task` carries the agent's reply rather than an ack.
let task = client
.transport
.send_task_message(None, &message, None, None, SendCompletion::WhenSettled)
.await?;
println!("Task ID: {}", task.id);§With SSE Streaming via ConnectRPC
use a2a_client::WebA2AClient;
// Create client with HTTP (which handles ConnectRPC streaming automatically)
let client = WebA2AClient::new_http("http://localhost:8080".to_string());
println!("HTTP client configured for streaming!");§SSE Streaming with Axum (requires axum-components feature)
ⓘ
use a2a_client::{WebA2AClient, components::create_sse_stream};
use axum::{Router, routing::get, extract::{State, Path}};
use std::sync::Arc;
let client = Arc::new(WebA2AClient::new_http("http://localhost:8080".to_string()));
let app = Router::new()
.route("/stream/{task_id}", get(stream_handler))
.with_state(client);
// Start your Axum server...
async fn stream_handler(
State(client): State<Arc<WebA2AClient>>,
Path(task_id): Path<String>,
) -> axum::response::sse::Sse<impl futures::Stream<Item = Result<axum::response::sse::Event, std::convert::Infallible>>> {
create_sse_stream(client, task_id)
}§Components
WebA2AClient- Main client wrapper for HTTP and WebSocket transportscomponents::TaskView- View model for displaying tasks in listscomponents::MessageView- View model for displaying individual messagescomponents::create_sse_stream- SSE stream creation with auto-fallback (requiresaxum-components)utils::formatters- Formatting utilities for A2A types
§Feature Flags
axum-components(default) - Enables Axum-specific SSE streaming components
§Integration
This library integrates with:
a2a-rs- Core A2A protocol implementationkorps- Declarative agent framework- Any agent implementing the A2A Protocol v1.0.0
§Examples
See the examples/ directory for complete working examples of different use cases.
Re-exports§
pub use error::ClientError;pub use error::Result;
Modules§
- components
- Reusable web components for A2A interfaces.
- error
- Error types for the a2a-client library.
- utils
- Utility functions for A2A web clients.
Structs§
- AppState
- Application state for Axum web applications.
- Client
Config - Re-exported so callers can configure
WebA2AClient::auto_connect_withwithout also depending ona2a-rsdirectly. Client-side connection settings applied to every transport built during negotiation, and to the agent-card fetch that precedes it. - WebA2A
Client - Web-friendly A2A client that wraps both HTTP and WebSocket clients.
- WebA2A
Client Builder - Builder for
WebA2AClient.