Building a Client

The ClientBuilder creates an A2aClient configured for your target agent. It handles transport selection, timeouts, authentication, and interceptors. This page builds a client; the pages under it cover each group of options.

Basic client

#![allow(unused)]
fn main() {
use a2a_protocol_sdk::client::ClientBuilder;

let client = ClientBuilder::new("http://agent.example.com")
    .build()
    .expect("build client");
}

Without a binding the builder uses JSON-RPC; it does not look at the URL to choose. To choose another:

#![allow(unused)]
fn main() {
use a2a_protocol_sdk::client::ClientBuilder;
// Force JSON-RPC transport
let client = ClientBuilder::new("http://agent.example.com")
    .with_protocol_binding("JSONRPC")
    .build()
    .unwrap();

// Force REST transport
let client = ClientBuilder::new("http://agent.example.com")
    .with_protocol_binding("HTTP+JSON")
    .build()
    .unwrap();
}

To build from the agent's card instead of a URL, so that the client picks the binding the card offers and checks the card's capabilities and required extensions, use ClientBuilder::from_card(&card); the builder reference describes how it chooses.

Which page do I need

You want toPage
Change timeouts, retry transient failures, choose output modes, or return before the task finishesTimeouts, retries and delivery
Send a token or API key, add your own hooks around each call, or ask for extensionsInterceptors, API keys and extensions
Look up a builder method and its defaultBuilder reference
Call an agent over gRPCgRPC client
Share one client across requests and tasksReusing and sharing a client
Share connections between many clientsSharing connections: HttpPool
Call an agent behind a load balancerBehind a load balancer

Next Steps