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
impl A2AServer
Sourcepub fn from_agent(executor: Arc<AgentExecutor>) -> Self
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.
Sourcepub fn with_store(self, store: Arc<dyn TaskStore>) -> Self
pub fn with_store(self, store: Arc<dyn TaskStore>) -> Self
Replace the default in-memory task store with a custom backend (P1-1).
Sourcepub fn with_max_tasks(self, max: usize) -> Self
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.
Sourcepub fn with_skill_router(self, router: Arc<dyn SkillRouter>) -> Self
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).
Sourcepub fn with_skill_map(self, map: SkillMapRouter) -> Self
pub fn with_skill_map(self, map: SkillMapRouter) -> Self
Attach a default skill router built from a static skill_id -> chain
map (P2-4).
Sourcepub fn with_streaming(self, capacity: usize) -> Self
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.
Sourcepub fn subscribe(&self) -> Option<Receiver<TaskPushNotification>>
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.
Sourcepub fn with_auth_token(self, token: impl Into<String>) -> Self
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.
Sourcepub fn with_rate_limiter(self, limiter: Arc<RateLimiter>) -> Self
pub fn with_rate_limiter(self, limiter: Arc<RateLimiter>) -> Self
Attach a rate limiter applied to every incoming request.
Sourcepub fn with_task_ttl(self, ttl: Option<Duration>) -> Self
pub fn with_task_ttl(self, ttl: Option<Duration>) -> Self
Set the task time-to-live before expiry cleanup (None disables expiry).
Sourcepub fn with_background_cleanup(self, interval: Duration) -> Self
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.
Sourcepub fn get_agent_card(&self) -> &AgentCard
pub fn get_agent_card(&self) -> &AgentCard
Get the agent card (for GET /.well-known/agent-card.json).
Sourcepub async fn handle_a2a_request(&self, req: A2ARequest) -> A2AResponse
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 tasktasks/cancel-> cancel a stored tasktasks/list-> list stored tasks- unknown method -> method_not_found error
Sourcepub async fn handle_a2a_request_authenticated(
&self,
req: A2ARequest,
bearer: Option<&str>,
) -> A2AResponse
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.