Overview
Flow Core’s callback system provides comprehensive event hooks for monitoring, debugging, and controlling workflow execution. Callbacks enable real-time tracking of workflow progress, error handling, and custom business logic injection.Callback Event System
CallbackEvent
Standardized event data structure passed to all callback handlers:Event Types
Complete list of available callback events:| Category | Event | Description |
|---|---|---|
| Workflow | on_workflow_start | Workflow execution begins |
on_workflow_end | Workflow completes successfully | |
on_workflow_error | Workflow encounters error | |
| Node | on_node_start | Node begins execution |
on_node_end | Node completes successfully | |
on_node_error | Node encounters error | |
| LLM | on_llm_start | LLM call begins |
on_llm_end | LLM call completes | |
on_llm_token | Individual token streamed | |
on_llm_error | LLM call fails | |
| Tool | on_tool_start | Tool execution begins |
on_tool_end | Tool execution completes | |
on_tool_error | Tool execution fails | |
| Custom | on_custom_event | User-defined events |
BaseCallbackHandler
Create custom callback handlers by extending the base class:CallbackManager
Manage multiple callback handlers with the CallbackManager:Handler Inheritance
Inheritable handlers propagate to sub-workflows:Built-in Handlers
ConsoleCallbackHandler
Pretty-print events to console with colors and emojis:LoggingCallbackHandler
Integration with Python’s logging system:MetricsCallbackHandler
Track execution metrics (example implementation):Integration Patterns
Pattern 1: Workflow Monitoring
Complete monitoring solution:Pattern 2: Progress Tracking
Track and report workflow progress:Pattern 3: Debugging & Tracing
Detailed execution tracing:Pattern 4: Cost Tracking
Track LLM token usage and costs:Advanced Features
Async Callbacks
Support for async callback handlers:Conditional Callbacks
Execute callbacks based on conditions:Event Filtering
Filter events by tags or metadata:Best Practices
Keep Callbacks Lightweight
Keep Callbacks Lightweight
Callbacks run synchronously - avoid heavy operations:
Handle Errors Gracefully
Handle Errors Gracefully
Don’t let callback errors crash workflows:
Use Appropriate Handlers
Use Appropriate Handlers
Choose the right handler for your needs:
- Console: Development/debugging
- Logging: Production monitoring
- Custom: Business logic
Manage Handler Lifecycle
Manage Handler Lifecycle
Clean up resources properly: