Skip to main content

Agent Lifecycle Management

This page explains the complete lifecycle of an agent in OmniDaemon, from registration to deletion, including pausing and resuming operations.

Overview

An agent in OmniDaemon goes through several states during its lifetime:
Let’s explore each stage in detail.

1. Registration

Registration is when you tell OmniDaemon about your agent and what topic it should listen to.

Simple Registration

What Happens During Registration

  1. Agent metadata stored in the storage backend:
  2. Consumer group created on the event bus:
  3. Agent starts listening for events on the topic
  4. Start time recorded in storage (for health checks and uptime tracking)

Registration Options

Multiple Agents

You can register multiple agents in the same runner:

2. Active State (Processing)

Once registered and started, your agent is active and processing events.

Event Processing Flow

Example Processing

Monitoring Active Agents


3. Pausing (Unsubscribe)

Sometimes you want to pause an agent without deleting it completely. This is useful for:
  • Temporary maintenance
  • Testing changes before deploying
  • Scaling down during low traffic
  • Debugging issues

How to Pause

Via SDK:
Via CLI:
Via API:

What Happens When Paused

  1. Agent stops consuming new messages
    • No new events delivered to this agent
    • Other agents in the group (if any) continue
  2. Consumer group remains on event bus
    • Message history preserved
    • Position in stream maintained
  3. Agent metadata kept in storage
    • Still shows as registered
    • Can see configuration and history
  4. DLQ preserved (if it exists)
    • Failed messages not deleted
    • Can still inspect and retry

Resuming from Pause

To resume a paused agent, simply restart your agent runner:
The agent will:
  • Re-register with same configuration
  • Resume from where it left off
  • Start processing new events
Why this works:
  • Consumer group still exists
  • Event bus remembers last processed position
  • Agent picks up from there

4. Deletion

Deletion permanently removes an agent and optionally cleans up its infrastructure.

Simple Delete (Keep Infrastructure)

Deletes agent from registry but keeps consumer group and DLQ: Via SDK:
Via CLI:
Use case: Temporary removal, planning to add agent back later

Complete Delete (Clean Everything)

Deletes agent AND cleans up all infrastructure: Via SDK:
Via CLI:
Use case: Permanently removing agent, won’t use again

What Happens During Deletion

Simple Delete:
  1. ✅ Agent removed from registry
  2. ✅ Stops processing new events
  3. ❌ Consumer group NOT deleted
  4. ❌ DLQ NOT deleted
  5. ❌ Message history preserved
Complete Delete:
  1. ✅ Agent removed from registry
  2. ✅ Stops processing new events
  3. ✅ Consumer group deleted
  4. ✅ DLQ deleted (if requested)
  5. ✅ All infrastructure cleaned up

Delete Entire Topic

Remove all agents for a topic: Via SDK:
Via CLI:
This removes ALL agents subscribed to the topic.

5. Graceful Shutdown

When you stop your agent runner (Ctrl+C), OmniDaemon performs a graceful shutdown:

What Happens During Shutdown

  1. Stop accepting new messages
    • Agent unsubscribes from topic
    • No new events delivered
  2. Finish current processing
    • In-flight messages completed
    • Results stored
  3. Clean up resources
    • Close event bus connections
    • Close storage connections
    • Release memory
  4. Clear start time from storage
    • Health checks show “stopped”
    • Uptime resets
  5. Exit cleanly
    • No hanging processes
    • No orphaned connections

Handling Signals

OmniDaemon handles these signals gracefully:

Lifecycle Management Strategies

Development

Staging

Production


Health Monitoring

Check Agent Status

Real-Time Status

The health command shows real-time status:
Output:
Status Values:
  • running - Agent runner active, processing events
  • stopped - Agent runner not running (but agents still registered)
  • ready - No agents registered, infrastructure healthy
  • degraded - Some infrastructure unhealthy
  • down - Critical infrastructure down

Advanced Patterns

Conditional Registration

Register agents based on environment:

Dynamic Agent Registration

Register agents based on configuration:

Health-Check-Based Registration

Only register if dependencies are healthy:

Best Practices

1. Use Descriptive Names

2. Version Your Agents

3. Handle Shutdown Gracefully

4. Monitor Agent Health

5. Use Unsubscribe for Maintenance


Troubleshooting

Agent Not Processing Events

Agent Stuck After Shutdown

Can’t Delete Agent


Further Reading


Summary

Agent Lifecycle States:
  1. Unregistered - Agent doesn’t exist yet
  2. Registered & Active - Agent processing events
  3. Paused (Unsubscribed) - Agent stopped, infrastructure preserved
  4. Deleted - Agent removed, optionally clean up infrastructure
Key Operations:
  • register_agent() - Create and start agent
  • unsubscribe_agent() - Pause agent (keep infrastructure)
  • delete_agent() - Remove agent (optionally clean up)
  • shutdown() - Graceful stop
Monitoring:
  • omnidaemon health - Real-time system status
  • omnidaemon agent list - All registered agents
  • omnidaemon metrics - Processing statistics