AgentHooks

Trait AgentHooks 

Source
pub trait AgentHooks:
    AgentDeriveT
    + Send
    + Sync {
    // Provided methods
    fn on_agent_create<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_run_start<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _task: &'life1 Task,
        _ctx: &'life2 Context,
    ) -> Pin<Box<dyn Future<Output = HookOutcome> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_run_complete<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _task: &'life1 Task,
        _result: &'life2 Self::Output,
        _ctx: &'life3 Context,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_turn_start<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _turn_index: usize,
        _ctx: &'life1 Context,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_turn_complete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _turn_index: usize,
        _ctx: &'life1 Context,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_tool_call<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _tool_call: &'life1 ToolCall,
        _ctx: &'life2 Context,
    ) -> Pin<Box<dyn Future<Output = HookOutcome> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_tool_start<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _tool_call: &'life1 ToolCall,
        _ctx: &'life2 Context,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_tool_result<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _tool_call: &'life1 ToolCall,
        _result: &'life2 ToolCallResult,
        _ctx: &'life3 Context,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn on_tool_error<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _tool_call: &'life1 ToolCall,
        _err: Value,
        _ctx: &'life2 Context,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_agent_shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}

Provided Methods§

Source

fn on_agent_create<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Hook called when builder creates a new instance of BaseAgent

Source

fn on_run_start<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _task: &'life1 Task, _ctx: &'life2 Context, ) -> Pin<Box<dyn Future<Output = HookOutcome> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when the Agent Execution is Triggered, Ability to Abort is Given for users

Source

fn on_run_complete<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _task: &'life1 Task, _result: &'life2 Self::Output, _ctx: &'life3 Context, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Called when the Agent Execution is Completed

Source

fn on_turn_start<'life0, 'life1, 'async_trait>( &'life0 self, _turn_index: usize, _ctx: &'life1 Context, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when an executor turn is started, useful for multi-turn Executors like ReAct

Source

fn on_turn_complete<'life0, 'life1, 'async_trait>( &'life0 self, _turn_index: usize, _ctx: &'life1 Context, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called when an executor turn is completed, useful for multi-turn Executors like ReAct

Source

fn on_tool_call<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _tool_call: &'life1 ToolCall, _ctx: &'life2 Context, ) -> Pin<Box<dyn Future<Output = HookOutcome> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn on_tool_start<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _tool_call: &'life1 ToolCall, _ctx: &'life2 Context, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called before executing the tool

Source

fn on_tool_result<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _tool_call: &'life1 ToolCall, _result: &'life2 ToolCallResult, _ctx: &'life3 Context, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Called post execution of tool with results

Source

fn on_tool_error<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _tool_call: &'life1 ToolCall, _err: Value, _ctx: &'life2 Context, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called if the execution of the tool failed

Source

fn on_agent_shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when an Actor Agent post-shutdown, This has no effect on DirectAgent, It only works for ActorBased Agents

Implementors§

Source§

impl<T> AgentHooks for BasicAgent<T>
where T: AgentDeriveT + AgentHooks + Send + Sync + 'static,

Source§

impl<T> AgentHooks for ReActAgent<T>
where T: AgentDeriveT + AgentHooks + Send + Sync + 'static,