Skip to main content

A2aClient

Struct A2aClient 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn get_task( &self, request: GetTaskRequest, ) -> Result<GetTaskResponse, A2aClientError>

GetTask — read a task by id.

Source

pub async fn list_tasks( &self, request: ListTasksRequest, ) -> Result<ListTasksResponse, A2aClientError>

ListTasks — list tasks with optional filtering.

Source

pub async fn cancel_task( &self, request: CancelTaskRequest, ) -> Result<CancelTaskResponse, A2aClientError>

CancelTask — cancel a task in progress.

Source

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.

Source

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.

Source

pub async fn create_push_notification_config( &self, request: CreateTaskPushNotificationConfigRequest, ) -> Result<CreateTaskPushNotificationConfigResponse, A2aClientError>

CreateTaskPushNotificationConfig — register a push notification config for a task.

Source

pub async fn get_push_notification_config( &self, request: GetTaskPushNotificationConfigRequest, ) -> Result<GetTaskPushNotificationConfigResponse, A2aClientError>

GetTaskPushNotificationConfig — read a config by id.

Source

pub async fn list_push_notification_configs( &self, request: ListTaskPushNotificationConfigsRequest, ) -> Result<ListTaskPushNotificationConfigsResponse, A2aClientError>

ListTaskPushNotificationConfigs — list a task’s configs.

Source

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.

Source

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

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for A2aClient

Source§

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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