Skip to main content

Hook

Trait Hook 

Source
pub trait Hook: Send + Sync {
    // Provided methods
    fn schema(&self) -> Vec<Tool> { ... }
    fn system_prompt(&self) -> Option<String> { ... }
    fn on_build_agent(&self, config: AgentConfig) -> AgentConfig { ... }
    fn on_before_run(
        &self,
        _agent: &str,
        _conversation_id: u64,
        _history: &[HistoryEntry],
    ) -> Vec<HistoryEntry> { ... }
    fn on_event(&self, _agent: &str, _conversation_id: u64, _event: &AgentEvent) { ... }
    fn preprocess(&self, _agent: &str, _content: &str) -> Option<String> { ... }
    fn scoped_tools(
        &self,
        _config: &AgentConfig,
    ) -> (Vec<String>, Option<String>) { ... }
    fn dispatch<'a>(
        &'a self,
        _name: &'a str,
        _call: ToolDispatch,
    ) -> Option<ToolFuture<'a>> { ... }
}
Expand description

A pluggable subsystem that participates in the agent lifecycle.

All methods have default no-op implementations so subsystems only override what they need.

Provided Methods§

Source

fn schema(&self) -> Vec<Tool>

Tool schemas this hook provides.

Source

fn system_prompt(&self) -> Option<String>

System prompt fragment appended to agent configs at build time.

Source

fn on_build_agent(&self, config: AgentConfig) -> AgentConfig

Called by Runtime::add_agent() before building the Agent.

Source

fn on_before_run( &self, _agent: &str, _conversation_id: u64, _history: &[HistoryEntry], ) -> Vec<HistoryEntry>

Inject context entries before each agent run.

Source

fn on_event(&self, _agent: &str, _conversation_id: u64, _event: &AgentEvent)

Called by Runtime after each agent step during execution.

Source

fn preprocess(&self, _agent: &str, _content: &str) -> Option<String>

Preprocess user content before it becomes a message. Return Some(modified) to transform, None to pass through.

Source

fn scoped_tools(&self, _config: &AgentConfig) -> (Vec<String>, Option<String>)

Tools to include when building a scoped agent’s whitelist, plus an optional scope prompt line (e.g. "skills: foo, bar").

Default: include all tools from schema() unconditionally, no scope line. Override to gate inclusion on agent config fields.

Source

fn dispatch<'a>( &'a self, _name: &'a str, _call: ToolDispatch, ) -> Option<ToolFuture<'a>>

Dispatch a tool call by name. Return None if this hook doesn’t own the tool — Env will try the next hook or the legacy entries.

Implementations on Foreign Types§

Source§

impl Hook for ()

No-op Hook for tests.

Implementors§