autoagents_core/agent/
hooks.rs1use crate::agent::task::Task;
2use crate::agent::{AgentDeriveT, Context};
3use crate::tool::ToolCallResult;
4use async_trait::async_trait;
5use autoagents_llm::ToolCall;
6use serde_json::Value;
7
8#[derive(PartialEq)]
9pub enum HookOutcome {
10 Continue,
11 Abort,
12}
13
14#[async_trait]
15pub trait AgentHooks: AgentDeriveT + Send + Sync {
16 async fn on_agent_create(&self) {}
18 async fn on_run_start(&self, _task: &Task, _ctx: &Context) -> HookOutcome {
20 HookOutcome::Continue
21 }
22 async fn on_run_complete(&self, _task: &Task, _result: &Self::Output, _ctx: &Context) {}
24 async fn on_turn_start(&self, _turn_index: usize, _ctx: &Context) {}
26 async fn on_turn_complete(&self, _turn_index: usize, _ctx: &Context) {}
28 async fn on_tool_call(&self, _tool_call: &ToolCall, _ctx: &Context) -> HookOutcome {
30 HookOutcome::Continue
31 }
32 async fn on_tool_start(&self, _tool_call: &ToolCall, _ctx: &Context) {}
34 async fn on_tool_result(
36 &self,
37 _tool_call: &ToolCall,
38 _result: &ToolCallResult,
39 _ctx: &Context,
40 ) {
41 }
42 async fn on_tool_error(&self, _tool_call: &ToolCall, _err: Value, _ctx: &Context) {}
44 async fn on_agent_shutdown(&self) {}
46}