pub trait Hook: Send + Sync {
// Provided methods
fn on_build_agent(&self, config: AgentConfig) -> AgentConfig { ... }
fn on_event(&self, _agent: &str, _event: &AgentEvent) { ... }
fn on_register_tools(
&self,
_tools: &mut ToolRegistry,
) -> impl Future<Output = ()> + Send { ... }
fn on_compact(&self, _prompt: &mut String) { ... }
}Expand description
Lifecycle backend for agent building, event observation, and tool registration.
Default implementations are no-ops so implementors only override what they need.
Provided Methods§
Sourcefn on_build_agent(&self, config: AgentConfig) -> AgentConfig
fn on_build_agent(&self, config: AgentConfig) -> AgentConfig
Called by Runtime::add_agent() before building the Agent.
Enriches the agent config: appends skill instructions, injects memory
into the system prompt, etc. The returned config is passed to AgentBuilder.
Default: returns config unchanged.
Sourcefn on_event(&self, _agent: &str, _event: &AgentEvent)
fn on_event(&self, _agent: &str, _event: &AgentEvent)
Called by Runtime after each agent step during execution.
Receives every AgentEvent produced during send_to and stream_to.
Use for logging, metrics, persistence, or forwarding.
Default: no-op.
Sourcefn on_register_tools(
&self,
_tools: &mut ToolRegistry,
) -> impl Future<Output = ()> + Send
fn on_register_tools( &self, _tools: &mut ToolRegistry, ) -> impl Future<Output = ()> + Send
Called by Runtime::new() to register tool schemas into the registry.
Implementations call tools.insert(tool) with schema-only Tool values.
No handlers or closures are stored — dispatch is handled by the daemon.
Default: no-op async.
Sourcefn on_compact(&self, _prompt: &mut String)
fn on_compact(&self, _prompt: &mut String)
Called during context compaction to enrich the compaction prompt.
Hooks append memory context (profile facts, recent entries) to the
prompt before the LLM summarizes the conversation. The runtime passes
the base prompt from compact.md; hooks mutate it in place.
Default: no-op.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.