pub struct A2aClient { /* private fields */ }Expand description
A client for communicating with A2A-compliant agents.
All A2A protocol methods are available as async methods. Create a client
via ClientBuilder or the A2aClient::from_card shorthand.
§Example
use a2a_protocol_client::ClientBuilder;
let client = ClientBuilder::new("http://localhost:8080").build()?;Implementations§
Source§impl A2aClient
impl A2aClient
Sourcepub fn from_card(card: &AgentCard) -> Result<A2aClient, ClientError>
pub fn from_card(card: &AgentCard) -> Result<A2aClient, ClientError>
Creates a client from an AgentCard using the recommended defaults.
Selects the transport based on the agent’s preferred protocol.
§Errors
Returns crate::error::ClientError::InvalidEndpoint if the agent
card URL is malformed or the transport cannot be constructed.
Sourcepub const fn config(&self) -> &ClientConfig
pub const fn config(&self) -> &ClientConfig
Returns a reference to the active client configuration.
Source§impl A2aClient
impl A2aClient
Sourcepub async fn get_extended_agent_card(&self) -> Result<AgentCard, ClientError>
pub async fn get_extended_agent_card(&self) -> Result<AgentCard, ClientError>
Fetches the full (private) agent card, authenticating the request.
Calls GetExtendedAgentCard. The returned card may include
private skills, security schemes, or additional interfaces not exposed
in the public /.well-known/agent.json.
The caller must have registered auth credentials via
crate::auth::AuthInterceptor or equivalent before calling this
method.
§Errors
Returns ClientError on transport or protocol errors.
Source§impl A2aClient
impl A2aClient
Sourcepub async fn set_push_config(
&self,
config: TaskPushNotificationConfig,
) -> Result<TaskPushNotificationConfig, ClientError>
pub async fn set_push_config( &self, config: TaskPushNotificationConfig, ) -> Result<TaskPushNotificationConfig, ClientError>
Registers or replaces a push notification configuration for a task.
Calls CreateTaskPushNotificationConfig. Returns the configuration as
stored by the server (including the server-assigned id).
§Errors
Returns ClientError::Protocol with
a2a_protocol_types::ErrorCode::PushNotificationNotSupported if the agent
does not support push notifications.
Sourcepub async fn get_push_config(
&self,
task_id: impl Into<String>,
id: impl Into<String>,
) -> Result<TaskPushNotificationConfig, ClientError>
pub async fn get_push_config( &self, task_id: impl Into<String>, id: impl Into<String>, ) -> Result<TaskPushNotificationConfig, ClientError>
Retrieves a push notification configuration by task ID and config ID.
Calls GetTaskPushNotificationConfig.
§Errors
Returns ClientError on transport or protocol errors.
Sourcepub async fn list_push_configs(
&self,
params: ListPushConfigsParams,
) -> Result<ListPushConfigsResponse, ClientError>
pub async fn list_push_configs( &self, params: ListPushConfigsParams, ) -> Result<ListPushConfigsResponse, ClientError>
Lists push notification configurations for a task with pagination.
Calls ListTaskPushNotificationConfigs.
§Errors
Returns ClientError on transport or protocol errors.
Sourcepub async fn delete_push_config(
&self,
task_id: impl Into<String>,
id: impl Into<String>,
) -> Result<(), ClientError>
pub async fn delete_push_config( &self, task_id: impl Into<String>, id: impl Into<String>, ) -> Result<(), ClientError>
Deletes a push notification configuration.
Calls DeleteTaskPushNotificationConfig.
§Errors
Returns ClientError on transport or protocol errors.
Source§impl A2aClient
impl A2aClient
Sourcepub async fn send_message(
&self,
params: MessageSendParams,
) -> Result<SendMessageResponse, ClientError>
pub async fn send_message( &self, params: MessageSendParams, ) -> Result<SendMessageResponse, ClientError>
Sends a message to the agent and waits for a complete response.
Calls the SendMessage JSON-RPC method. The agent may respond with
either a completed Task or an immediate Message.
§Errors
Returns ClientError on transport, serialization, or protocol errors.
Sourcepub async fn stream_message(
&self,
params: MessageSendParams,
) -> Result<EventStream, ClientError>
pub async fn stream_message( &self, params: MessageSendParams, ) -> Result<EventStream, ClientError>
Sends a message and returns a streaming EventStream of progress
events.
Calls the SendStreamingMessage JSON-RPC method. The agent responds
with an SSE stream of a2a_protocol_types::StreamResponse events.
§Errors
Returns ClientError on transport or protocol errors.
Source§impl A2aClient
impl A2aClient
Sourcepub async fn get_task(
&self,
params: TaskQueryParams,
) -> Result<Task, ClientError>
pub async fn get_task( &self, params: TaskQueryParams, ) -> Result<Task, ClientError>
Retrieves a task by ID.
Calls the GetTask JSON-RPC method.
§Errors
Returns ClientError::Protocol with a2a_protocol_types::ErrorCode::TaskNotFound
if no task with the given ID exists.
Sourcepub async fn list_tasks(
&self,
params: ListTasksParams,
) -> Result<TaskListResponse, ClientError>
pub async fn list_tasks( &self, params: ListTasksParams, ) -> Result<TaskListResponse, ClientError>
Lists tasks visible to the caller.
Calls the ListTasks JSON-RPC method. Results are paginated; use
params.page_token to fetch subsequent pages.
§Errors
Returns ClientError on transport or protocol errors.
Sourcepub async fn cancel_task(
&self,
id: impl Into<String>,
) -> Result<Task, ClientError>
pub async fn cancel_task( &self, id: impl Into<String>, ) -> Result<Task, ClientError>
Requests cancellation of a running task.
Calls the CancelTask JSON-RPC method. Returns the task in its
post-cancellation state.
§Errors
Returns ClientError::Protocol with
a2a_protocol_types::ErrorCode::TaskNotCancelable if the task cannot be
canceled in its current state.
Sourcepub async fn subscribe_to_task(
&self,
id: impl Into<String>,
) -> Result<EventStream, ClientError>
pub async fn subscribe_to_task( &self, id: impl Into<String>, ) -> Result<EventStream, ClientError>
Subscribes to the SSE stream for an in-progress task.
Calls the SubscribeToTask method. Useful after an unexpected
disconnection from a SendStreamingMessage call.
Events already delivered before the reconnect are not replayed.
§Errors
Returns ClientError::Protocol with
a2a_protocol_types::ErrorCode::TaskNotFound if the task is not in a
streaming-eligible state.