Skip to main content

RequestHandlerBuilder

Struct RequestHandlerBuilder 

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

Fluent builder for RequestHandler.

§Required

  • executor: Any AgentExecutor implementation (passed as a concrete type; the builder erases it to Arc<dyn AgentExecutor> during build).

§Optional (with defaults)

  • task_store: defaults to InMemoryTaskStore.
  • push_config_store: defaults to InMemoryPushConfigStore.
  • push_sender: defaults to None.
  • interceptors: defaults to an empty chain.
  • agent_card: defaults to None.
  • tenant_resolver: defaults to None (no tenant resolution).
  • tenant_config: defaults to None (no per-tenant limits).

Implementations§

Source§

impl RequestHandlerBuilder

Source

pub fn new(executor: impl AgentExecutor) -> RequestHandlerBuilder

Creates a new builder with the given executor.

The executor is type-erased to Arc<dyn AgentExecutor>.

Source

pub fn with_task_store( self, store: impl TaskStore + 'static, ) -> RequestHandlerBuilder

Sets a custom task store.

Source

pub fn with_task_store_arc( self, store: Arc<dyn TaskStore>, ) -> RequestHandlerBuilder

Sets a custom task store from an existing Arc.

Use this when you want to share a store instance across multiple handlers or access it from background tasks.

Source

pub fn with_task_store_config( self, config: TaskStoreConfig, ) -> RequestHandlerBuilder

Configures the default InMemoryTaskStore with custom TTL and capacity settings.

§Panics

Panics in debug builds if a custom task store has already been set via with_task_store, since the config would be silently ignored.

Source

pub fn with_push_config_store( self, store: impl PushConfigStore + 'static, ) -> RequestHandlerBuilder

Sets a custom push configuration store.

Source

pub fn with_push_sender( self, sender: impl PushSender + 'static, ) -> RequestHandlerBuilder

Sets a push notification sender.

Source

pub fn with_interceptor( self, interceptor: impl ServerInterceptor + 'static, ) -> RequestHandlerBuilder

Adds a server interceptor to the chain.

Source

pub const fn with_executor_timeout( self, timeout: Duration, ) -> RequestHandlerBuilder

Sets a timeout for executor execution.

If the executor does not complete within this duration, the task is marked as failed with a timeout error.

Source

pub fn with_agent_card(self, card: AgentCard) -> RequestHandlerBuilder

Sets the agent card for discovery responses.

Source

pub const fn with_event_queue_capacity( self, capacity: usize, ) -> RequestHandlerBuilder

Sets the event queue channel capacity for streaming.

Defaults to 64 items. Higher values allow more events to be buffered before backpressure is applied.

Source

pub const fn with_max_event_size( self, max_event_size: usize, ) -> RequestHandlerBuilder

Sets the maximum serialized event size in bytes.

Events exceeding this size are rejected to prevent OOM conditions. Defaults to 16 MiB.

Source

pub const fn with_max_concurrent_streams( self, max: usize, ) -> RequestHandlerBuilder

Sets the maximum number of concurrent streaming event queues.

Limits memory usage from concurrent streams. When the limit is reached, new streaming requests will fail.

Source

pub const fn with_event_queue_write_timeout( self, timeout: Duration, ) -> RequestHandlerBuilder

Sets the write timeout for event queue sends.

Prevents executors from blocking indefinitely when a client is slow or disconnected. Default: 5 seconds.

Source

pub const fn with_handler_limits( self, limits: HandlerLimits, ) -> RequestHandlerBuilder

Sets configurable limits for the handler (ID lengths, metadata size, etc.).

Defaults to HandlerLimits::default().

Source

pub fn with_metrics( self, metrics: impl Metrics + 'static, ) -> RequestHandlerBuilder

Sets a metrics observer for handler activity.

Defaults to NoopMetrics which discards all events.

Source

pub fn with_tenant_resolver( self, resolver: impl TenantResolver, ) -> RequestHandlerBuilder

Sets a tenant resolver for multi-tenant deployments.

The resolver extracts a tenant identifier from each incoming request’s CallContext. When combined with with_tenant_config, this enables per-tenant resource limits and configuration.

Defaults to None (single-tenant mode).

Source

pub fn with_tenant_config( self, config: PerTenantConfig, ) -> RequestHandlerBuilder

Sets per-tenant configuration for multi-tenant deployments.

PerTenantConfig allows differentiated service levels (timeouts, capacity limits, rate limits) per tenant. Pair with with_tenant_resolver to extract the tenant identity from incoming requests.

Defaults to None (uniform limits for all callers).

Source

pub fn build(self) -> Result<RequestHandler, ServerError>

Builds the RequestHandler.

§Errors

Returns ServerError::InvalidParams if the configuration is invalid:

  • Agent card with empty supported_interfaces
  • Zero executor timeout (would cause immediate timeouts)

Trait Implementations§

Source§

impl Debug for RequestHandlerBuilder

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