Skip to main content

A2aClient

Struct A2aClient 

Source
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

Source

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.

Source

pub const fn config(&self) -> &ClientConfig

Returns a reference to the active client configuration.

Source§

impl A2aClient

Source

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

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for A2aClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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> 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, 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