pub struct RequestHandlerBuilder { /* private fields */ }Expand description
Fluent builder for RequestHandler.
§Required
executor: AnyAgentExecutorimplementation (passed as a concrete type; the builder erases it toArc<dyn AgentExecutor>duringbuild).
§Optional (with defaults)
task_store: defaults toInMemoryTaskStore.push_config_store: defaults toInMemoryPushConfigStore.push_sender: defaults toNone.interceptors: defaults to an empty chain.agent_card: defaults toNone.tenant_resolver: defaults toNone(no tenant resolution).tenant_config: defaults toNone(no per-tenant limits).
Implementations§
Source§impl RequestHandlerBuilder
impl RequestHandlerBuilder
Sourcepub fn new(executor: impl AgentExecutor) -> RequestHandlerBuilder
pub fn new(executor: impl AgentExecutor) -> RequestHandlerBuilder
Creates a new builder with the given executor.
The executor is type-erased to Arc<dyn AgentExecutor>.
Sourcepub fn with_task_store(
self,
store: impl TaskStore + 'static,
) -> RequestHandlerBuilder
pub fn with_task_store( self, store: impl TaskStore + 'static, ) -> RequestHandlerBuilder
Sets a custom task store.
Sourcepub fn with_task_store_arc(
self,
store: Arc<dyn TaskStore>,
) -> RequestHandlerBuilder
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.
Sourcepub fn with_task_store_config(
self,
config: TaskStoreConfig,
) -> RequestHandlerBuilder
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.
Sourcepub fn with_push_config_store(
self,
store: impl PushConfigStore + 'static,
) -> RequestHandlerBuilder
pub fn with_push_config_store( self, store: impl PushConfigStore + 'static, ) -> RequestHandlerBuilder
Sets a custom push configuration store.
Sourcepub fn with_push_sender(
self,
sender: impl PushSender + 'static,
) -> RequestHandlerBuilder
pub fn with_push_sender( self, sender: impl PushSender + 'static, ) -> RequestHandlerBuilder
Sets a push notification sender.
Sourcepub fn with_interceptor(
self,
interceptor: impl ServerInterceptor + 'static,
) -> RequestHandlerBuilder
pub fn with_interceptor( self, interceptor: impl ServerInterceptor + 'static, ) -> RequestHandlerBuilder
Adds a server interceptor to the chain.
Sourcepub const fn with_executor_timeout(
self,
timeout: Duration,
) -> RequestHandlerBuilder
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.
Sourcepub fn with_agent_card(self, card: AgentCard) -> RequestHandlerBuilder
pub fn with_agent_card(self, card: AgentCard) -> RequestHandlerBuilder
Sets the agent card for discovery responses.
Sourcepub const fn with_event_queue_capacity(
self,
capacity: usize,
) -> RequestHandlerBuilder
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.
Sourcepub const fn with_max_event_size(
self,
max_event_size: usize,
) -> RequestHandlerBuilder
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.
Sourcepub const fn with_max_concurrent_streams(
self,
max: usize,
) -> RequestHandlerBuilder
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.
Sourcepub const fn with_event_queue_write_timeout(
self,
timeout: Duration,
) -> RequestHandlerBuilder
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.
Sourcepub const fn with_handler_limits(
self,
limits: HandlerLimits,
) -> RequestHandlerBuilder
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().
Sourcepub fn with_metrics(
self,
metrics: impl Metrics + 'static,
) -> RequestHandlerBuilder
pub fn with_metrics( self, metrics: impl Metrics + 'static, ) -> RequestHandlerBuilder
Sets a metrics observer for handler activity.
Defaults to NoopMetrics which discards all events.
Sourcepub fn with_tenant_resolver(
self,
resolver: impl TenantResolver,
) -> RequestHandlerBuilder
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).
Sourcepub fn with_tenant_config(
self,
config: PerTenantConfig,
) -> RequestHandlerBuilder
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).
Sourcepub fn build(self) -> Result<RequestHandler, ServerError>
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§
Auto Trait Implementations§
impl Freeze for RequestHandlerBuilder
impl !RefUnwindSafe for RequestHandlerBuilder
impl Send for RequestHandlerBuilder
impl Sync for RequestHandlerBuilder
impl Unpin for RequestHandlerBuilder
impl UnsafeUnpin for RequestHandlerBuilder
impl !UnwindSafe for RequestHandlerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request