Skip to main content

A2AServer

Struct A2AServer 

Source
pub struct A2AServer { /* private fields */ }
Expand description

A2A Server - wraps an agent and provides handler functions.

The server does NOT start its own HTTP listener. Instead, it provides handle_a2a_request() and get_agent_card() that you can call from any HTTP framework’s route handler.

Tasks are stored through the TaskStore trait so that tasks/get can retrieve them and tasks/cancel can transition their status. When the default in-memory store exceeds its capacity, the least recently updated task is evicted (LRU).

Implementations§

Source§

impl A2AServer

Source

pub fn new(chain: Arc<dyn BaseChain>) -> Self

Create a new A2A server backed by a BaseChain.

Source

pub fn from_agent(executor: Arc<AgentExecutor>) -> Self

Create a server backed directly by a stateful agent (P1-8).

The AgentExecutor is adapted to the chain interface, so A2A tasks get genuine conversational continuity. Attach memory to the executor (.with_memory(...)) before wrapping for multi-turn state.

Source

pub fn with_store(self, store: Arc<dyn TaskStore>) -> Self

Replace the default in-memory task store with a custom backend (P1-1).

Source

pub fn with_max_tasks(self, max: usize) -> Self

Set the maximum number of tasks before LRU eviction.

Replaces the store with a fresh in-memory store of the given capacity, discarding any tasks stored so far. Call this before sending tasks.

Source

pub fn with_skill_router(self, router: Arc<dyn SkillRouter>) -> Self

Attach a skill router so tasks/send requests with a skillId are dispatched to a different chain (P2-4).

Source

pub fn with_skill_map(self, map: SkillMapRouter) -> Self

Attach a default skill router built from a static skill_id -> chain map (P2-4).

Source

pub fn with_streaming(self, capacity: usize) -> Self

Enable streaming push notifications over an SSE-compatible channel (P2-1).

Creates a broadcast channel with the given capacity and advertises {"sse": true} on the agent card. Subscribe with A2AServer::subscribe.

Source

pub fn subscribe(&self) -> Option<Receiver<TaskPushNotification>>

Subscribe to task push notifications, if streaming is enabled (P2-1).

Returns None when the server was not built with A2AServer::with_streaming.

Source

pub fn with_auth_token(self, token: impl Into<String>) -> Self

Require a bearer token on every request.

Enables authentication on the server and advertises bearer as a supported scheme on the agent card. Requests without a matching Authorization: Bearer <token> header are rejected with a 401.

Source

pub fn with_rate_limiter(self, limiter: Arc<RateLimiter>) -> Self

Attach a rate limiter applied to every incoming request.

Source

pub fn with_task_ttl(self, ttl: Option<Duration>) -> Self

Set the task time-to-live before expiry cleanup (None disables expiry).

Source

pub fn with_background_cleanup(self, interval: Duration) -> Self

Spawn a background sweeper that periodically scans for expired tasks (P1-2), in addition to the lazy cleanup on the read paths.

The loop calls sweep_expired_tasks every interval (clamped to at least 1s). It runs until the current Tokio runtime shuts down. If the server has no TTL configured (with_task_ttl(None)), no task is spawned — there is nothing to expire.

Source

pub fn with_card(self, card: AgentCard) -> Self

Set a custom agent card.

Source

pub fn get_agent_card(&self) -> &AgentCard

Get the agent card (for GET /.well-known/agent-card.json).

Source

pub async fn handle_a2a_request(&self, req: A2ARequest) -> A2AResponse

Handle an incoming A2A request (for POST /).

Applies the optional rate limiter, then dispatches based on the request method:

  • tasks/send -> acknowledge a new async task (or continue one)
  • tasks/get -> return a stored task
  • tasks/cancel -> cancel a stored task
  • tasks/list -> list stored tasks
  • unknown method -> method_not_found error
Source

pub async fn handle_a2a_request_authenticated( &self, req: A2ARequest, bearer: Option<&str>, ) -> A2AResponse

Handle an incoming request with an optional bearer token.

If the server was configured with A2AServer::with_auth_token, requests without a matching bearer token are rejected with a 401.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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<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