Skip to main content

Hook

Trait Hook 

Source
pub trait Hook: Send + Sync {
    type Model: Model + Send + Sync;

    // Required methods
    fn model(&self) -> &Self::Model;
    fn tools(&self, agent: &str) -> Vec<Tool>;
    fn dispatch(
        &self,
        agent: &str,
        calls: &[(&str, &str)],
    ) -> impl Future<Output = Vec<Result<String>>> + Send;

    // Provided methods
    fn enrich_prompt(&self, config: &AgentConfig) -> String { ... }
    fn on_event(&self, _event: &AgentEvent) { ... }
}
Expand description

Stateful runtime backend.

Owns the model provider, tool registry, skill registry, MCP bridge, and any other backend state. Runtime holds Arc<H> and delegates through these methods.

Required Associated Types§

Source

type Model: Model + Send + Sync

The model provider for this hook.

Required Methods§

Source

fn model(&self) -> &Self::Model

Access the model provider.

Source

fn tools(&self, agent: &str) -> Vec<Tool>

Return tool schemas available to the named agent.

Source

fn dispatch( &self, agent: &str, calls: &[(&str, &str)], ) -> impl Future<Output = Vec<Result<String>>> + Send

Dispatch tool calls for the named agent.

Each entry in calls is (method_name, params_json). Returns one result per call in the same order.

Provided Methods§

Source

fn enrich_prompt(&self, config: &AgentConfig) -> String

Build an enriched system prompt for the given agent config.

Default implementation returns the config’s system prompt unchanged. Override to inject skills, MCP context, or other prompt augmentation.

Source

fn on_event(&self, _event: &AgentEvent)

Called when an agent emits an event during execution.

Default is a 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.

Implementations on Foreign Types§

Source§

impl Hook for ()

Source§

type Model = ()

Source§

fn model(&self) -> &()

Source§

fn tools(&self, _agent: &str) -> Vec<Tool>

Source§

fn dispatch( &self, _agent: &str, calls: &[(&str, &str)], ) -> impl Future<Output = Vec<Result<String>>> + Send

Implementors§