A2AClient

Struct A2AClient 

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

A2A client for communicating with remote agents

Implementations§

Source§

impl A2AClient

Source

pub async fn from_card_url(base_url: impl AsRef<str>) -> A2AResult<Self>

Create a new A2A client from an agent card URL

This will fetch the agent card from the specified URL and use the service endpoint URL from the card for all subsequent requests.

Uses a default reqwest::Client for HTTP requests. For custom HTTP configuration, use from_card_url_with_client().

§Example
use a2a_client::A2AClient;

let client = A2AClient::from_card_url("https://agent.example.com").await?;
Source

pub async fn from_card_url_with_client( base_url: impl AsRef<str>, http_client: Client, ) -> A2AResult<Self>

Create a new A2A client from an agent card URL with a custom HTTP client

This allows you to provide a pre-configured reqwest::Client with custom settings like timeouts, proxies, TLS config, default headers, etc.

§Example
use a2a_client::A2AClient;
use reqwest::Client;
use std::time::Duration;

let http_client = Client::builder()
    .timeout(Duration::from_secs(30))
    .build()?;

let client = A2AClient::from_card_url_with_client(
    "https://agent.example.com",
    http_client
).await?;
Source

pub fn from_card(agent_card: AgentCard) -> A2AResult<Self>

Create a new A2A client directly from an agent card

This is useful when you already have an agent card and don’t need to fetch it. Uses a default reqwest::Client. For custom HTTP configuration, use from_card_with_client().

§Example
use a2a_client::A2AClient;
use a2a_types::AgentCard;

let client = A2AClient::from_card(agent_card)?;
Source

pub fn from_card_with_client( agent_card: AgentCard, http_client: Client, ) -> A2AResult<Self>

Create a new A2A client from an agent card with a custom HTTP client

This allows you to provide a pre-configured reqwest::Client with custom settings like timeouts, proxies, TLS config, default headers, etc.

§Example
use a2a_client::A2AClient;
use a2a_types::AgentCard;
use reqwest::Client;
use std::time::Duration;

let http_client = Client::builder()
    .timeout(Duration::from_secs(30))
    .default_headers({
        let mut headers = reqwest::header::HeaderMap::new();
        headers.insert("X-Custom-Header", "value".parse()?);
        headers
    })
    .build()?;

let client = A2AClient::from_card_with_client(agent_card, http_client)?;
Source

pub fn from_card_with_headers( agent_card: AgentCard, headers: HashMap<String, String>, ) -> A2AResult<Self>

Create a new A2A client from an agent card with custom headers

This is a convenience method that builds a reqwest::Client with the provided headers and uses it to create the A2AClient.

§Example
use a2a_client::A2AClient;
use a2a_types::AgentCard;
use std::collections::HashMap;

let mut headers = HashMap::new();
headers.insert("Authorization".to_string(), "Bearer token123".to_string());
headers.insert("X-API-Key".to_string(), "my-api-key".to_string());

let client = A2AClient::from_card_with_headers(agent_card, headers)?;
Source

pub fn with_auth_token(self, token: impl Into<String>) -> Self

Set authentication token (builder pattern)

Source

pub fn agent_card(&self) -> &AgentCard

Get the cached agent card

Source

pub async fn fetch_agent_card( &self, base_url: impl AsRef<str>, ) -> A2AResult<AgentCard>

Fetch a fresh agent card from the base URL

Source

pub async fn send_message( &self, params: MessageSendParams, ) -> A2AResult<SendMessageResponse>

Send a message to the remote agent (non-streaming)

Source

pub async fn send_streaming_message( &self, params: MessageSendParams, ) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<SendStreamingMessageResult>> + Send>>>

Send a streaming message to the remote agent

Returns a stream of events (Task, Message, TaskStatusUpdateEvent, TaskArtifactUpdateEvent)

Source

pub async fn get_task(&self, params: TaskQueryParams) -> A2AResult<Task>

Get a specific task from the remote agent

Source

pub async fn cancel_task(&self, params: TaskIdParams) -> A2AResult<Task>

Cancel a task by its ID

Source

pub async fn resubscribe_task( &self, params: TaskIdParams, ) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<SendStreamingMessageResult>> + Send>>>

Resubscribe to a task’s event stream

This is used if a previous SSE connection for an active task was broken.

Source

pub async fn set_task_push_notification_config( &self, params: TaskPushNotificationConfig, ) -> A2AResult<TaskPushNotificationConfig>

Set or update the push notification configuration for a given task

Source

pub async fn get_task_push_notification_config( &self, params: TaskIdParams, ) -> A2AResult<TaskPushNotificationConfig>

Get the push notification configuration for a given task

Source

pub async fn list_task_push_notification_config( &self, params: ListTaskPushNotificationConfigParams, ) -> A2AResult<Vec<TaskPushNotificationConfig>>

List push notification configurations for a given task

Source

pub async fn delete_task_push_notification_config( &self, params: DeleteTaskPushNotificationConfigParams, ) -> A2AResult<()>

Delete a push notification configuration for a given task

Source

pub async fn call_extension_method<TParams, TResponse>( &self, method: &str, params: TParams, ) -> A2AResult<TResponse>
where TParams: Serialize, TResponse: for<'de> Deserialize<'de>,

Call a custom extension method

This allows calling custom JSON-RPC methods defined by agent extensions.

Source

pub async fn list_tasks( &self, context_id: Option<String>, ) -> A2AResult<Vec<Task>>

List tasks from the remote agent

Note: This method is not part of the official A2A spec but is commonly implemented.

Trait Implementations§

Source§

impl Clone for A2AClient

Source§

fn clone(&self) -> A2AClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: 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: 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,