pub struct AgentHooks {
pub should_stop_after_turn: Option<Arc<dyn Fn(&ShouldStopAfterTurnContext) -> bool + Sync + Send>>,
pub before_tool_call: Option<Box<dyn Fn(&BeforeToolCallContext) -> BeforeToolCallResult + Sync + Send>>,
pub after_tool_call: Option<Box<dyn Fn(&AfterToolCallContext) -> AfterToolCallResult + Sync + Send>>,
pub get_steering_messages: Option<Arc<dyn Fn() -> Vec<Message> + Sync + Send>>,
pub get_follow_up_messages: Option<Arc<dyn Fn() -> Vec<Message> + Sync + Send>>,
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 + Sync + Send>>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 + Sync + Send>>Called before a tool is executed. Return a BeforeToolCallResult with
block: true to prevent execution.
after_tool_call: Option<Box<dyn Fn(&AfterToolCallContext) -> AfterToolCallResult + Sync + Send>>Called after a tool execution completes. Can override the result.
get_steering_messages: Option<Arc<dyn Fn() -> Vec<Message> + Sync + Send>>Returns steering messages to inject mid-run. Called after each turn (unless stopped).
get_follow_up_messages: Option<Arc<dyn Fn() -> Vec<Message> + Sync + Send>>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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.