a2a-client
A reusable Rust library for building web-based frontends for A2A (Agent-to-Agent) Protocol agents.
Overview
a2a-client provides reusable components, utilities, and client wrappers for creating web applications that interact with A2A protocol agents. It's designed to be integrated into your own web applications, not used as a standalone application.
Features
- 🔌 Unified Client API - Single interface for HTTP and WebSocket transports
- 📡 SSE Streaming - Server-Sent Events with automatic fallback to polling
- 🎨 View Models - Ready-to-use view models for tasks and messages
- 🔄 Auto-reconnection - Resilient WebSocket connections with retry logic
- 🧩 Modular Components - Use only what you need via feature flags
- 🦀 Type-safe - Leverages Rust's type system for protocol correctness
Installation
Add to your Cargo.toml:
[]
= { = "../a2a-client" }
# For Axum integration with SSE streaming components
= { = "../a2a-client", = ["axum-components"] }
Quick Start
Basic HTTP Client
use WebA2AClient;
async
With WebSocket Support
use WebA2AClient;
async
SSE Streaming with Axum
use ;
use ;
use Arc;
async
async
Architecture
a2a-client/
├── src/
│ ├── lib.rs # Core client API
│ ├── components/ # Reusable UI components
│ │ ├── streaming.rs # SSE streaming helpers
│ │ └── task_viewer.rs # View models for tasks/messages
│ └── utils/ # Utilities
│ └── formatters.rs # Display formatting
└── examples/ # Usage examples (coming soon)
Core Components
WebA2AClient
The main client struct that wraps both HTTP and WebSocket clients:
Methods:
new_http(base_url)- HTTP-only clientnew_with_websocket(http_url, ws_url)- Client with both transportsauto_connect(base_url)- Auto-detect available transportshas_websocket()- Check if WebSocket is availablewebsocket()- Get WebSocket client reference
View Models
TaskView
Display model for task lists:
MessageView
Display model for individual messages:
Streaming Components
create_sse_stream
Creates a Server-Sent Events stream for task updates:
Features:
- Automatic WebSocket connection with retry logic
- Graceful fallback to HTTP polling
- Emits
task-update,task-status, andartifactevents - Keep-alive heartbeat
Formatters
// Format task state for display
;
// Extract text from message parts
;
// Truncate text for previews
;
Features
axum-components (default)
Enables Axum-specific components like SSE streaming support.
[]
= { = "../a2a-client", = false } # Minimal
= { = "../a2a-client" } # With Axum components
Integration with A2A Agents
This library works seamlessly with agents built using:
a2a-rs- Core protocol implementationa2a-agents- Declarative agent frameworka2a-agent-reimbursement- Example agent implementation
Development
Building
Testing
# Unit tests
# Integration tests (requires running agent)
Examples
See the examples/ directory for complete working examples:
basic_client.rs- Simple HTTP client usage (coming soon)sse_streaming.rs- SSE streaming with Axum (coming soon)websocket_client.rs- WebSocket integration (coming soon)
Roadmap
See TODO.md for planned features and improvements.
Contributing
This library is part of the a2a-rs workspace. Contributions are welcome!
License
MIT
See Also
- a2a-rs - Core A2A protocol implementation
- a2a-agents - Declarative agent framework
- A2A Protocol Specification - Protocol documentation