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 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?;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?;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)?;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)?;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)?;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
Sourcepub async fn send_message(
&self,
params: MessageSendParams,
) -> A2AResult<SendMessageResponse>
pub async fn send_message( &self, params: MessageSendParams, ) -> A2AResult<SendMessageResponse>
Send a message to the remote agent (non-streaming)
Sourcepub async fn send_streaming_message(
&self,
params: MessageSendParams,
) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<SendStreamingMessageResult>> + Send>>>
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)
Sourcepub async fn get_task(&self, params: TaskQueryParams) -> A2AResult<Task>
pub async fn get_task(&self, params: TaskQueryParams) -> A2AResult<Task>
Get a specific task from the remote agent
Sourcepub async fn cancel_task(&self, params: TaskIdParams) -> A2AResult<Task>
pub async fn cancel_task(&self, params: TaskIdParams) -> A2AResult<Task>
Cancel a task by its ID
Sourcepub async fn resubscribe_task(
&self,
params: TaskIdParams,
) -> A2AResult<Pin<Box<dyn Stream<Item = A2AResult<SendStreamingMessageResult>> + Send>>>
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.
Sourcepub async fn set_task_push_notification_config(
&self,
params: TaskPushNotificationConfig,
) -> A2AResult<TaskPushNotificationConfig>
pub async fn set_task_push_notification_config( &self, params: TaskPushNotificationConfig, ) -> A2AResult<TaskPushNotificationConfig>
Set or update the push notification configuration for a given task
Sourcepub async fn get_task_push_notification_config(
&self,
params: TaskIdParams,
) -> A2AResult<TaskPushNotificationConfig>
pub async fn get_task_push_notification_config( &self, params: TaskIdParams, ) -> A2AResult<TaskPushNotificationConfig>
Get the push notification configuration for a given task
Sourcepub async fn list_task_push_notification_config(
&self,
params: ListTaskPushNotificationConfigParams,
) -> A2AResult<Vec<TaskPushNotificationConfig>>
pub async fn list_task_push_notification_config( &self, params: ListTaskPushNotificationConfigParams, ) -> A2AResult<Vec<TaskPushNotificationConfig>>
List push notification configurations for a given task
Sourcepub async fn delete_task_push_notification_config(
&self,
params: DeleteTaskPushNotificationConfigParams,
) -> A2AResult<()>
pub async fn delete_task_push_notification_config( &self, params: DeleteTaskPushNotificationConfigParams, ) -> A2AResult<()>
Delete a push notification configuration for a given task
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.