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 transport
- 📡 SSE Streaming - Server-Sent Events with automatic fallback to polling
- 🎨 View Models - Ready-to-use view models for tasks and messages
- 🧩 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
SSE Streaming with Axum
use ;
use ;
use Arc;
async
async
Architecture
flowchart TD
subgraph WebApp[Web Application / Frontend]
UI[UI / Frontend Component]
AppState[AppState]
TaskView[TaskView / MessageView]
end
subgraph Client[a2a-client Crate]
WebClient[WebA2AClient]
HTTPClient[HttpClient]
SSE[create_sse_stream]
end
subgraph Server[A2A Agent Server]
AgentCard[/agent-card Endpoint]
Tasks[/tasks Endpoint]
end
UI --> AppState
AppState --> WebClient
WebClient --> HTTPClient
HTTPClient -->|Discover Transport / Fetch Card| AgentCard
HTTPClient -->|Send messages / Poll fallback| Tasks
SSE -->|Fetch Updates| HTTPClient
SSE -->|Emit Task Events| UI
TaskView -->|Map Domain Model| AppState
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 clientauto_connect(base_url)- Auto-detect available transports
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:
- 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)
Roadmap
See the workspace TODO.md for open and deferred work.
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