M

Struct M 

Source
pub struct M;
Expand description

The M namespace — static factory methods for middleware.

Implementations§

Source§

impl M

Source

pub fn log() -> MiddlewareComposite

Add logging middleware.

Source

pub fn latency() -> MiddlewareComposite

Add latency tracking middleware.

Source

pub fn timeout(duration: Duration) -> MiddlewareComposite

Add timeout middleware (placeholder — records the duration for use by the runtime).

Source

pub fn retry(max_retries: u32) -> MiddlewareComposite

Add retry middleware — tracks errors and advises on retry.

Source

pub fn tap( f: impl Fn(&AgentEvent) + Send + Sync + 'static, ) -> MiddlewareComposite

Add a custom event observer — called on every agent event.

Source

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.

Source

pub fn cost() -> MiddlewareComposite

Add cost tracking middleware — records token usage estimates.

Source

pub fn rate_limit(rps: u32) -> MiddlewareComposite

Add rate limiting middleware — enforces max requests per second.

Source

pub fn circuit_breaker(threshold: u32) -> MiddlewareComposite

Add circuit breaker middleware — opens after consecutive failures.

Source

pub fn trace() -> MiddlewareComposite

Add tracing span middleware — creates spans for distributed tracing.

Source

pub fn audit() -> MiddlewareComposite

Add audit middleware — records all tool calls for review.

Source

pub fn scope(names: &[&str], inner: MiddlewareComposite) -> MiddlewareComposite

Scope middleware to specific agent names.

Source

pub fn structured_log() -> MiddlewareComposite

Structured logging middleware — logs agent events as structured JSON.

Source

pub fn dispatch_log() -> MiddlewareComposite

Dispatch logging middleware — logs dispatch/join events.

Source

pub fn topology_log() -> MiddlewareComposite

Topology logging middleware — logs agent topology events.

Source

pub fn validate( f: impl Fn(&FunctionCall) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite

Add a tool input validator middleware.

Source

pub fn fallback_model(model: &str) -> MiddlewareComposite

Fallback to an alternative model on error.

Source

pub fn cache() -> MiddlewareComposite

Response caching middleware — caches model responses to avoid redundant calls.

Source

pub fn dedup() -> MiddlewareComposite

Deduplicate consecutive identical requests.

Source

pub fn sample(rate: f64) -> MiddlewareComposite

Sample/pass-through a fraction of requests (0.0–1.0).

Source

pub fn metrics() -> MiddlewareComposite

Metrics collection middleware — tracks request counts, error counts, and latencies.

Source

pub fn before_agent( f: impl Fn(&InvocationContext) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite

Shortcut for a before-agent hook.

Source

pub fn after_agent( f: impl Fn(&InvocationContext) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite

Shortcut for an after-agent hook.

Source

pub fn before_model( f: impl Fn(&LlmRequest) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite

Shortcut for a before-model hook.

Source

pub fn after_model( f: impl Fn(&LlmRequest, &LlmResponse) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite

Shortcut for an after-model hook.

Source

pub fn on_loop(f: impl Fn(u32) + Send + Sync + 'static) -> MiddlewareComposite

Loop iteration event hook — called on each iteration of a loop agent.

Source

pub fn on_timeout(f: impl Fn() + Send + Sync + 'static) -> MiddlewareComposite

Timeout event hook — called when an agent times out.

Source

pub fn on_route(f: impl Fn(&str) + Send + Sync + 'static) -> MiddlewareComposite

Route decision event hook — called when a route agent selects a branch.

Source

pub fn on_fallback( f: impl Fn(&str) + Send + Sync + 'static, ) -> MiddlewareComposite

Fallback event hook — called when a fallback agent activates.

Auto Trait Implementations§

§

impl Freeze for M

§

impl RefUnwindSafe for M

§

impl Send for M

§

impl Sync for M

§

impl Unpin for M

§

impl UnwindSafe for M

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more