Expand description
RuntimeLayer trait: middleware hooks for LLM calls and tool dispatch (#2286).
Provides interception points before and after each LLM chat call and each tool execution.
Layers are composed in a stack: each layer is called in order, and any layer may
short-circuit the actual call by returning Some(result) from before_chat or before_tool.
§MVP
No layers are registered at bootstrap — the runtime_layers vec in Agent defaults to empty,
making the hook loops zero-cost (no iteration, no allocation).
Future layers (rate limiting, guardrails, cost tracking, audit logging) add themselves to the vec at bootstrap without modifying the agent loop.
§Implementation note
Default implementations return Box::pin(std::future::ready(...)). This allocates once per
call per registered layer. For the MVP empty-vec case, no allocation occurs. Real layers
should keep their work minimal to avoid blocking the agent loop.
Structs§
- Layer
Context - Context available to runtime layers during interception.
- Noop
Layer - No-op layer that passes everything through unchanged.
Traits§
- Runtime
Layer - Middleware layer that wraps LLM calls and tool dispatch.
Type Aliases§
- Before
Tool Result - Short-circuit result type for
before_tool:Some(result)bypasses tool execution.