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.
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 const fn with_task_store_config(
self,
config: TaskStoreConfig,
) -> RequestHandlerBuilder
pub const fn with_task_store_config( self, config: TaskStoreConfig, ) -> RequestHandlerBuilder
Configures the default InMemoryTaskStore with custom TTL and capacity settings.
This is ignored if a custom task store is set via with_task_store.
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 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 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)