Skip to main content

Middleware

Trait Middleware 

Source
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§

Source

fn name(&self) -> &str

Middleware identifier (for logging and ordering).

Provided Methods§

Source

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.

Source

fn tools(&self) -> Vec<Box<dyn Tool>>

Tools injected into the agent context by this middleware.

Source

fn system_prompt_additions(&self) -> Vec<String>

System prompt additions contributed by this middleware.

Additions are concatenated in stack order.

Implementors§