Expand description
Lifecycle hooks for the agent loop.
Hooks are callbacks invoked at well-defined points during an agent run. They allow consumers to observe, log, gate, or transform behaviour without modifying the agent loop itself.
§Hook points
SessionStart— at the top ofAgent::run(), before any LLM call.PreToolCall— before each tool dispatch (after the permission hook).PostToolCall— after each tool returns.PreCompact— before compaction fires.PostCompact— after compaction completes.SessionEnd— just before returning fromAgent::run().
§Usage
ⓘ
use recursive::hooks::{Hook, HookEvent, HookAction, HookRegistry};
struct MyHook;
impl Hook for MyHook {
fn on_event(&self, event: HookEvent) -> HookAction {
match event {
HookEvent::PreToolCall { name, .. } => {
eprintln!("about to call {name}");
HookAction::Continue
}
_ => HookAction::Continue,
}
}
}
let mut registry = HookRegistry::new();
registry.register(Arc::new(MyHook));Structs§
- Hook
Registry - A registry of hooks that dispatches events to all registered hooks in order.
- Tool
Timing Hook - A hook that prints tool call timing information to stderr.
Enums§
- Hook
Action - Action a hook can request in response to an event.
- Hook
Event - Events emitted at lifecycle points during an agent run.
Traits§
- Hook
- A lifecycle hook that can observe and influence agent behaviour.