Expand description
M — Middleware composition.
Compose middleware in any order with |.
§Wiring status
TextAgent pipelines (via AgentBuilder::middleware + AgentBuilder::build) —
fully wired. Every factory in this module produces a MiddlewareComposite
whose layers are installed into the LlmTextAgent middleware chain at compile
time. Hooks fire in this order per run() call:
before_model(forward order) — may short-circuit with a cached response.- LLM call (skipped if
before_modelreturnedSome). after_model(reverse order) — may replace the LLM response.before_tool(forward) /after_tool(reverse) /on_tool_error(forward) — called for each tool dispatch round.on_error(forward) — called once ifrun()returns an error.
Live sessions (via Live::middleware) — the tool-lifecycle hooks
are wired: before_tool (a returned error vetoes the call), after_tool,
and on_tool_error fire around every tool dispatch in the control lane,
including background tools. Model-level hooks (before_model/after_model)
do not apply to Live — a Live session streams over the wire and has no
discrete LlmRequest/LlmResponse to intercept; use them on TextAgent
pipelines instead.
Structs§
- Audit
Entry - An audit log entry.
- Audit
Middleware - Records all tool calls for audit review.
- Cache
Middleware - Caches model responses keyed by request hash to avoid redundant LLM calls.
- Cost
Middleware - Tracks the number of tool calls as a proxy for cost.
- M
- The
Mnamespace — static factory methods for middleware. - Metrics
Middleware - Collects request and error counts.
- Middleware
Composite - A middleware composite — one or more middleware layers (
M::a() | M::b()).