pub struct A2aClient { /* private fields */ }Expand description
The base URL of an A2A peer.
peer is the URL the well-known card resolves to, e.g.
http://peer:8080. The well-known URI and the JSON-RPC
method table are appended to this base, so a peer that
exposes its card at http://peer:8080/.well-known/agent-card.json
and its method table at http://peer:8080/a2a is driven
with A2aClient::new("http://peer:8080").
The four constructors below build a client aimed at the
conventional paths. A consumer whose peer uses a
non-conventional layout — e.g. the card at
/card and the JSON-RPC at /rpc — uses
A2aClient::with_paths to point the client at
non-default paths.
Implementations§
Source§impl A2aClient
impl A2aClient
Sourcepub fn new(peer: impl Into<String>) -> Result<Self, A2aClientError>
pub fn new(peer: impl Into<String>) -> Result<Self, A2aClientError>
A client pointed at the conventional paths.
The well-known card is fetched from
peer + /.well-known/agent-card.json; the
JSON-RPC method table is POSTed to
peer + /a2a. The two paths match the
A2A v1.0 §8 discovery and §3 method
routes; a consumer whose peer does not
follow them uses
with_paths instead.
§Errors
A2aClientError::Io when the underlying
reqwest::Client cannot be built (a TLS
configuration error or an invalid
default-header value). The transport is
built once at construction; every method
on the client reuses it.
Sourcepub fn with_paths(
peer: impl Into<String>,
card_path: impl Into<String>,
jsonrpc_path: impl Into<String>,
streaming_path: impl Into<String>,
) -> Result<Self, A2aClientError>
pub fn with_paths( peer: impl Into<String>, card_path: impl Into<String>, jsonrpc_path: impl Into<String>, streaming_path: impl Into<String>, ) -> Result<Self, A2aClientError>
A client pointed at non-default card and JSON-RPC paths.
card_path is the URI the GET to fetch the
agent card is sent to, relative to peer
(e.g. /custom/card). jsonrpc_path is the
URI the POST to the JSON-RPC method table
is sent to, relative to peer
(e.g. /custom/rpc). streaming_path is
the URI the streaming methods
(send_streaming_message
and subscribe_to_task)
POST to, relative to peer.
§Errors
A2aClientError::Io when the underlying
reqwest::Client cannot be built. The
construction mirrors A2aClient::new.
Sourcepub fn with_bearer_token(self, token: impl Into<String>) -> Self
pub fn with_bearer_token(self, token: impl Into<String>) -> Self
Attaches a Bearer token to every subsequent request.
The A2A v1.0 spec lets an agent declare a
securitySchemes map on its card; the most
common value is Http with Bearer (RFC
6750). A consumer that has an opaque token
from the peer’s auth endpoint passes it
here, and every card(), send_message(),
and send_streaming_message() call carries
Authorization: Bearer <token>. The card
itself is fetched unauthenticated by default
— a peer that gates the card behind auth
needs a separate way to get the token, which
is out of scope for this commit.
The token is held in an Arc<str>; a clone
shares the same allocation, not a copy of
the secret.
Sourcepub async fn card(&self) -> Result<AgentCard, A2aClientError>
pub async fn card(&self) -> Result<AgentCard, A2aClientError>
Fetches the agent card at the well-known URI.
Not cached. A consumer who wants the card once calls it once; a consumer who wants the card to reflect a server-side update calls it again.
§Errors
A2aClientError::Io on a transport
failure or non-2xx status, or
A2aClientError::Parse when the body
is well-formed JSON but not the
AgentCard shape.
Sourcepub async fn send_message(
&self,
request: SendMessageRequest,
) -> Result<SendMessageResponse, A2aClientError>
pub async fn send_message( &self, request: SendMessageRequest, ) -> Result<SendMessageResponse, A2aClientError>
SendMessage — send a message to the agent.
§Errors
A2aClientError on transport, JSON-RPC, or parse failure.
Sourcepub async fn get_task(
&self,
request: GetTaskRequest,
) -> Result<GetTaskResponse, A2aClientError>
pub async fn get_task( &self, request: GetTaskRequest, ) -> Result<GetTaskResponse, A2aClientError>
GetTask — read a task by id.
Sourcepub async fn list_tasks(
&self,
request: ListTasksRequest,
) -> Result<ListTasksResponse, A2aClientError>
pub async fn list_tasks( &self, request: ListTasksRequest, ) -> Result<ListTasksResponse, A2aClientError>
ListTasks — list tasks with optional filtering.
Sourcepub async fn cancel_task(
&self,
request: CancelTaskRequest,
) -> Result<CancelTaskResponse, A2aClientError>
pub async fn cancel_task( &self, request: CancelTaskRequest, ) -> Result<CancelTaskResponse, A2aClientError>
CancelTask — cancel a task in progress.
Sourcepub async fn send_streaming_message(
&self,
request: SendMessageRequest,
) -> Result<Vec<StreamingEvent>, A2aClientError>
pub async fn send_streaming_message( &self, request: SendMessageRequest, ) -> Result<Vec<StreamingEvent>, A2aClientError>
SendStreamingMessage — send a message and stream the agent’s
progress as a sequence of typed events.
Returns every event the server sent before
closing the stream. The A2A spec terminates
a SendStreamingMessage with a status
event whose final flag is true; a
consumer who needs that terminal event
checks StreamingEvent::Status(…).final
on the last element.
Sourcepub async fn subscribe_to_task(
&self,
task_id: String,
) -> Result<Vec<StreamingEvent>, A2aClientError>
pub async fn subscribe_to_task( &self, task_id: String, ) -> Result<Vec<StreamingEvent>, A2aClientError>
SubscribeToTask — open an SSE stream of updates
for an existing non-terminal task.
Sourcepub async fn create_push_notification_config(
&self,
request: CreateTaskPushNotificationConfigRequest,
) -> Result<CreateTaskPushNotificationConfigResponse, A2aClientError>
pub async fn create_push_notification_config( &self, request: CreateTaskPushNotificationConfigRequest, ) -> Result<CreateTaskPushNotificationConfigResponse, A2aClientError>
CreateTaskPushNotificationConfig — register a
push notification config for a task.
Sourcepub async fn get_push_notification_config(
&self,
request: GetTaskPushNotificationConfigRequest,
) -> Result<GetTaskPushNotificationConfigResponse, A2aClientError>
pub async fn get_push_notification_config( &self, request: GetTaskPushNotificationConfigRequest, ) -> Result<GetTaskPushNotificationConfigResponse, A2aClientError>
GetTaskPushNotificationConfig — read a config by id.
Sourcepub async fn list_push_notification_configs(
&self,
request: ListTaskPushNotificationConfigsRequest,
) -> Result<ListTaskPushNotificationConfigsResponse, A2aClientError>
pub async fn list_push_notification_configs( &self, request: ListTaskPushNotificationConfigsRequest, ) -> Result<ListTaskPushNotificationConfigsResponse, A2aClientError>
ListTaskPushNotificationConfigs — list a task’s configs.
Sourcepub async fn delete_push_notification_config(
&self,
request: DeleteTaskPushNotificationConfigRequest,
) -> Result<(), A2aClientError>
pub async fn delete_push_notification_config( &self, request: DeleteTaskPushNotificationConfigRequest, ) -> Result<(), A2aClientError>
DeleteTaskPushNotificationConfig — remove a config.
Returns Ok(()) when the peer confirms the
deletion. The A2A spec answers a successful
delete with the empty JSON-RPC result; the
helper’s () deserialisation accepts that
without an extra wrapper.
Sourcepub async fn get_extended_agent_card(
&self,
request: GetExtendedAgentCardRequest,
) -> Result<GetExtendedAgentCardResponse, A2aClientError>
pub async fn get_extended_agent_card( &self, request: GetExtendedAgentCardRequest, ) -> Result<GetExtendedAgentCardResponse, A2aClientError>
GetExtendedAgentCard — fetch the
authenticated extended agent card.
The A2A spec splits the agent card into two reads: the public card served on the well-known path with no authentication, and the extended card returned by this method, which requires the same bearer token the JSON-RPC and streaming routes require. The extended card is the same card plus any additional capabilities the server chooses not to advertise publicly (a paid tool, an admin endpoint, a tenant-scoped skill).
A consumer who has not set a bearer token
via with_bearer_token
will see a 401 from the peer — that is
the spec’s “you must authenticate to read
this card” signal, not a transport error.
A consumer who has set a token gets the
extended card in the response.
Trait Implementations§
Source§impl Clone for A2aClient
impl Clone for A2aClient
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
A clone is cheap: the HttpClient
reqwest ships already pools and
shares connections across clones,
and the id counter is an Arc so a
clone and its original issue distinct
ids. The Arc<str> paths are
reference-counted copies, not deep
clones. The bearer token, if any, is
also Arc<str> — a clone points at
the same allocation, not a copy of
the secret.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more