Skip to main content

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 advertised v1 endpoints 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?;
§Errors

Returns an error if the agent card cannot be fetched, parsed, or does not advertise a supported JSONRPC or HTTP+JSON interface.

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?;
§Errors

Returns an error if the agent card cannot be fetched, the response status is not successful, JSON parsing fails, or the card does not advertise a supported interface.

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)?;
§Errors

Returns an error if the agent card does not advertise a supported JSONRPC or HTTP+JSON interface.

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)?;
§Errors

Returns an error if the agent card does not advertise a supported JSONRPC or HTTP+JSON interface.

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)?;
§Errors

Returns an error if the agent card is invalid, headers cannot be parsed, or the HTTP client cannot be built.

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

§Errors

Returns an error if the network request fails, the response status is not successful, or JSON parsing fails.

Source

pub async fn fetch_extended_agent_card_if_available( &self, ) -> A2AResult<Option<AgentCard>>

Fetch the extended agent card if the agent advertises one.

Checks capabilities.extended_agent_card on the cached public card first. If the agent does not advertise an extended card, returns None immediately without making a network request.

§Errors

Returns an error if the network request fails or the response cannot be parsed.

Source

pub async fn send_message( &self, request: SendMessageRequest, ) -> A2AResult<SendMessageResponse>

Send a message using the A2A v1 surface.

Source

pub async fn send_streaming_message( &self, request: SendMessageRequest, ) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<StreamResponse>> + Send>>>

Send a streaming message using the A2A v1 surface.

Source

pub async fn get_task(&self, request: GetTaskRequest) -> A2AResult<Task>

Retrieve a task using the A2A v1 surface.

Source

pub async fn list_tasks( &self, request: ListTasksRequest, ) -> A2AResult<ListTasksResponse>

List tasks using the A2A v1 surface.

Source

pub async fn cancel_task(&self, request: CancelTaskRequest) -> A2AResult<Task>

Cancel a task using the A2A v1 surface.

Source

pub async fn subscribe_to_task( &self, request: SubscribeToTaskRequest, ) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<StreamResponse>> + Send>>>

Subscribe to a task stream using the A2A v1 surface.

Source

pub async fn get_extended_agent_card( &self, request: GetExtendedAgentCardRequest, ) -> A2AResult<AgentCard>

Fetch the extended agent card using the A2A v1 surface.

Source

pub async fn create_task_push_notification_config( &self, request: TaskPushNotificationConfig, ) -> A2AResult<TaskPushNotificationConfig>

Create or replace a task push notification config using the A2A v1 surface.

Source

pub async fn get_task_push_notification_config( &self, request: GetTaskPushNotificationConfigRequest, ) -> A2AResult<TaskPushNotificationConfig>

Fetch a task push notification config using the A2A v1 surface.

Source

pub async fn list_task_push_notification_configs( &self, request: ListTaskPushNotificationConfigsRequest, ) -> A2AResult<ListTaskPushNotificationConfigsResponse>

List task push notification configs using the A2A v1 surface.

Source

pub async fn delete_task_push_notification_config( &self, request: DeleteTaskPushNotificationConfigRequest, ) -> A2AResult<()>

Delete a task push notification config using the A2A v1 surface.

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.

§Errors

Returns an error if the RPC request fails or the remote agent returns an error response.

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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,