Timeouts, retries and delivery
The builder options that decide how long a call may take, whether a failed call is tried again, and what the agent sends back. Every option here has a default, listed in the builder reference; set only the ones you need to change.
Timeouts
#![allow(unused)] fn main() { use a2a_protocol_sdk::client::ClientBuilder; let url = "http://agent.example.com"; use std::time::Duration; let client = ClientBuilder::new(url) .with_timeout(Duration::from_secs(60)) // Per-request timeout (default: 30s) .with_connection_timeout(Duration::from_secs(5)) // TCP connect timeout (default: 10s) .with_stream_connect_timeout(Duration::from_secs(15)) // stream headers (default: 30s) .with_stream_first_event_timeout(Duration::from_secs(60)) // first event after that (default: 5 min) .with_stream_idle_timeout(Some(Duration::from_secs(120))) // silence allowed mid-stream (default: 5 min) .build() .unwrap(); }
Output modes
Specify which MIME types the client can handle:
#![allow(unused)] fn main() { use a2a_protocol_sdk::client::ClientBuilder; let url = "http://agent.example.com"; let client = ClientBuilder::new(url) .with_accepted_output_modes(vec![ "text/plain".into(), "application/json".into(), "image/png".into(), ]) .build() .unwrap(); }
Default: ["text/plain", "application/json"]
History length
Control how many historical messages are included in responses:
#![allow(unused)] fn main() { use a2a_protocol_sdk::client::ClientBuilder; let url = "http://agent.example.com"; let client = ClientBuilder::new(url) .with_history_length(10) // Include last 10 messages .build() .unwrap(); }
Retry policy
Enable automatic retries on transient failures (connection errors, timeouts, HTTP 429/502/503/504):
#![allow(unused)] fn main() { use a2a_protocol_sdk::client::ClientBuilder; use std::time::Duration; let url = "http://agent.example.com"; use a2a_protocol_client::RetryPolicy; let client = ClientBuilder::new(url) .with_retry_policy(RetryPolicy::default()) // 3 retries, 500ms initial backoff .build() .unwrap(); // Custom retry configuration let client = ClientBuilder::new(url) .with_retry_policy( RetryPolicy::default() .with_max_retries(5) .with_initial_backoff(Duration::from_secs(1)) .with_max_backoff(Duration::from_secs(60)) .with_backoff_multiplier(3.0), ) .build() .unwrap(); }
Retries can multiply an overload: with three retries, a saturated worker sees up to four times the calls it was sent. Three opt-in bounds keep a client from adding to it:
#![allow(unused)] fn main() { use a2a_protocol_sdk::client::ClientBuilder; use std::time::Duration; let url = "http://agent.example.com"; use a2a_protocol_client::{RetryBudget, RetryPolicy}; let client = ClientBuilder::new(url) .with_retry_policy( RetryPolicy::default() // At most one retry per ten calls, and one a second besides. .with_budget(RetryBudget::new(0.1, 1.0)) // No retry starts more than 20 s after the call's first attempt. .with_max_elapsed(Duration::from_secs(20)), ) // At most 32 calls wait for a response at once. .with_max_in_flight(32) .build() .unwrap(); }
A retry the budget cannot pay for, or that would start after max_elapsed, is
not made, and the error that called for it is returned. A call that finds the
in-flight cap reached is refused up front with TooManyPendingRequests, which is
retryable, so a retry policy backs off and tries again as responses arrive. A
streaming call counts until its stream has opened, not while it stays open.
All three are per client: a thousand clients each have their own, so share one
Arc<A2aClient> per peer to bound the calls to it.
Sends (send_message, stream_message, creating a push config) are retried only
on a 429, a 503, or a protocol error that names a retry delay (RetryInfo), all
of which prove the server did not process them. After a timeout or a dropped
connection they are not re-sent, except a send_message or stream_message that
carries an idempotency key the peer honours; see
Idempotent Sends.
Return immediately
For push notification workflows, return the task immediately without waiting for completion:
#![allow(unused)] fn main() { use a2a_protocol_sdk::client::ClientBuilder; let url = "http://agent.example.com"; let client = ClientBuilder::new(url) .with_return_immediately(true) .build() .unwrap(); }
Streams have their own timeouts for each phase of a stream; Streaming Responses explains each one.