pub trait LLMClientMiddleware: Send + Sync {
// Provided methods
fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_response: &'life2 LLMResponse,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_error: &'life2 KernelError,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Hook trait for intercepting LLMClient request/response cycles.
All methods have default no-op implementations. Override only the hooks you need. Each hook receives an immutable reference, so middleware cannot mutate requests or responses — only observe.
The trait is object-safe: Box<dyn LLMClientMiddleware> is usable.
Provided Methods§
Sourcefn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called before each complete request is sent.
Use for logging, metrics, or request tracing.
Sourcefn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_response: &'life2 LLMResponse,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_response: &'life2 LLMResponse,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called after a successful complete response.
Use for logging, metrics, or response tracing.
Sourcefn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_error: &'life2 KernelError,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_error: &'life2 KernelError,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when complete returns an error.
Use for error logging, alerting, or metrics.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".