The Callback System
Callbacks in Plexe let you hook into key points in the model building lifecycle. They’re useful for:- Logging progress and results
- Integrating with experiment tracking systems
- Implementing custom monitoring solutions
- Saving artifacts
- Event triggering for workflows
Callback Lifecycle Events
TheCallback
base class defines four key methods that are triggered at different points:
on_build_start(info)
: Called once whenmodel.build()
beginson_iteration_start(info)
: Called at the start of each build iterationon_iteration_end(info)
: Called at the end of each build iterationon_build_end(info)
: Called once when the entire build process completes
info
parameter provides context about the current state, including:
- The model’s intent and configuration
- The current iteration number
- The datasets being used
- Current schemas
- Performance metrics (in
on_iteration_end
)
Built-in Callbacks
Chain of Thought Callback
This callback is automatically added when you setchain_of_thought=True
in model.build()
. It captures the
detailed reasoning steps and decision-making process of the AI agents.
- Problem analysis
- Solution planning
- Code development
- Debugging
- Evaluation
MLflow Callback
This integrates with MLflow, a popular platform for tracking ML experiments:- Creates runs for each iteration
- Logs parameters (intent, provider, iteration number)
- Records metrics (accuracy, RMSE, etc.)
- Saves artifacts (code, model files)
- Tags runs with relevant metadata
Creating Custom Callbacks
You can create your own callbacks by subclassingCallback
:
Logging System
In addition to callbacks, Plexe has a built-in logging system for observing the inner workings of the library.Configuring Logging
You can configure Plexe’s logging system to adjust verbosity:Logging Levels
- DEBUG: Very detailed information, useful for diagnosing problems
- INFO: Confirmation that things are working as expected
- WARNING: Indication of potential issues
- ERROR: Serious problems that prevented operations
- CRITICAL: Very serious errors
Log Output Destinations
By default, Plexe logs to the console (stdout), but you can redirect logs:Integrating Callbacks and Logging
For comprehensive monitoring, combine callbacks and logging:- Standard logging for library operations
- MLflow integration for experiment tracking
- Custom timing logs for performance monitoring
- Detailed agent reasoning via chain-of-thought
Best Practices
- Start Simple: Begin with
chain_of_thought=True
to see what’s happening - Use Callbacks for Integration: Connect Plexe to your existing ML infrastructure
- Create Custom Callbacks: Build callbacks tailored to your workflow needs
- Adjust Log Levels: Set appropriate verbosity based on your needs
- Combine Approaches: Use both logging and callbacks for comprehensive monitoring