Learn how to implement callbacks to monitor and log AI agent interactions, errors, and task completions.Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start
- Code
- No Code
Requirements
- Python 3.10 or higher
- OpenAI API key. Generate OpenAI API key here. Use Other models using this guide.
- Basic understanding of Python functions
Understanding Callbacks
What are Callbacks?
Callbacks are functions that get called automatically when specific events occur in your AI agents:
- Interactions between user and agent
- Error messages
- Tool calls
- Self-reflection moments
- Task completion
- Generation progress
Features
Interaction Callback
Triggered when the agent interacts with users
Error Callback
Called when errors occur
Tool Call Callback
Activated when tools are used
LLM Start Callback
Triggered when AI model call begins (thinking/responding)
Self Reflection Callback
Triggered during agent self-reflection
Instruction Callback
Called when instructions are processed
Generating Callback
Activated during content generation
Basic Implementation
1. Simple Logging Callback
- Code
- No Code
2. Multiple Callback Types
- Code
- No Code
Complete Example
Here’s a full implementation showing all callback types and proper logging:- Code
- No Code
Advanced Examples
- All callback types
- Comprehensive logging
- Task callbacks
- Tool integration
- Multiple agents
- Code
- No Code
Async Callbacks
Async callbacks allow you to handle events asynchronously, which is particularly useful for long-running operations or when dealing with multiple agents simultaneously.Basic Async Callback Implementation
- Code
- No Code
asyncio.run().Complete Async Example
- Code
- No Code
Async Display Functions
PraisonAI Agents provides several async versions of display functions, prefixed with ‘a’. Here’s the complete list:adisplay_instruction
adisplay_tool_call
adisplay_error
adisplay_generating
Example Usage
Verbose Mode and Process Orchestration
Verbose UI is now driven by composingon_task_start and on_task_complete callbacks, ensuring workflow processes work correctly with verbose=True:
How It Works
Integration with Process Orchestration
Previously, verbose mode bypassed workflow and hierarchical processes. Now the execution goes throughrun_all_tasks() so process="workflow" and process="hierarchical" work correctly with verbose display:
Callback Composition
User-suppliedon_task_start and on_task_complete callbacks are composed with verbose ones - both run:
- User callback executes first
- Verbose callback executes second
- Errors in either are logged at debug level and do not interrupt the task
Process Types Support
Verbose mode now supports all process orchestration types:| Process Type | Verbose Support | Behavior |
|---|---|---|
sequential | ✅ | Shows tasks executing in order |
workflow | ✅ | Shows dependency-based execution |
hierarchical | ✅ | Shows manager-agent interactions |
Best Practices
Error Handling
- Implement proper error handling
- Use try-catch blocks
- Log errors appropriately
- Handle edge cases
Performance
- Keep callbacks lightweight
- Avoid blocking operations
- Use async when appropriate
- Monitor resource usage
Next Steps
AutoAgents
Learn about automatically created and managed AI agents
Mini Agents
Explore lightweight, focused AI agents
Remember to handle callbacks efficiently and implement proper error handling to ensure smooth agent operations.

