pub struct CallbackManager { /* private fields */ }Expand description
Callback manager that handles multiple handlers
Dispatch events to all registered handlers. Prefer the dispatch_* methods
over poking handlers() directly: the dispatch methods guarantee every
handler is invoked in order and (when a Tracer is attached via
with_tracer) also publish each run as a
tracing span.
Implementations§
Source§impl CallbackManager
impl CallbackManager
Sourcepub fn add_handler(self, handler: Arc<dyn CallbackHandler>) -> Self
pub fn add_handler(self, handler: Arc<dyn CallbackHandler>) -> Self
Add a callback handler
Sourcepub fn with_tracer(self, tracer: Arc<Tracer>) -> Self
pub fn with_tracer(self, tracer: Arc<Tracer>) -> Self
Attach a Tracer so every dispatched run is also published as a
tracing span (Q6: minimal merge between callbacks and the tracing tree).
With a tracer attached, dispatch_*_start starts a span named after the
run and dispatch_*_end/dispatch_*_error ends it. Nested runs become
parent/child spans via the tracer’s task-local span stack.
Sourcepub fn handlers(&self) -> &[Arc<dyn CallbackHandler>]
pub fn handlers(&self) -> &[Arc<dyn CallbackHandler>]
Get all handlers
Sourcepub fn merge_with(&self, other: &CallbackManager) -> CallbackManager
pub fn merge_with(&self, other: &CallbackManager) -> CallbackManager
Merge other’s handlers into a new manager, keeping this manager’s
handlers first and appending other’s (Q8: config merges append
callback handlers instead of replacing them wholesale).
self’s tracer wins; if self has none, other’s tracer is used.
The active trace-span table starts empty in the merged manager.
Source§impl CallbackManager
impl CallbackManager
Sourcepub async fn dispatch_run_start(&self, run: &RunTree)
pub async fn dispatch_run_start(&self, run: &RunTree)
Dispatch on_run_start to all handlers.
Sourcepub async fn dispatch_run_end(&self, run: &RunTree)
pub async fn dispatch_run_end(&self, run: &RunTree)
Dispatch on_run_end to all handlers.
Sourcepub async fn dispatch_run_error(&self, run: &RunTree, error: &str)
pub async fn dispatch_run_error(&self, run: &RunTree, error: &str)
Dispatch on_run_error to all handlers.
Sourcepub async fn dispatch_chain_start(&self, run: &RunTree, inputs: &Value)
pub async fn dispatch_chain_start(&self, run: &RunTree, inputs: &Value)
Dispatch on_chain_start to all handlers.
Sourcepub async fn dispatch_chain_end(&self, run: &RunTree, outputs: &Value)
pub async fn dispatch_chain_end(&self, run: &RunTree, outputs: &Value)
Dispatch on_chain_end to all handlers.
Sourcepub async fn dispatch_chain_error(&self, run: &RunTree, error: &str)
pub async fn dispatch_chain_error(&self, run: &RunTree, error: &str)
Dispatch on_chain_error to all handlers.
Sourcepub async fn dispatch_llm_start(&self, run: &RunTree, messages: &[Message])
pub async fn dispatch_llm_start(&self, run: &RunTree, messages: &[Message])
Dispatch on_llm_start to all handlers.
Sourcepub async fn dispatch_llm_end(&self, run: &RunTree, response: &str)
pub async fn dispatch_llm_end(&self, run: &RunTree, response: &str)
Dispatch on_llm_end to all handlers.
Sourcepub async fn dispatch_llm_error(&self, run: &RunTree, error: &str)
pub async fn dispatch_llm_error(&self, run: &RunTree, error: &str)
Dispatch on_llm_error to all handlers.
Sourcepub async fn dispatch_llm_new_token(&self, run: &RunTree, token: &str)
pub async fn dispatch_llm_new_token(&self, run: &RunTree, token: &str)
Dispatch on_llm_new_token to all handlers.
Sourcepub async fn dispatch_llm_thinking(&self, run: &RunTree, thinking: &str)
pub async fn dispatch_llm_thinking(&self, run: &RunTree, thinking: &str)
Dispatch on_llm_thinking to all handlers.
Sourcepub async fn dispatch_tool_start(
&self,
run: &RunTree,
tool_name: &str,
input: &str,
)
pub async fn dispatch_tool_start( &self, run: &RunTree, tool_name: &str, input: &str, )
Dispatch on_tool_start to all handlers.
Sourcepub async fn dispatch_tool_end(&self, run: &RunTree, output: &str)
pub async fn dispatch_tool_end(&self, run: &RunTree, output: &str)
Dispatch on_tool_end to all handlers.
Sourcepub async fn dispatch_tool_error(&self, run: &RunTree, error: &str)
pub async fn dispatch_tool_error(&self, run: &RunTree, error: &str)
Dispatch on_tool_error to all handlers.
Sourcepub async fn dispatch_retriever_start(&self, run: &RunTree, query: &str)
pub async fn dispatch_retriever_start(&self, run: &RunTree, query: &str)
Dispatch on_retriever_start to all handlers.
Sourcepub async fn dispatch_retriever_end(&self, run: &RunTree, documents: &[Value])
pub async fn dispatch_retriever_end(&self, run: &RunTree, documents: &[Value])
Dispatch on_retriever_end to all handlers.
Sourcepub async fn dispatch_retriever_error(&self, run: &RunTree, error: &str)
pub async fn dispatch_retriever_error(&self, run: &RunTree, error: &str)
Dispatch on_retriever_error to all handlers.