Callback Pattern
The callback is where your AI agent runs! This page explains the callback pattern in depth, including what data you receive, how to return results, and best practices.What is a Callback?
A callback is the function that OmniDaemon calls when an event arrives for your agent.- ✅ Must be async (
async def) - ✅ Receives one parameter (
message: dict) - ✅ Returns a dict (or None)
- ✅ Called automatically by OmniDaemon
The Message Parameter
Themessage parameter contains the full EventEnvelope sent by the publisher.
What’s Inside
Example Message
Where Your AI Agent Runs
The callback is WHERE YOUR AI AGENT RUNS!OmniCore Agent Example
Google ADK Example
Plain Python Example
Smart Callback Patterns
Use the metadata in themessage to make intelligent decisions!
1. Multi-Tenant Routing
2. Request Tracking
3. Source-Based Processing
4. Causation Chain Tracking
5. Conditional Processing
6. Webhook Notification
Return Values
Your callback should return a dictionary (or None).Success Response
Error Response
No Return (None)
What Happens to Return Values?
- Stored in storage backend (for 24 hours with TTL)
- Sent to webhook (if webhook URL provided)
- Published to reply_to topic (if specified)
- Tracked in metrics (success/failure counts)
Error Handling
Retriable vs Non-Retriable Errors
Retry Configuration
Custom Retry Logic
Async Best Practices
Use async/await Properly
Don’t Block the Event Loop
Handle Timeouts
Performance Tips
1. Initialize Outside Callback
2. Connection Pooling
3. Batch Operations
4. Parallel Processing
Testing Callbacks
Unit Testing
Mocking
Further Reading
- Agent Lifecycle - Registration, processing, deletion
- Event-Driven Architecture - How events flow
- Common Patterns - Production-ready recipes
- Complete Examples - Real-world implementations
Summary
Key Points:- ✅ Callback = Where your AI agent runs
- ✅ Receives full EventEnvelope (content + metadata)
- ✅ Use metadata for smart decisions (tenant, source, correlation)
- ✅ Return dict or None
- ✅ Handle errors properly (retriable vs non-retriable)
- ✅ Must be async function
- ✅ Initialize outside, reuse inside
content- Your datacorrelation_id- Request trackingcausation_id- Event chaintenant_id- Multi-tenancysource- Event originwebhook- HTTP callbackreply_to- Response topic
- Multi-tenant routing
- Request tracking
- Source-based processing
- Event chain tracking
- Conditional processing
- Webhook notifications