Skip to main content

CallbackHandler

Trait CallbackHandler 

Source
pub trait CallbackHandler: Send + Sync {
    // Provided methods
    fn on_llm_start<'a>(
        &'a self,
        _model_type: &'a str,
        _messages: &'a [Message],
    ) -> BoxFuture<'a, ()> { ... }
    fn on_llm_end<'a>(&'a self, _response: &'a Value) -> BoxFuture<'a, ()> { ... }
    fn on_tool_start<'a>(
        &'a self,
        _tool_name: &'a str,
        _input: &'a Value,
    ) -> BoxFuture<'a, ()> { ... }
    fn on_tool_end<'a>(
        &'a self,
        _tool_name: &'a str,
        _output: &'a str,
    ) -> BoxFuture<'a, ()> { ... }
    fn on_tool_error<'a>(
        &'a self,
        _tool_name: &'a str,
        _error: &'a str,
    ) -> BoxFuture<'a, ()> { ... }
    fn on_retry<'a>(
        &'a self,
        _attempt: u32,
        _error: &'a str,
    ) -> BoxFuture<'a, ()> { ... }
    fn on_chain_start<'a>(&'a self, _chain_name: &'a str) -> BoxFuture<'a, ()> { ... }
    fn on_chain_end<'a>(&'a self, _output: &'a Value) -> BoxFuture<'a, ()> { ... }
    fn ignore_tool(&self) -> bool { ... }
    fn ignore_llm(&self) -> bool { ... }
}
Expand description

Trait for receiving callback events during execution.

All methods have default no-op implementations, so consumers only need to override the events they care about. The ignore_* methods allow filtering entire categories of events.

§Example

use synwire_core::callbacks::CallbackHandler;
use synwire_core::BoxFuture;

struct LoggingCallback;

impl CallbackHandler for LoggingCallback {
    fn on_tool_start<'a>(
        &'a self,
        _tool_name: &'a str,
        _input: &'a serde_json::Value,
    ) -> BoxFuture<'a, ()> {
        Box::pin(async {
            // log tool start
        })
    }
}

Provided Methods§

Source

fn on_llm_start<'a>( &'a self, _model_type: &'a str, _messages: &'a [Message], ) -> BoxFuture<'a, ()>

Called when an LLM invocation starts.

Source

fn on_llm_end<'a>(&'a self, _response: &'a Value) -> BoxFuture<'a, ()>

Called when an LLM invocation ends.

Source

fn on_tool_start<'a>( &'a self, _tool_name: &'a str, _input: &'a Value, ) -> BoxFuture<'a, ()>

Called when a tool invocation starts.

Source

fn on_tool_end<'a>( &'a self, _tool_name: &'a str, _output: &'a str, ) -> BoxFuture<'a, ()>

Called when a tool invocation ends.

Source

fn on_tool_error<'a>( &'a self, _tool_name: &'a str, _error: &'a str, ) -> BoxFuture<'a, ()>

Called on tool error.

Source

fn on_retry<'a>(&'a self, _attempt: u32, _error: &'a str) -> BoxFuture<'a, ()>

Called on retry.

Source

fn on_chain_start<'a>(&'a self, _chain_name: &'a str) -> BoxFuture<'a, ()>

Called when a chain starts.

Source

fn on_chain_end<'a>(&'a self, _output: &'a Value) -> BoxFuture<'a, ()>

Called when a chain ends.

Source

fn ignore_tool(&self) -> bool

Whether to ignore tool callbacks.

Source

fn ignore_llm(&self) -> bool

Whether to ignore LLM callbacks.

Implementors§