Expand description
Advanced callback system for agent events.
This module provides a type-safe, extensible callback system that allows hooking into various agent lifecycle events with support for:
- Type-based dispatch: Register callbacks for specific step types
- Priority ordering: Control callback execution order
- Async support: Both sync and async callbacks
- Context passing: Access agent state in callbacks
§Example
ⓘ
use machi::callback::{CallbackRegistry, Priority};
use machi::memory::ActionStep;
// Sync callbacks
let registry = CallbackRegistry::builder()
.on::<ActionStep>(|step, ctx| {
println!("Step {} completed", step.step_number);
})
.on_any(|step, ctx| {
println!("Any step: {:?}", step.to_value());
})
.with_logging()
.build();
// Async callbacks
let async_registry = AsyncCallbackRegistry::builder()
.on_async::<ActionStep>(|step, ctx| async move {
// Async operation like sending to a channel
println!("Async: Step {} completed", step.step_number);
})
.build();Structs§
- Async
Callback Registry - Async callback registry for managing async callbacks.
- Async
Callback Registry Builder - Builder for constructing an
AsyncCallbackRegistrywith fluent API. - Callback
Context - Context passed to callbacks during agent execution.
- Callback
Registry - Registry for managing callbacks by step type.
- Callback
Registry Builder - Builder for constructing a
CallbackRegistrywith fluent API. - Logging
Config - Configuration for the logging handler.
- Metrics
Collector - Metrics collector for tracking agent execution statistics.
- Metrics
Snapshot - Snapshot of metrics at a point in time.
- Priority
- Priority level for callback execution order.
- RunMetrics
- Metrics collected during an agent run, including duration.
Functions§
- logging_
handler - Create a logging handler with the given configuration.
- metrics_
handler - Create a metrics handler that updates the given collector.
- tracing_
handler - Create a tracing handler that emits spans for each step.
Type Aliases§
- Boxed
Callback - Type alias for boxed synchronous callback.
- Callback
Context Ref - Reference-counted callback context for shared access.
- Callback
Fn - Type alias for synchronous callback function.