pub trait AgentObserver: Send {
// Required methods
fn check_interrupt(&mut self) -> LoopControl;
fn on_status(&mut self, message: &str);
fn on_tool_result(
&mut self,
tool_name: &str,
tool_call_id: &str,
action: &AgentAction,
result: &AgentActionResult,
);
fn on_error(&mut self, error: &str);
fn on_generation_start(&mut self);
fn on_generation_complete(&mut self, tokens: usize);
}Expand description
How the agent loop communicates with its environment
Required Methods§
Sourcefn check_interrupt(&mut self) -> LoopControl
fn check_interrupt(&mut self) -> LoopControl
Called between steps to check for user interruption or injected messages.
Returns LoopControl::Continue to proceed, Interrupt to stop,
or InjectMessage(text) to redirect the agent with new user input.
Sourcefn on_status(&mut self, message: &str)
fn on_status(&mut self, message: &str)
Called when the loop status changes (e.g., “Iteration 3 - executing tools”)
Sourcefn on_tool_result(
&mut self,
tool_name: &str,
tool_call_id: &str,
action: &AgentAction,
result: &AgentActionResult,
)
fn on_tool_result( &mut self, tool_name: &str, tool_call_id: &str, action: &AgentAction, result: &AgentActionResult, )
Called after a tool call is executed
Sourcefn on_generation_start(&mut self)
fn on_generation_start(&mut self)
Called when model generation starts (for status tracking)
Sourcefn on_generation_complete(&mut self, tokens: usize)
fn on_generation_complete(&mut self, tokens: usize)
Called when model generation completes with token count