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§
Sourcefn on_llm_start<'a>(
&'a self,
_model_type: &'a str,
_messages: &'a [Message],
) -> BoxFuture<'a, ()>
fn on_llm_start<'a>( &'a self, _model_type: &'a str, _messages: &'a [Message], ) -> BoxFuture<'a, ()>
Called when an LLM invocation starts.
Sourcefn on_llm_end<'a>(&'a self, _response: &'a Value) -> BoxFuture<'a, ()>
fn on_llm_end<'a>(&'a self, _response: &'a Value) -> BoxFuture<'a, ()>
Called when an LLM invocation ends.
Sourcefn on_tool_start<'a>(
&'a self,
_tool_name: &'a str,
_input: &'a Value,
) -> BoxFuture<'a, ()>
fn on_tool_start<'a>( &'a self, _tool_name: &'a str, _input: &'a Value, ) -> BoxFuture<'a, ()>
Called when a tool invocation starts.
Sourcefn on_tool_end<'a>(
&'a self,
_tool_name: &'a str,
_output: &'a str,
) -> BoxFuture<'a, ()>
fn on_tool_end<'a>( &'a self, _tool_name: &'a str, _output: &'a str, ) -> BoxFuture<'a, ()>
Called when a tool invocation ends.
Sourcefn on_tool_error<'a>(
&'a self,
_tool_name: &'a str,
_error: &'a str,
) -> BoxFuture<'a, ()>
fn on_tool_error<'a>( &'a self, _tool_name: &'a str, _error: &'a str, ) -> BoxFuture<'a, ()>
Called on tool error.
Sourcefn on_retry<'a>(&'a self, _attempt: u32, _error: &'a str) -> BoxFuture<'a, ()>
fn on_retry<'a>(&'a self, _attempt: u32, _error: &'a str) -> BoxFuture<'a, ()>
Called on retry.
Sourcefn on_chain_start<'a>(&'a self, _chain_name: &'a str) -> BoxFuture<'a, ()>
fn on_chain_start<'a>(&'a self, _chain_name: &'a str) -> BoxFuture<'a, ()>
Called when a chain starts.
Sourcefn on_chain_end<'a>(&'a self, _output: &'a Value) -> BoxFuture<'a, ()>
fn on_chain_end<'a>(&'a self, _output: &'a Value) -> BoxFuture<'a, ()>
Called when a chain ends.
Sourcefn ignore_tool(&self) -> bool
fn ignore_tool(&self) -> bool
Whether to ignore tool callbacks.
Sourcefn ignore_llm(&self) -> bool
fn ignore_llm(&self) -> bool
Whether to ignore LLM callbacks.