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) -> ClientResult<Self>
pub fn from_card(card: &AgentCard) -> ClientResult<Self>
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,
) -> ClientResult<AuthenticatedExtendedCardResponse>
pub async fn get_extended_agent_card( &self, ) -> ClientResult<AuthenticatedExtendedCardResponse>
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,
) -> ClientResult<TaskPushNotificationConfig>
pub async fn set_push_config( &self, config: TaskPushNotificationConfig, ) -> ClientResult<TaskPushNotificationConfig>
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>,
) -> ClientResult<TaskPushNotificationConfig>
pub async fn get_push_config( &self, task_id: impl Into<String>, id: impl Into<String>, ) -> ClientResult<TaskPushNotificationConfig>
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,
) -> ClientResult<ListPushConfigsResponse>
pub async fn list_push_configs( &self, params: ListPushConfigsParams, ) -> ClientResult<ListPushConfigsResponse>
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>,
) -> ClientResult<()>
pub async fn delete_push_config( &self, task_id: impl Into<String>, id: impl Into<String>, ) -> ClientResult<()>
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,
) -> ClientResult<SendMessageResponse>
pub async fn send_message( &self, params: MessageSendParams, ) -> ClientResult<SendMessageResponse>
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.
Client-level configuration (e.g. return_immediately, history_length)
is automatically merged into the request parameters. Per-request values
take precedence.
§Errors
Returns ClientError on transport, serialization, or protocol errors.
Sourcepub async fn stream_message(
&self,
params: MessageSendParams,
) -> ClientResult<EventStream>
pub async fn stream_message( &self, params: MessageSendParams, ) -> ClientResult<EventStream>
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) -> ClientResult<Task>
pub async fn get_task(&self, params: TaskQueryParams) -> ClientResult<Task>
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,
) -> ClientResult<TaskListResponse>
pub async fn list_tasks( &self, params: ListTasksParams, ) -> ClientResult<TaskListResponse>
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>) -> ClientResult<Task>
pub async fn cancel_task(&self, id: impl Into<String>) -> ClientResult<Task>
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>,
) -> ClientResult<EventStream>
pub async fn subscribe_to_task( &self, id: impl Into<String>, ) -> ClientResult<EventStream>
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§
Auto Trait Implementations§
impl Freeze for A2aClient
impl !RefUnwindSafe for A2aClient
impl Send for A2aClient
impl Sync for A2aClient
impl Unpin for A2aClient
impl UnsafeUnpin for A2aClient
impl !UnwindSafe for A2aClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request