pub struct A2AClient { /* private fields */ }Expand description
A2A Client - communicates with remote A2A agents.
Implementations§
Source§impl A2AClient
impl A2AClient
Sourcepub fn new(base_url: impl Into<String>) -> Result<Self, A2AError>
pub fn new(base_url: impl Into<String>) -> Result<Self, A2AError>
Create a new client targeting the given base URL.
Uses a 30s per-request timeout and a 10s connect timeout. The client is safe to share and call concurrently; each request gets its own ID.
Returns an error if the HTTP client cannot be built (e.g. the TLS
backend fails to initialize). For full configuration, use
builder instead.
Sourcepub fn with_http_client(base_url: impl Into<String>, http: Client) -> Self
pub fn with_http_client(base_url: impl Into<String>, http: Client) -> Self
Create a client with a custom reqwest::Client (for timeouts, etc.).
The given client is used for both RPC and streaming requests; if it carries a total timeout, long-lived SSE streams will be cut off — the caller owns that trade-off.
Sourcepub fn builder(base_url: impl Into<String>) -> A2AClientBuilder
pub fn builder(base_url: impl Into<String>) -> A2AClientBuilder
Start building a client with full configuration.
Sourcepub async fn get_agent_card(&self) -> Result<AgentCard, A2AError>
pub async fn get_agent_card(&self) -> Result<AgentCard, A2AError>
Fetch the agent card from GET /.well-known/agent-card.json.
Performs two integrity checks (P1-3):
- URL consistency: if the card advertises a
urlthat differs from the base URL this client was pointed at, a warning is logged. The card is still returned — a load-balanced deployment legitimately advertises a public URL different from the node you reached. - Signature: if the card carries a
signatureand a verification secret is configured, the signature is verified and a mismatch is a hard error. Withrequire_card_signature, a signed card with no secret configured is also rejected. Unsigned cards pass through.
Sourcepub async fn send_task(&self, message: A2AMessage) -> Result<A2ATask, A2AError>
pub async fn send_task(&self, message: A2AMessage) -> Result<A2ATask, A2AError>
Send a task to the remote agent (tasks/send).
The request carries the client’s trace_id, if configured (P1-5).
Sourcepub async fn send_task_with_message_id(
&self,
message: A2AMessage,
message_id: &str,
) -> Result<A2ATask, A2AError>
pub async fn send_task_with_message_id( &self, message: A2AMessage, message_id: &str, ) -> Result<A2ATask, A2AError>
Send a task with an explicit message_id so a retried call returns the
already-created task instead of running the chain twice (P1-6).
Sourcepub async fn resume_task(
&self,
task_id: &str,
message: A2AMessage,
) -> Result<A2ATask, A2AError>
pub async fn resume_task( &self, task_id: &str, message: A2AMessage, ) -> Result<A2ATask, A2AError>
Send a message to continue an existing input-required task, resuming
it back to working (P2-3).
Equivalent to tasks/send carrying a taskId.
Sourcepub async fn get_task(&self, task_id: &str) -> Result<A2ATask, A2AError>
pub async fn get_task(&self, task_id: &str) -> Result<A2ATask, A2AError>
Get a task by ID (tasks/get).
Sourcepub async fn get_task_details(
&self,
task_id: &str,
) -> Result<A2ATaskDetails, A2AError>
pub async fn get_task_details( &self, task_id: &str, ) -> Result<A2ATaskDetails, A2AError>
Get a task by ID including its result and error (tasks/get).
Sourcepub async fn cancel_task(&self, task_id: &str) -> Result<A2ATask, A2AError>
pub async fn cancel_task(&self, task_id: &str) -> Result<A2ATask, A2AError>
Cancel a task by ID (tasks/cancel).
Sourcepub async fn send_task_and_wait(
&self,
message: A2AMessage,
timeout: Duration,
) -> Result<A2ATaskResult, A2AError>
pub async fn send_task_and_wait( &self, message: A2AMessage, timeout: Duration, ) -> Result<A2ATaskResult, A2AError>
Send a task and poll tasks/get until it reaches a terminal state.
Returns the task result on completed, an error on failed /
cancelled / rejected / expired, an A2AError::InputRequired
when the agent asks for more information (resume with
A2AClient::resume_task), or a A2AError::Timeout if the task does
not complete within timeout.
Sourcepub async fn send_task_and_wait_with_message_id(
&self,
message: A2AMessage,
message_id: &str,
timeout: Duration,
) -> Result<A2ATaskResult, A2AError>
pub async fn send_task_and_wait_with_message_id( &self, message: A2AMessage, message_id: &str, timeout: Duration, ) -> Result<A2ATaskResult, A2AError>
Idempotent variant of A2AClient::send_task_and_wait: sends the task
with a message_id (P1-6) so retries never create duplicate tasks.
Sourcepub async fn post_request(
&self,
req: A2ARequest,
) -> Result<A2AResponse, A2AError>
pub async fn post_request( &self, req: A2ARequest, ) -> Result<A2AResponse, A2AError>
Send a raw A2A request via POST to the agent endpoint.
Sourcepub async fn connect_sse(&self, sse_url: &str) -> Result<A2ASseStream, A2AError>
pub async fn connect_sse(&self, sse_url: &str) -> Result<A2ASseStream, A2AError>
Open an SSE stream from sse_url, yielding TaskPushNotification
events as they arrive (P2-1).
The stream is useful for observing task progress without polling
tasks/get. Events carry a task.id, so a caller receiving
notifications for multiple tasks can filter by the id it cares about.
Sourcepub async fn send_task_streaming(
&self,
sse_url: &str,
message: A2AMessage,
) -> Result<A2ASseStream, A2AError>
pub async fn send_task_streaming( &self, sse_url: &str, message: A2AMessage, ) -> Result<A2ASseStream, A2AError>
Send a task and stream its progress notifications over SSE (P2-1).
Opens the SSE subscription at sse_url first (so no early events are
missed), then sends the task via tasks/send. The returned stream
yields TaskPushNotification events for the task.