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, _agent: &str, _prompt: &mut String) { ... }
fn on_before_run(&self, _agent: &str, _history: &[Message]) -> Vec<Message> { ... }
fn on_after_run(
&self,
_agent: &str,
_history: &[Message],
_system_prompt: &str,
) { ... }
}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, _agent: &str, _prompt: &mut String)
fn on_compact(&self, _agent: &str, _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.
Sourcefn on_before_run(&self, _agent: &str, _history: &[Message]) -> Vec<Message>
fn on_before_run(&self, _agent: &str, _history: &[Message]) -> Vec<Message>
Called by Runtime before each agent run (send_to / stream_to).
Receives the agent name and conversation history (including the latest user message). Returns messages to inject before the user message for additional context (e.g. auto-recalled memory).
Default: no injection.
Sourcefn on_after_run(&self, _agent: &str, _history: &[Message], _system_prompt: &str)
fn on_after_run(&self, _agent: &str, _history: &[Message], _system_prompt: &str)
Called by Runtime after agent execution completes (send_to / stream_to).
Receives the agent name, final conversation history, and system prompt. Synchronous — implementations that need async work should spawn their own background tasks internally.
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.