pub struct GenericHandler { /* private fields */ }Expand description
Closure-based CallbackHandler for ad-hoc observability hooks.
Unset hooks delegate to the generic lifecycle layer, matching the
CallbackHandler trait defaults (e.g. an unset on_llm_start forwards
to on_run_start).
Implementations§
Source§impl GenericHandler
impl GenericHandler
Sourcepub fn with_run_start(
self,
f: impl Fn(&RunTree) + Send + Sync + 'static,
) -> Self
pub fn with_run_start( self, f: impl Fn(&RunTree) + Send + Sync + 'static, ) -> Self
Set the generic run-start hook.
Sourcepub fn with_run_end(self, f: impl Fn(&RunTree) + Send + Sync + 'static) -> Self
pub fn with_run_end(self, f: impl Fn(&RunTree) + Send + Sync + 'static) -> Self
Set the generic run-end hook.
Sourcepub fn with_run_error(
self,
f: impl Fn(&RunTree, &str) + Send + Sync + 'static,
) -> Self
pub fn with_run_error( self, f: impl Fn(&RunTree, &str) + Send + Sync + 'static, ) -> Self
Set the generic run-error hook.
Sourcepub fn with_llm_start(
self,
f: impl Fn(&RunTree, &[Message]) + Send + Sync + 'static,
) -> Self
pub fn with_llm_start( self, f: impl Fn(&RunTree, &[Message]) + Send + Sync + 'static, ) -> Self
Set the LLM start hook (falls back to the run-start hook when unset).
Sourcepub fn with_llm_end(
self,
f: impl Fn(&RunTree, &str) + Send + Sync + 'static,
) -> Self
pub fn with_llm_end( self, f: impl Fn(&RunTree, &str) + Send + Sync + 'static, ) -> Self
Set the LLM end hook (falls back to the run-end hook when unset).
Sourcepub fn with_llm_new_token(
self,
f: impl Fn(&RunTree, &str) + Send + Sync + 'static,
) -> Self
pub fn with_llm_new_token( self, f: impl Fn(&RunTree, &str) + Send + Sync + 'static, ) -> Self
Set the streaming-token hook (default: no-op).
Sourcepub fn with_llm_thinking(
self,
f: impl Fn(&RunTree, &str) + Send + Sync + 'static,
) -> Self
pub fn with_llm_thinking( self, f: impl Fn(&RunTree, &str) + Send + Sync + 'static, ) -> Self
Set the extended-thinking token hook (default: no-op).
Trait Implementations§
Source§impl CallbackHandler for GenericHandler
impl CallbackHandler for GenericHandler
Source§fn on_run_start<'life0, 'life1, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_run_start<'life0, 'life1, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when any run starts
Source§fn on_run_end<'life0, 'life1, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_run_end<'life0, 'life1, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a run ends successfully
Source§fn on_run_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_run_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a run fails
Source§fn on_llm_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
messages: &'life2 [Message],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_llm_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
messages: &'life2 [Message],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when an LLM starts
Source§fn on_llm_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
response: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_llm_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
response: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when an LLM ends
Source§fn on_llm_new_token<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
token: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_llm_new_token<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
token: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each new token during streaming
Source§fn on_llm_thinking<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
thinking: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_llm_thinking<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
thinking: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each thinking token during streaming (extended thinking). Read more
Source§fn on_tool_start<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
tool_name: &'life2 str,
input: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn on_tool_start<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
tool_name: &'life2 str,
input: &'life3 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Called when a tool starts
Source§fn on_retriever_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
query: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_retriever_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
query: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a retriever starts
Source§fn on_llm_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_llm_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when an LLM errors
Source§fn on_chain_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_inputs: &'life2 Value,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_chain_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_inputs: &'life2 Value,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a chain starts
Source§fn on_chain_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_outputs: &'life2 Value,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_chain_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_outputs: &'life2 Value,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a chain ends
Source§fn on_chain_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_chain_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a chain errors
Source§fn on_tool_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_output: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_tool_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_output: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a tool ends
Source§fn on_tool_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_tool_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a tool errors
Source§fn on_retriever_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_documents: &'life2 [Value],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_retriever_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
_documents: &'life2 [Value],
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a retriever ends
Source§fn on_retriever_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_retriever_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
run: &'life1 RunTree,
error: &'life2 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a retriever errors
Source§impl Default for GenericHandler
impl Default for GenericHandler
Source§fn default() -> GenericHandler
fn default() -> GenericHandler
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for GenericHandler
impl !UnwindSafe for GenericHandler
impl Freeze for GenericHandler
impl Send for GenericHandler
impl Sync for GenericHandler
impl Unpin for GenericHandler
impl UnsafeUnpin for GenericHandler
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