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,
_elapsed: Duration,
) -> 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,
_elapsed: Duration,
) -> 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,
_elapsed: Duration,
) -> 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,
_elapsed: Duration,
) -> 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.
elapsed is the wall time spent in the inner client (including
retries when the middleware wraps a RetryClient). Use for
logging, metrics, or response tracing.
Sourcefn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_request: &'life1 LLMRequest,
_error: &'life2 KernelError,
_elapsed: Duration,
) -> 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,
_elapsed: Duration,
) -> 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.
elapsed is the wall time spent in the inner client before the
error surfaced. 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".