pub struct M;Expand description
The M namespace — static factory methods for middleware.
Implementations§
Source§impl M
impl M
Sourcepub fn timeout(duration: Duration) -> MiddlewareComposite
pub fn timeout(duration: Duration) -> MiddlewareComposite
Add timeout middleware (placeholder — records the duration for use by the runtime).
Sourcepub fn retry(max_retries: u32) -> MiddlewareComposite
pub fn retry(max_retries: u32) -> MiddlewareComposite
Add retry middleware — tracks errors and advises on retry.
Sourcepub fn tap(
f: impl Fn(&AgentEvent) + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn tap( f: impl Fn(&AgentEvent) + Send + Sync + 'static, ) -> MiddlewareComposite
Add a custom event observer — called on every agent event.
Sourcepub fn before_tool(
f: impl Fn(&FunctionCall) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn before_tool( f: impl Fn(&FunctionCall) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Add a custom before-tool filter — called before every tool invocation.
Sourcepub fn cost() -> MiddlewareComposite
pub fn cost() -> MiddlewareComposite
Add cost tracking middleware — records token usage estimates.
Sourcepub fn rate_limit(rps: u32) -> MiddlewareComposite
pub fn rate_limit(rps: u32) -> MiddlewareComposite
Add rate limiting middleware — enforces max requests per second.
Sourcepub fn circuit_breaker(threshold: u32) -> MiddlewareComposite
pub fn circuit_breaker(threshold: u32) -> MiddlewareComposite
Add circuit breaker middleware — opens after consecutive failures.
Sourcepub fn trace() -> MiddlewareComposite
pub fn trace() -> MiddlewareComposite
Add tracing span middleware — creates spans for distributed tracing.
Sourcepub fn audit() -> MiddlewareComposite
pub fn audit() -> MiddlewareComposite
Add audit middleware — records all tool calls for review.
Sourcepub fn scope(names: &[&str], inner: MiddlewareComposite) -> MiddlewareComposite
pub fn scope(names: &[&str], inner: MiddlewareComposite) -> MiddlewareComposite
Scope middleware to specific agent names.
Sourcepub fn structured_log() -> MiddlewareComposite
pub fn structured_log() -> MiddlewareComposite
Structured logging middleware — logs agent events as structured JSON.
Sourcepub fn dispatch_log() -> MiddlewareComposite
pub fn dispatch_log() -> MiddlewareComposite
Dispatch logging middleware — logs dispatch/join events.
Sourcepub fn topology_log() -> MiddlewareComposite
pub fn topology_log() -> MiddlewareComposite
Topology logging middleware — logs agent topology events.
Sourcepub fn validate(
f: impl Fn(&FunctionCall) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn validate( f: impl Fn(&FunctionCall) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Add a tool input validator middleware.
Sourcepub fn fallback_model(model: &str) -> MiddlewareComposite
pub fn fallback_model(model: &str) -> MiddlewareComposite
Fallback to an alternative model on error.
Sourcepub fn cache() -> MiddlewareComposite
pub fn cache() -> MiddlewareComposite
Response caching middleware — caches model responses to avoid redundant calls.
Sourcepub fn sample(rate: f64) -> MiddlewareComposite
pub fn sample(rate: f64) -> MiddlewareComposite
Sample/pass-through a fraction of requests (0.0–1.0).
Sourcepub fn metrics() -> MiddlewareComposite
pub fn metrics() -> MiddlewareComposite
Metrics collection middleware — tracks request counts, error counts, and latencies.
Sourcepub fn before_agent(
f: impl Fn(&InvocationContext) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn before_agent( f: impl Fn(&InvocationContext) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Shortcut for a before-agent hook.
Sourcepub fn after_agent(
f: impl Fn(&InvocationContext) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn after_agent( f: impl Fn(&InvocationContext) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Shortcut for an after-agent hook.
Sourcepub fn before_model(
f: impl Fn(&LlmRequest) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn before_model( f: impl Fn(&LlmRequest) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Shortcut for a before-model hook.
Sourcepub fn after_model(
f: impl Fn(&LlmRequest, &LlmResponse) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn after_model( f: impl Fn(&LlmRequest, &LlmResponse) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Shortcut for an after-model hook.
Sourcepub fn on_loop(f: impl Fn(u32) + Send + Sync + 'static) -> MiddlewareComposite
pub fn on_loop(f: impl Fn(u32) + Send + Sync + 'static) -> MiddlewareComposite
Loop iteration event hook — called on each iteration of a loop agent.
Sourcepub fn on_timeout(f: impl Fn() + Send + Sync + 'static) -> MiddlewareComposite
pub fn on_timeout(f: impl Fn() + Send + Sync + 'static) -> MiddlewareComposite
Timeout event hook — called when an agent times out.