Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Growth Department

Funnel optimization, conversion tracking, cohort analysis, KPI dashboards.

FieldValue
IDgrowth
Icon&
Colororange
Engine crategrowth-engine (~375 lines)
Dept cratedept-growth
StatusSkeleton – manager structures with CRUD, minimal business logic

Overview

The Growth department tracks growth metrics for a solo SaaS business: conversion funnels with ordered stages, user cohorts for retention analysis, and KPI time-series recording. The engine provides three manager subsystems backed by ObjectStore.


Current Status: Skeleton

The growth engine has manager structures but minimal business logic (~375 lines total across lib.rs and three manager modules). The managers provide CRUD operations:

  • FunnelManageradd_stage(sid, name, order), list_stages(sid), record_conversion(sid, stage_id, count). Defines ordered funnel stages and records conversion counts per stage.
  • CohortManagercreate_cohort(sid, name, size), list_cohorts(sid), analyze_retention(sid, cohort_id). Creates named cohorts with initial size for retention tracking.
  • KpiManagerrecord_kpi(sid, name, value, unit), list_kpis(sid), get_kpi_trend(sid, name). Records time-series KPI measurements and computes simple two-point trend (delta between last two readings).

The department is fully registered and bootable – it appears in the department registry, responds to chat, and has 4 agent tools wired. However, it needs the following to be production-ready:

  • Funnel drop-off rate calculation and visualization data
  • Cohort retention matrix computation
  • KPI alerting (threshold-based notifications)
  • Churn prediction models via AgentPort
  • Historical trend analysis beyond two-point comparison
  • Dashboard data aggregation endpoints

Engine Details

Crate: growth-engine (~375 lines)

Struct: GrowthEngine

Constructor:

#![allow(unused)]
fn main() {
GrowthEngine::new(
    storage: Arc<dyn StoragePort>,
    events: Arc<dyn EventPort>,
    agent: Arc<dyn AgentPort>,
    jobs: Arc<dyn JobPort>,
)
}

Managers:

ManagerMethodsDescription
FunnelManageradd_stage(), list_stages(), record_conversion()Conversion funnel tracking
CohortManagercreate_cohort(), list_cohorts(), analyze_retention()User cohort analysis
KpiManagerrecord_kpi(), list_kpis(), get_kpi_trend()KPI time-series

Implements: rusvel_core::engine::Engine trait (kind: "growth", name: "Growth Engine")


Manifest

Declared in dept-growth/src/manifest.rs:

id:            "growth"
name:          "Growth Department"
description:   "Funnel optimization, conversion tracking, cohort analysis, churn prediction, retention strategies, KPI dashboards"
icon:          "&"
color:         "orange"
capabilities:  ["funnel", "cohort", "kpi"]

System Prompt

You are the Growth department of RUSVEL.

Focus: funnel optimization, conversion tracking, cohort analysis, churn prediction, retention strategies, KPI dashboards.

Tools

Tools registered at runtime via dept-growth/src/tools.rs (4 tools):

ToolParametersDescription
growth.funnel.add_stagesession_id, name, orderAdd a funnel stage for conversion tracking
growth.cohort.create_cohortsession_id, name, sizeCreate a user cohort for retention analysis
growth.kpi.record_kpisession_id, name, value, unitRecord a KPI measurement
growth.kpi.get_trendsession_id, kpi_nameCompare last two readings for a named metric (simple trend with delta)

Personas

None declared in the manifest.


Skills

None declared in the manifest.


Rules

None declared in the manifest.


Jobs

None declared in the manifest. Future candidates:

  • Scheduled KPI snapshot collection
  • Periodic cohort retention analysis
  • Churn detection scans

Events

Defined Constants (engine)

ConstantValue
FUNNEL_UPDATEDgrowth.funnel.updated
COHORT_ANALYZEDgrowth.cohort.analyzed
KPI_RECORDEDgrowth.kpi.recorded
CHURN_DETECTEDgrowth.churn.detected

These constants are defined in the engine but are not yet emitted automatically by the manager methods. They are not listed in the manifest’s events_produced.

Consumed

None.


API Routes

None declared in the manifest. The department is accessible via the standard parameterized routes:

  • GET /api/dept/growth/status – department status
  • POST /api/dept/growth/chat – SSE chat

CLI Commands

Standard department CLI:

rusvel growth status    # One-shot status
rusvel growth list      # List items
rusvel growth events    # Show events

Entity Auto-Discovery

The standard CRUD subsystems are available at /api/dept/growth/*:

  • Agents, Skills, Rules, Hooks, Workflows, MCP Servers

Chat Flow

sequenceDiagram
    participant U as User
    participant API as /api/dept/growth/chat
    participant Agent as AgentRuntime
    participant Tool as growth.* tools
    participant Engine as GrowthEngine
    participant Store as StoragePort

    U->>API: POST "Record MRR of $12,000"
    API->>Agent: run_streaming(system_prompt, tools)
    Agent->>Tool: growth.kpi.record_kpi(name="MRR", value=12000, unit="USD")
    Tool->>Engine: kpi().record_kpi(sid, "MRR", 12000.0, "USD")
    Engine->>Store: objects.put("kpis", id, value)
    Store-->>Engine: Ok
    Engine-->>Tool: kpi_id
    Tool-->>Agent: {"kpi_id": "..."}
    Agent->>Tool: growth.kpi.get_trend(kpi_name="MRR")
    Tool->>Engine: kpi().list_kpis(sid)
    Engine->>Store: objects.list("kpis")
    Store-->>Engine: Vec<KpiEntry>
    Tool->>Tool: filter by name, sort, compute delta
    Tool-->>Agent: {"previous": 10000, "latest": 12000, "delta": 2000}
    Agent-->>API: SSE chunks
    API-->>U: "MRR recorded at $12,000. Up $2,000 from last reading."

Extending the Department

Adding funnel drop-off analysis

  1. Add a drop_off_rates(sid) method to FunnelManager that computes conversion percentages between consecutive stages
  2. Register a growth.funnel.analyze tool in dept-growth/src/tools.rs
  3. Add a quick action to the manifest

Adding churn detection

  1. Implement a detect_churn(sid) method in CohortManager that identifies cohorts with declining retention
  2. Wire events::CHURN_DETECTED emission when thresholds are crossed
  3. Optionally use AgentPort for AI-powered churn prediction
  4. Add to the manifest’s events_produced

Adding dashboard data endpoints

  1. Add route contributions to the manifest for /api/dept/growth/dashboard
  2. Implement a handler that aggregates funnel, cohort, and KPI data into a single response
  3. Wire the route in rusvel-api

Port Dependencies

PortRequiredUsage
StoragePortYesFunnel stages, cohorts, KPI entries (via ObjectStore)
EventPortYesDomain event emission (constants defined, not yet auto-emitted)
AgentPortYesLLM-powered growth analysis via chat, future churn prediction
JobPortYesFuture: scheduled KPI collection and analysis