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).max_concurrent_streams: defaults toDEFAULT_MAX_CONCURRENT_STREAMS(1024).executor_timeout: defaults toNone(unbounded — recommended to set explicitly; seewith_executor_timeout).
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.
There is deliberately no default: any fixed value would silently mark legitimately long-running agent tasks as failed. Production deployments should set a timeout matched to their workload so a hung executor cannot pin a task (and its stream resources) forever.
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 DEFAULT_QUEUE_CAPACITY (256 items). Higher values allow
more events to be buffered before backpressure is applied. Lower values
reduce memory footprint at the cost of earlier slow-consumer stalls.
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. Defaults to
DEFAULT_MAX_CONCURRENT_STREAMS (1024); pass usize::MAX to
effectively disable the ceiling.
Sourcepub const fn with_event_queue_write_timeout(
self,
timeout: Duration,
) -> RequestHandlerBuilder
👎Deprecated since 0.7.0: has no effect: event queue writes never block; slow consumers receive an explicit lag error instead. Will be removed in 0.8.
pub const fn with_event_queue_write_timeout( self, timeout: Duration, ) -> RequestHandlerBuilder
has no effect: event queue writes never block; slow consumers receive an explicit lag error instead. Will be removed in 0.8.
Sets the write timeout for event queue sends.
Retained for API compatibility only. Event queue writes never block (the broadcast channel is non-blocking), so this value has no effect; a slow streaming consumer receives an explicit lag error on its reader instead of exerting backpressure on the executor.
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 const fn require_resolved_tenant(self) -> RequestHandlerBuilder
pub const fn require_resolved_tenant(self) -> RequestHandlerBuilder
Enables strict multi-tenancy: reject any request for which a configured
with_tenant_resolver returns None
(no tenant could be determined) instead of falling back to the shared
default ("") partition.
Use this when every request must carry an identifiable tenant — it closes the gap where header-less or unauthenticated callers would otherwise all share one default bucket. Has no effect unless a resolver is configured.
Defaults to false (the resolver’s documented None → default-partition
behavior is preserved).
Sourcepub const fn allow_unauthenticated_extended_card(self) -> RequestHandlerBuilder
pub const fn allow_unauthenticated_extended_card(self) -> RequestHandlerBuilder
Serves GetExtendedAgentCard even when no authenticating interceptor
is registered.
Spec §13.3 requires the extended card endpoint to be authenticated, so
by default a handler whose card declares
capabilities.extendedAgentCard: true refuses to serve the card
unless the interceptor chain contains at least one interceptor whose
authenticates()
returns true. Call this only when the extended card genuinely
contains nothing sensitive (e.g. it is identical to the public card)
or authentication is enforced upstream of this process (API gateway,
service mesh, mTLS sidecar).
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 !RefUnwindSafe for RequestHandlerBuilder
impl !UnwindSafe for RequestHandlerBuilder
impl Freeze for RequestHandlerBuilder
impl Send for RequestHandlerBuilder
impl Sync for RequestHandlerBuilder
impl Unpin for RequestHandlerBuilder
impl UnsafeUnpin 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