Skip to main content

A2AClient

Struct A2AClient 

Source
pub struct A2AClient { /* private fields */ }
Expand description

A2A Client - communicates with remote A2A agents.

Implementations§

Source§

impl A2AClient

Source

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.

Source

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.

Source

pub fn builder(base_url: impl Into<String>) -> A2AClientBuilder

Start building a client with full configuration.

Source

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 url that 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 signature and a verification secret is configured, the signature is verified and a mismatch is a hard error. With require_card_signature, a signed card with no secret configured is also rejected. Unsigned cards pass through.
Source

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).

Source

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).

Source

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.

Source

pub async fn get_task(&self, task_id: &str) -> Result<A2ATask, A2AError>

Get a task by ID (tasks/get).

Source

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).

Source

pub async fn cancel_task(&self, task_id: &str) -> Result<A2ATask, A2AError>

Cancel a task by ID (tasks/cancel).

Source

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.

Source

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.

Source

pub async fn post_request( &self, req: A2ARequest, ) -> Result<A2AResponse, A2AError>

Send a raw A2A request via POST to the agent endpoint.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more