Overview
Lucidic provides Python decorators that make it even easier to track your AI workflows. With decorators, you can automatically wrap functions with step and event tracking without manualcreate_step()
and end_step()
calls.
Benefits
- Cleaner Code: No need for try-finally blocks or manual cleanup
- Automatic Error Handling: Steps and events are properly ended even if exceptions occur
- Function Metadata Capture: Automatically captures function inputs and outputs
- Works with Async: Full support for both sync and async functions
- Graceful Degradation: Functions work normally if Lucidic isn’t initialized
The @step
Decorator
The @step
decorator automatically wraps a function with step tracking.
Basic Usage
Parameters
All parameters are optional:state
- Current state descriptionaction
- Action being performedgoal
- Goal of this stepscreenshot_path
- Path to screenshot for this stepeval_score
- Evaluation score (0.0 to 5.0)eval_description
- Evaluation description
Error Handling
If an exception occurs, the step is automatically ended with an error indication:Async Support
Decorators work seamlessly with async functions:The @event
Decorator
The @event
decorator creates an event for a function call, automatically capturing inputs and outputs.
Basic Usage
Auto-Generated Descriptions
If you don’t provide a description, it’s automatically generated from the function signature:Parameters
description
- Custom description (auto-generated if not provided)result
- Custom result (auto-generated from return value if not provided)model
- Model name if this represents a model callcost_added
- Cost to add for this event
Capturing Results
The decorator automatically captures function return values:Combining Decorators
You can use both decorators together for comprehensive tracking:Real-World Example
Here’s a complete example showing decorators in an AI document processing pipeline:Best Practices
1. Use Meaningful Parameters
2. Combine with Manual Tracking
Decorators work well with manual tracking for fine-grained control:3. Nested Functions
When using nested decorated functions, each creates its own tracking:Limitations
- Result Recording: The
@event
decorator has a known limitation where updating the event within the decorated function may prevent the function result from being recorded properly - Context Isolation: Each decorated function creates its own context - you cannot update a parent decorator’s step/event from within a child function
- Parameter Modification: Decorator parameters are set at definition time and cannot be modified at runtime
Next Steps
- See Examples for more decorator usage patterns
- Learn about Manual Step Management for fine-grained control
- Explore Event Tracking for understanding what gets captured