Skip to main content

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.
Key Points:
  • Must be async (async def)
  • Receives one parameter (message: dict)
  • Returns a dict (or None)
  • Called automatically by OmniDaemon

The Message Parameter

The message 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 the message 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?

  1. Stored in storage backend (for 24 hours with TTL)
  2. Sent to webhook (if webhook URL provided)
  3. Published to reply_to topic (if specified)
  4. 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


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
Metadata You Get:
  • content - Your data
  • correlation_id - Request tracking
  • causation_id - Event chain
  • tenant_id - Multi-tenancy
  • source - Event origin
  • webhook - HTTP callback
  • reply_to - Response topic
Smart Patterns:
  • Multi-tenant routing
  • Request tracking
  • Source-based processing
  • Event chain tracking
  • Conditional processing
  • Webhook notifications
The callback is your agent’s brain - use it wisely! 🧠✨