Skip to main content

AgentObserver

Trait AgentObserver 

Source
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§

Source

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.

Source

fn on_status(&mut self, message: &str)

Called when the loop status changes (e.g., “Iteration 3 - executing tools”)

Source

fn on_tool_result( &mut self, tool_name: &str, tool_call_id: &str, action: &AgentAction, result: &AgentActionResult, )

Called after a tool call is executed

Source

fn on_error(&mut self, error: &str)

Called when the model returns an error

Source

fn on_generation_start(&mut self)

Called when model generation starts (for status tracking)

Source

fn on_generation_complete(&mut self, tokens: usize)

Called when model generation completes with token count

Implementors§