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;
use a2a_rs::services::AsyncA2AClient;
// 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());
let task = client.http.send_task_message("task-1", &message, None, None).await?;
println!("Task ID: {}", task.id);§With WebSocket Support
use a2a_client::WebA2AClient;
// Create client with both HTTP and WebSocket
let client = WebA2AClient::new_with_websocket(
"http://localhost:8080".to_string(),
"ws://localhost:8080/ws".to_string()
);
if client.has_websocket() {
println!("WebSocket support available!");
}§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 implementationa2a-agents- Declarative agent framework- Any agent implementing the A2A Protocol v0.3.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.
- WebA2A
Client - Web-friendly A2A client that wraps both HTTP and WebSocket clients.
- WebA2A
Client Builder - Builder for
WebA2AClient.