EventAgent is a passive event observer that subscribes to NATS JetStream events, validates them, persists them to SQLite, and correlates related events into workflow instances.
Order Service ──┐
│
Payment Service ─┼──► NATS ──► EventAgent (Passive Observer)
│
└──► publishes events
EventAgent observes events published by services (Order Service, Payment Service) and persists them. It does NOT trigger workflows or publish new events.
- Passive Observation: Subscribes to
events.>on NATS, validates and persists events to SQLite - Event Correlation: Groups related events into workflow instances by correlation key (e.g.,
order_id) - Out-of-Order Detection: Distinguishes between
timestamp(event time) andreceived_at(observation time) - CLI Interface: Rich CLI for querying events and workflows
pip install eventagentOr with uv:
uv pip install eventagent# Install the package
pip install eventagent
# Start NATS server (requires Docker)
docker run -d --name nats -p 4222:4222 nats:latest -js -sd /data
# Run EventAgent (passive observer)
python -m eventagent run --servers localhost:4222
# In another terminal, publish an event
python -m eventagent order --order-id order_123 --amount 100.0# Start passive observer
eventagent run --servers nats://localhost:4222
# Publish an order event
eventagent order --order-id order_123 --amount 100.0
# Publish a custom event
eventagent publish order.created --payload '{"amount": 500}' --correlation '{"order_id": "123"}'
# Start payment service (listens for orders)
eventagent payment-service --payment-result success
# Query events
eventagent events --order-id 8472
eventagent events --type order.created
# View workflow timeline
eventagent workflow order_8472
# List all workflows
eventagent workflowsNATS_SERVERS: NATS server URLs (comma-separated) - default:localhost:4222PAYMENT_RESULT: For payment service, eithersuccessorfailureORDER_ID: Order ID for order service CLIORDER_AMOUNT: Order amount for order service CLI
User A (Device 1) NATS EventAgent (Server)
│ │ │
└── publish order.created ──► │
│ │ │
User B (Device 2) │ │
│ │ │
└── publish payment.initiated ──► │
│ │ │
│ └───► observe & persist │
│ │ │
User C (Device 3) │ │
│ │ │
└── publish payment.succeeded ──► │
│ │ │
│ └───► observe & persist │
│ │ │
│ ┌──────────────┴──────────────┐ │
│ │ EventAgent correlates all │ │
│ │ events into a single │ │
│ │ workflow (order_id) │ │
│ └─────────────────────────────┘ │
Multiple users on different devices can publish events. EventAgent correlates them by the order_id field.