pub struct AgentHooks {
pub should_stop_after_turn: Option<Arc<dyn Fn(&ShouldStopAfterTurnContext) -> bool + Send + Sync>>,
pub before_tool_call: Option<Box<dyn Fn(&BeforeToolCallContext) -> BeforeToolCallResult + Send + Sync>>,
pub after_tool_call: Option<Box<dyn Fn(&AfterToolCallContext) -> AfterToolCallResult + Send + Sync>>,
pub get_steering_messages: Option<Arc<dyn Fn() -> Vec<Message> + Send + Sync>>,
pub get_follow_up_messages: Option<Arc<dyn Fn() -> Vec<Message> + Send + Sync>>,
pub tool_execution: ToolExecutionMode,
}Expand description
Stable since 0.63.0
Callback hooks for the agent loop.
These mirror pi-mono’s AgentLoopConfig hooks, allowing callers to
inject custom logic at key points in the agentic loop.
Fields§
§should_stop_after_turn: Option<Arc<dyn Fn(&ShouldStopAfterTurnContext) -> bool + Send + Sync>>Called after each turn completes. Return true to stop the agent loop.
Wrapped in Arc so the hook can be invoked multiple times without
being consumed (unlike Box<dyn Fn> which requires take()).
before_tool_call: Option<Box<dyn Fn(&BeforeToolCallContext) -> BeforeToolCallResult + Send + Sync>>Called before a tool is executed. Return a BeforeToolCallResult with
block: true to prevent execution.
after_tool_call: Option<Box<dyn Fn(&AfterToolCallContext) -> AfterToolCallResult + Send + Sync>>Called after a tool execution completes. Can override the result.
get_steering_messages: Option<Arc<dyn Fn() -> Vec<Message> + Send + Sync>>Returns steering messages to inject mid-run. Called after each turn (unless stopped).
get_follow_up_messages: Option<Arc<dyn Fn() -> Vec<Message> + Send + Sync>>Returns follow-up messages to process after the agent would stop. Called when the agent has no more tool calls and no steering messages.
tool_execution: ToolExecutionModeTool execution mode.
Trait Implementations§
Source§impl Default for AgentHooks
impl Default for AgentHooks
Source§fn default() -> AgentHooks
fn default() -> AgentHooks
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for AgentHooks
impl !UnwindSafe for AgentHooks
impl Freeze for AgentHooks
impl Send for AgentHooks
impl Sync for AgentHooks
impl Unpin for AgentHooks
impl UnsafeUnpin for AgentHooks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more