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 { ... }
}Expand description
Lifecycle hooks that allow observing and customizing agent behavior. Implementers can observe agent creation, per-run lifecycle (start/complete), per-turn lifecycle (start/complete) for multi-turn executors, and tool execution (pre-call gating, start, result, error).
Provided Methods§
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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_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
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,
Sourcefn 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_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
Sourcefn 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_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
Sourcefn 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_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