Skip to main content

OmniCore Agent Example

Learn how to run OmniCore Agent in production with OmniDaemon using the Supervisor pattern.
πŸ’‘ Working code: examples/agents_with_supervisors/

The Challenge

When running AI agents in production, you face a critical problem: one agent crash shouldn’t kill your entire system. Most AI frameworks run everything in a single Python process:
  • ❌ Agent crashes β†’ entire process dies
  • ❌ Memory leak in one agent β†’ affects all agents
  • ❌ No isolation β†’ agents share the same memory space
  • ❌ Exception in agent code β†’ takes down the whole system
This isn’t acceptable for production. You need fault isolation.

The Supervisor Solution

OmniDaemon solves this with Agent Supervisors - lightweight process managers for your AI agents.

What is a Supervisor?

A Supervisor is a component that runs your agent in its own isolated process and manages its lifecycle. Think of it like Docker containers, but for Python AI agents:
  • Each agent runs in a separate process (different PID)
  • Supervisor monitors the agent process health
  • Automatically restarts crashed agents
  • Handles clean shutdown and resource cleanup
  • Communicates with agent via stdio (JSON protocol)

Why This Matters

Without Supervisor (all in one process):
With Supervisor (process isolation):
Production Benefits:
  • βœ… Fault Isolation - Agent A crashes, Agent B keeps running
  • βœ… Auto-Recovery - Crashed agents restart automatically
  • βœ… Resource Isolation - Each agent has its own memory/CPU space
  • βœ… Clean Shutdown - Supervisors handle graceful termination
πŸ“š Deep Dive: Agent Supervisor Architecture explains the technical details of how supervisors work under the hood.

How It Works

Instead of running your agent callback directly in the main process (risky), you wrap it in a supervisor.

❌ Simple Pattern (Development Only)

Problems:
  • No process isolation
  • Crashes affect everything
  • No auto-restart

βœ… Supervisor Pattern (Production-Ready)

Benefits:
  • Process isolation βœ…
  • Auto-restart on crash βœ…
  • Resource cleanup βœ…
The supervisor handles process spawning, health monitoring, stdio communication, and crash recovery automatically.
πŸ“š How it works internally: Complete Agent Process Flow shows the full lifecycle from event to response.

Implementation

Now that you understand WHY supervisors exist, let’s build a production-ready OmniCore Agent.

Prerequisites

Directory Structure

The Supervisor pattern requires your agent code in a directory:
πŸ’‘ Why a directory? The supervisor needs to spawn a new process with your agent code. Organizing it in a directory allows the supervisor to install dependencies in isolation and import your callback function properly.

Step 1: Agent Code

Create my_agent/agent.py with your OmniCore Agent logic:
Key Points:
  • This code runs in a separate process, not the main process
  • MCP tools connect once and stay connected
  • Clean separation of concerns

Step 2: Agent Runner

Create agent_runner.py that manages the supervisor:
What Happens Here:
  1. create_supervisor_from_directory() spawns a new Python process
  2. Process imports my_agent.agent module
  3. Supervisor keeps process running, waiting for events
  4. When event arrives, supervisor sends it to agent via stdio
  5. Agent processes and returns result
  6. Supervisor sends result back to OmniDaemon

Step 3: Run It

Expected output:
The agent is now running in its own process, ready to handle events!

Testing Your Agent

Publish an event to test:
Run it:

Production Deployment

Environment Variables

Horizontal Scaling

Run multiple instances for load balancing:
OmniDaemon automatically distributes work across all instances.

Monitoring


Complete Working Example

See the full production implementation with Google ADK: πŸ“ examples/agents_with_supervisors/ This example includes:
  • Google ADK integration
  • MCP filesystem tools
  • Process isolation with supervisors
  • Error handling
  • Graceful shutdown
  • Multiple agents

Understanding the Architecture

This supervisor pattern is fundamental to how OmniDaemon achieves production-grade reliability.

Process Architecture

Core Concepts: Implementation Guides: Other Examples:

Key Takeaways

βœ… Supervisors provide process isolation - One agent crash doesn’t affect others
βœ… Production requirement - Use supervisors for any production AI agent
βœ… Simple to use - create_supervisor_from_directory() handles everything
βœ… Auto-recovery - Crashed agents restart automatically
βœ… Resource cleanup - Graceful shutdown of MCP tools and connections
The supervisor pattern is what makes OmniDaemon production-ready. It transforms your AI agents from fragile single-process scripts into robust, fault-tolerant services.
Next: Try the Google ADK example to see supervisors with a different AI framework.