pub struct A2AClient { /* private fields */ }Expand description
A2A client for communicating with remote agents
Implementations§
Source§impl A2AClient
impl A2AClient
Sourcepub async fn from_card_url(base_url: impl AsRef<str>) -> A2AResult<Self>
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.
Sourcepub async fn from_card_url_with_client(
base_url: impl AsRef<str>,
http_client: Client,
) -> A2AResult<Self>
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.
Sourcepub fn from_card(agent_card: AgentCard) -> A2AResult<Self>
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.
Sourcepub fn from_card_with_client(
agent_card: AgentCard,
http_client: Client,
) -> A2AResult<Self>
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.
Sourcepub fn from_card_with_headers(
agent_card: AgentCard,
headers: HashMap<String, String>,
) -> A2AResult<Self>
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.
Sourcepub fn with_auth_token(self, token: impl Into<String>) -> Self
pub fn with_auth_token(self, token: impl Into<String>) -> Self
Set authentication token (builder pattern)
Sourcepub fn agent_card(&self) -> &AgentCard
pub fn agent_card(&self) -> &AgentCard
Get the cached agent card
Sourcepub async fn fetch_agent_card(
&self,
base_url: impl AsRef<str>,
) -> A2AResult<AgentCard>
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.
Sourcepub async fn fetch_extended_agent_card_if_available(
&self,
) -> A2AResult<Option<AgentCard>>
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.
Sourcepub async fn send_message(
&self,
request: SendMessageRequest,
) -> A2AResult<SendMessageResponse>
pub async fn send_message( &self, request: SendMessageRequest, ) -> A2AResult<SendMessageResponse>
Send a message using the A2A v1 surface.
Sourcepub async fn send_streaming_message(
&self,
request: SendMessageRequest,
) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<StreamResponse>> + Send>>>
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.
Sourcepub async fn get_task(&self, request: GetTaskRequest) -> A2AResult<Task>
pub async fn get_task(&self, request: GetTaskRequest) -> A2AResult<Task>
Retrieve a task using the A2A v1 surface.
Sourcepub async fn list_tasks(
&self,
request: ListTasksRequest,
) -> A2AResult<ListTasksResponse>
pub async fn list_tasks( &self, request: ListTasksRequest, ) -> A2AResult<ListTasksResponse>
List tasks using the A2A v1 surface.
Sourcepub async fn cancel_task(&self, request: CancelTaskRequest) -> A2AResult<Task>
pub async fn cancel_task(&self, request: CancelTaskRequest) -> A2AResult<Task>
Cancel a task using the A2A v1 surface.
Sourcepub async fn subscribe_to_task(
&self,
request: SubscribeToTaskRequest,
) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<StreamResponse>> + Send>>>
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.
Sourcepub async fn get_extended_agent_card(
&self,
request: GetExtendedAgentCardRequest,
) -> A2AResult<AgentCard>
pub async fn get_extended_agent_card( &self, request: GetExtendedAgentCardRequest, ) -> A2AResult<AgentCard>
Fetch the extended agent card using the A2A v1 surface.
Sourcepub async fn create_task_push_notification_config(
&self,
request: TaskPushNotificationConfig,
) -> A2AResult<TaskPushNotificationConfig>
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.
Sourcepub async fn get_task_push_notification_config(
&self,
request: GetTaskPushNotificationConfigRequest,
) -> A2AResult<TaskPushNotificationConfig>
pub async fn get_task_push_notification_config( &self, request: GetTaskPushNotificationConfigRequest, ) -> A2AResult<TaskPushNotificationConfig>
Fetch a task push notification config using the A2A v1 surface.
Sourcepub async fn list_task_push_notification_configs(
&self,
request: ListTaskPushNotificationConfigsRequest,
) -> A2AResult<ListTaskPushNotificationConfigsResponse>
pub async fn list_task_push_notification_configs( &self, request: ListTaskPushNotificationConfigsRequest, ) -> A2AResult<ListTaskPushNotificationConfigsResponse>
List task push notification configs using the A2A v1 surface.
Sourcepub async fn delete_task_push_notification_config(
&self,
request: DeleteTaskPushNotificationConfigRequest,
) -> A2AResult<()>
pub async fn delete_task_push_notification_config( &self, request: DeleteTaskPushNotificationConfigRequest, ) -> A2AResult<()>
Delete a task push notification config using the A2A v1 surface.
Sourcepub async fn call_extension_method<TParams, TResponse>(
&self,
method: &str,
params: TParams,
) -> A2AResult<TResponse>where
TParams: Serialize,
TResponse: for<'de> Deserialize<'de>,
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.