pub struct M;Expand description
The M namespace — static factory methods for middleware.
Implementations§
Source§impl M
impl M
Sourcepub fn log() -> MiddlewareComposite
pub fn log() -> MiddlewareComposite
Add logging middleware.
Sourcepub fn latency() -> MiddlewareComposite
pub fn latency() -> MiddlewareComposite
Add latency tracking middleware.
Sourcepub fn timeout(duration: Duration) -> MiddlewareComposite
pub fn timeout(duration: Duration) -> MiddlewareComposite
Bound the agent run to duration. The text agent enforces the tightest
timeout across its middleware chain by wrapping the whole run; on elapse
it emits AgentEvent::Timeout and returns an error.
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 after_tool(
f: impl Fn(&FunctionCall, &Value) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn after_tool( f: impl Fn(&FunctionCall, &Value) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Add a custom after-tool hook — called after every successful tool invocation.
Sourcepub fn on_error(
f: impl Fn(&AgentError) -> Result<(), String> + Send + Sync + 'static,
) -> MiddlewareComposite
pub fn on_error( f: impl Fn(&AgentError) -> Result<(), String> + Send + Sync + 'static, ) -> MiddlewareComposite
Add a custom error observer — called when an agent-level error occurs.
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 — spaces tool calls to at most rps per
second by delaying before_tool (concurrent calls queue rather than
burst).
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 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 cache() -> MiddlewareComposite
pub fn cache() -> MiddlewareComposite
Response caching middleware — caches model responses to avoid redundant calls.
Sourcepub fn dedup() -> MiddlewareComposite
pub fn dedup() -> MiddlewareComposite
Deduplicate consecutive identical requests.
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.
Sourcepub fn on_route(f: impl Fn(&str) + Send + Sync + 'static) -> MiddlewareComposite
pub fn on_route(f: impl Fn(&str) + Send + Sync + 'static) -> MiddlewareComposite
Route decision event hook — called when a route agent selects a branch.
Sourcepub fn on_fallback(
f: impl Fn(&str) + Send + Sync + 'static,
) -> MiddlewareComposite
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 UnsafeUnpin for M
impl UnwindSafe for M
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Conv for T
impl<T> Conv for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.