pub trait Middleware: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn process(
&self,
input: MiddlewareInput,
) -> BoxFuture<'_, Result<MiddlewareResult, AgentError>> { ... }
fn tools(&self) -> Vec<Box<dyn Tool>> { ... }
fn system_prompt_additions(&self) -> Vec<String> { ... }
}Expand description
Cross-cutting concern injected into the agent loop.
Required Methods§
Provided Methods§
Sourcefn process(
&self,
input: MiddlewareInput,
) -> BoxFuture<'_, Result<MiddlewareResult, AgentError>>
fn process( &self, input: MiddlewareInput, ) -> BoxFuture<'_, Result<MiddlewareResult, AgentError>>
Process the input and optionally call through to the next layer.
The default implementation calls next unchanged.
Sourcefn tools(&self) -> Vec<Box<dyn Tool>>
fn tools(&self) -> Vec<Box<dyn Tool>>
Tools injected into the agent context by this middleware.
Sourcefn system_prompt_additions(&self) -> Vec<String>
fn system_prompt_additions(&self) -> Vec<String>
System prompt additions contributed by this middleware.
Additions are concatenated in stack order.