Skip to main content

RequestHandler

Struct RequestHandler 

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

The core protocol logic handler.

Orchestrates task lifecycle, event streaming, push notifications, and interceptor chains for all A2A methods.

RequestHandler is not generic — it stores the executor as Arc<dyn AgentExecutor>, enabling dynamic dispatch and simplifying the downstream API (dispatchers, builder, etc.).

§Store ownership

Stores are held as Arc<dyn TaskStore> / Arc<dyn PushConfigStore> rather than Box<dyn ...> so that they can be cheaply cloned into background tasks (e.g. the streaming push-delivery processor).

Implementations§

Source§

impl RequestHandler

Source

pub async fn on_cancel_task( &self, params: CancelTaskParams, headers: Option<&HashMap<String, String>>, ) -> Result<Task, ServerError>

Handles CancelTask.

§Errors

Returns ServerError::TaskNotFound or ServerError::TaskNotCancelable.

Source§

impl RequestHandler

Source

pub async fn on_get_extended_agent_card( &self, headers: Option<&HashMap<String, String>>, ) -> Result<AgentCard, ServerError>

Handles GetExtendedAgentCard.

§Errors

Returns ServerError::Internal if no agent card is configured.

Source§

impl RequestHandler

Source

pub async fn on_get_task( &self, params: TaskQueryParams, headers: Option<&HashMap<String, String>>, ) -> Result<Task, ServerError>

Handles GetTask. Returns ServerError::TaskNotFound if missing.

§Errors

Returns ServerError::TaskNotFound if the task does not exist.

Source§

impl RequestHandler

Source

pub async fn on_list_tasks( &self, params: ListTasksParams, headers: Option<&HashMap<String, String>>, ) -> Result<TaskListResponse, ServerError>

Handles ListTasks.

§Errors

Returns a ServerError if the store query fails.

Source§

impl RequestHandler

Source

pub async fn on_resubscribe( &self, params: TaskIdParams, headers: Option<&HashMap<String, String>>, ) -> Result<InMemoryQueueReader, ServerError>

Handles SubscribeToTask.

§Errors

Returns ServerError::TaskNotFound if the task does not exist.

Source§

impl RequestHandler

Source

pub async fn on_send_message( &self, params: MessageSendParams, streaming: bool, headers: Option<&HashMap<String, String>>, ) -> Result<SendMessageResult, ServerError>

Handles SendMessage / SendStreamingMessage.

The optional headers map carries HTTP request headers for interceptor access-control decisions (e.g. Authorization).

§Errors

Returns ServerError if task creation or execution fails.

Source§

impl RequestHandler

Source

pub async fn on_set_push_config( &self, config: TaskPushNotificationConfig, headers: Option<&HashMap<String, String>>, ) -> Result<TaskPushNotificationConfig, ServerError>

Handles CreateTaskPushNotificationConfig.

§Errors

Returns ServerError::PushNotSupported if no push sender is configured.

Source

pub async fn on_get_push_config( &self, params: GetPushConfigParams, headers: Option<&HashMap<String, String>>, ) -> Result<TaskPushNotificationConfig, ServerError>

Handles GetTaskPushNotificationConfig.

§Errors

Returns ServerError::InvalidParams if the config is not found.

Source

pub async fn on_list_push_configs( &self, task_id: &str, tenant: Option<&str>, headers: Option<&HashMap<String, String>>, ) -> Result<Vec<TaskPushNotificationConfig>, ServerError>

Handles ListTaskPushNotificationConfigs.

§Errors

Returns a ServerError if the store query fails.

Source

pub async fn on_delete_push_config( &self, params: DeletePushConfigParams, headers: Option<&HashMap<String, String>>, ) -> Result<(), ServerError>

Handles DeleteTaskPushNotificationConfig.

§Errors

Returns a ServerError if the delete operation fails.

Source§

impl RequestHandler

Source

pub async fn shutdown(&self)

Initiates graceful shutdown of the handler.

This method:

  1. Cancels all in-flight tasks by signalling their cancellation tokens.
  2. Destroys all event queues, causing readers to see EOF.

After calling shutdown(), new requests will still be accepted but in-flight tasks will observe cancellation. The caller should stop accepting new connections after calling this method.

Source

pub async fn shutdown_with_timeout(&self, timeout: Duration)

Initiates graceful shutdown with a timeout.

Cancels all in-flight tasks and waits up to timeout for event queues to drain before force-destroying them. This gives executors a chance to finish writing final events before the queues are torn down.

Source§

impl RequestHandler

Source

pub fn tenant_resolver(&self) -> Option<&(dyn TenantResolver + 'static)>

Returns the tenant resolver, if configured.

Use this in dispatchers or middleware to resolve the tenant identity from a CallContext before processing a request.

Source

pub const fn tenant_config(&self) -> Option<&PerTenantConfig>

Returns the per-tenant configuration, if configured.

Use this alongside tenant_resolver to look up resource limits for the resolved tenant.

Trait Implementations§

Source§

impl Debug for RequestHandler

Source§

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

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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