Overview
Every plugin has access toself.context (PluginContext), which provides:
- Logging and debugging
- Execution tracing
- Variable watching
- Step timing
- Permission checks
- Environment variables
Logging
Basic Logging
Log Levels
| Level | Method | Use Case |
|---|---|---|
info | info() | Normal execution flow |
warn | warn() | Warnings, non-critical issues |
error | error() | Errors and failures |
debug | debug() | Detailed debugging (only in debug mode) |
Tracing
Track execution events for debugging and monitoring:Trace Entry Structure
Step Timing
Measure execution time for specific steps:- Starting a new step automatically ends the previous one
- Always call
end_step()when done
Variable Watching
Capture variable snapshots for debugging:Retrieving Variables
API Call Tracking
API calls are automatically tracked:Permissions
Check Permissions
Available Permissions
llm_access- Invoke LLM modelsknowledge_access- Search knowledge basesstorage_access- Persistent storagetools_access- Invoke other toolsnetwork_access- External API calls
Environment Variables
Get Environment Variable
Context Properties
Access execution metadata:Debug Information
Get comprehensive debug data:Debug Info Structure
Complete Example
Best Practices
Log Important Events
Log Important Events
Use
info() for significant events, helps with debugging and monitoringTrace Key Milestones
Trace Key Milestones
Use
trace() for important events with data (data loaded, processing complete, etc.)Time Critical Steps
Time Critical Steps
Use
start_step() and end_step() to measure performance of critical operationsWatch Key Variables
Watch Key Variables
Use
watch_variable() for important intermediate results during debuggingCheck Permissions Early
Check Permissions Early
Call
require_permission() early in the method to fail fast