pub struct WebA2AClient {
pub transport: Arc<dyn Transport>,
}Expand description
Web-friendly A2A client that wraps both HTTP and WebSocket clients.
This is the main entry point for interacting with A2A agents from web applications. It provides a unified interface for both HTTP and WebSocket transports, with automatic fallback and retry logic.
§Examples
§HTTP-only client
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_http("http://localhost:8080".to_string());§Client configured for streaming
use a2a_client::WebA2AClient;
let client = WebA2AClient::new_http("http://localhost:8080".to_string());§Auto-detecting transports
use a2a_client::WebA2AClient;
let client = WebA2AClient::auto_connect("http://localhost:8080").await?;Fields§
§transport: Arc<dyn Transport>The negotiated transport for A2A requests and streaming.
Held behind an Arc<dyn Transport> so the client is agnostic to the
underlying wire protocol (ConnectRPC, JSON-RPC 2.0, …) and can share the
transport with a reconnecting subscription stream.
Implementations§
Source§impl WebA2AClient
impl WebA2AClient
Sourcepub fn builder() -> WebA2AClientBuilder
pub fn builder() -> WebA2AClientBuilder
Create a builder for configuring the client.
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::builder()
.http_url("http://localhost:8080")
.build();Sourcepub async fn auto_connect(base_url: &str) -> Result<Self>
pub async fn auto_connect(base_url: &str) -> Result<Self>
Auto-connect to an agent by fetching its card and negotiating a transport.
Fetches the agent card from the well-known endpoint and selects a transport
from the card’s supported_interfaces (ConnectRPC preferred, JSON-RPC 2.0
as interop fallback). If the card can’t be fetched or none of its interfaces
match a compiled-in transport, falls back to a ConnectRPC client on
base_url so the call still works against a bare agent URL.
§Arguments
base_url- Base URL of the A2A agent
§Examples
use a2a_client::WebA2AClient;
let client = WebA2AClient::auto_connect("http://localhost:8080").await?;Sourcepub async fn auto_connect_with(
base_url: &str,
config: &ClientConfig,
) -> Result<Self>
pub async fn auto_connect_with( base_url: &str, config: &ClientConfig, ) -> Result<Self>
As auto_connect, with credentials and a request
timeout.
The card-driven path is the one that needs this most: negotiation has to fetch the agent card before it can pick a transport, and an agent that authenticates its RPC endpoints usually authenticates its card too.
§Examples
use a2a_client::{ClientConfig, WebA2AClient};
let client = WebA2AClient::auto_connect_with(
"http://localhost:8080",
&ClientConfig::new().with_auth_token("token"),
)
.await?;Sourcepub async fn subscribe(
&self,
task_id: &str,
) -> Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, A2AError>> + Send>>>
pub async fn subscribe( &self, task_id: &str, ) -> Result<Pin<Box<dyn Stream<Item = Result<StreamEvent, A2AError>> + Send>>>
Subscribe to a task’s updates as a protocol-neutral stream of
StreamEvents.
This is the spec-compliant path: a single A2A SubscribeToTask round
trip with no reconnection and no Last-Event-ID — what any A2A agent
expects. For automatic reconnection (and gap-free resume against an
a2a-rs server) use
subscribe_resilient.
Sourcepub fn subscribe_resilient(
&self,
task_id: &str,
policy: RetryPolicy,
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, A2AError>> + Send>>
pub fn subscribe_resilient( &self, task_id: &str, policy: RetryPolicy, ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, A2AError>> + Send>>
Subscribe to a task’s updates with automatic reconnect + exponential backoff. The stream ends when the task reaches a terminal state (or retries are exhausted).
Reconnection itself is spec-compliant (it re-issues SubscribeToTask).
Resuming without gaps via Last-Event-ID is an a2a-rs enhancement
beyond the A2A v1.0 spec: it works against an a2a-rs server and degrades
gracefully (reconnect-from-current-state) against any spec-compliant one.
This is the reusable core that create_sse_stream
builds on; framework-agnostic, so non-Axum frontends can consume it
directly.