An autonomous revenue operations agent that monitors business metrics, investigates anomalies, and recommends actions — built entirely on Cloudflare's AI and agent stack.
The agent monitors 8 revenue metrics on a cron schedule. When it detects an anomaly (z-score + threshold detection), it runs a 6-step Cloudflare Workflow: fetch metrics → detect anomalies → LLM root cause analysis → store results → update agent state. Users see the full evidence trail — not just a conclusion — and can chat with the agent to dig deeper.
- Autonomous — cron-triggered investigations every 15 minutes, no user action needed
- Persistent — Durable Object per company maintains health score and investigation memory across requests
- Evidence-driven — anomaly detection runs deterministically first; the LLM only fires when a real anomaly is confirmed, and must reason from that evidence
- Mock mode — full demo runs with zero API keys
git clone https://github.com/GOH8910/cf_ai_revops
cd cf_ai_revops
npm installCreate the local D1 database:
npx wrangler d1 create cf-ai-revops-db
# Copy the database_id output into wrangler.toml under [[d1_databases]]
npx wrangler d1 migrations apply cf-ai-revops-db --localStart the dev server:
npm run dev
# Open http://localhost:8787No API key needed — LLM_PROVIDER=mock is the default. To use OpenAI or Workers AI, copy .dev.vars.example to .dev.vars and set the relevant variables.
On first load the app seeds 7 days of metric data with a pre-baked checkout latency incident.
- Dashboard loads → Revenue Health Score ~71 (amber), one active anomaly
- Click ▶ Run Investigation → investigation card appears with evidence trail
- Chat: "Why did the checkout rate drop?" → grounded answer from the investigation
- Click + Inject Incident → inject a new synthetic anomaly
- Click ↺ Reset Demo → returns to clean baseline
Suggested chat prompts: Why did revenue drop today? · What's the biggest risk right now? · What should I fix first?
| Component | Role |
|---|---|
| Cloudflare Workers | HTTP API, cron scheduler, request router |
| Durable Objects | Per-company agent state (health score, last investigation ID), serialises concurrent mutations |
| Cloudflare Workflows | 6-step retryable investigation pipeline with per-step checkpointing |
| Workers AI | LLM inference — @cf/meta/llama-3.1-8b-instruct |
| D1 (SQLite) | Metric snapshots, investigation history, chat messages |
| KV | Health score cache (15-minute TTL matching cron interval) |
| Cron Triggers | Autonomous scheduled investigations every 15 minutes |
Static assets (public/) are vanilla JS served directly by the Worker.
Browser (vanilla JS) → Cloudflare Worker (API + static assets)
│
├── Durable Object (RevOpsAgent)
│ health score · last investigation ID
│ serialises concurrent Workflow + chat mutations
│
├── Workflow (InvestigationWorkflow)
│ step 1: create investigation record
│ step 2: fetch metrics from D1
│ step 3: detect anomalies (z-score)
│ step 4: LLM root cause analysis
│ step 5: store investigation results
│ step 6: update Durable Object
│
├── D1 — metric_snapshots · investigations · chat_messages
├── KV — health score cache (TTL 15m)
└── Workers AI / OpenAI
See docs/architecture.md for the full design rationale.
cf_ai_revops/
├── PROMPTS.md ← AI prompts used + design rationale
├── wrangler.toml
├── src/
│ ├── index.ts ← Worker entry: router + cron handler
│ ├── agent/
│ │ ├── RevOpsAgent.ts ← Durable Object: chat, state, memory
│ │ ├── InvestigationWorkflow.ts ← Cloudflare Workflow: 6-step pipeline
│ │ └── prompts.ts ← LLM prompt templates
│ ├── services/
│ │ ├── anomalyDetection.ts ← Z-score detection, health score
│ │ ├── mockData.ts ← Mock data generator + seeds
│ │ ├── llmProvider.ts ← Workers AI / OpenAI / Mock abstraction
│ │ └── storage.ts ← D1 query helpers
│ └── db/migrations/0001_schema.sql
└── public/ ← Vanilla JS frontend
├── index.html
├── styles.css
└── app.js
