Skip to main content

Overview

The decision engine executes decision flows to produce personalized offer recommendations. It processes each request through a pipeline of stages, each transforming the candidate set.

Request Flow

Recommend API request


┌─────────────────┐
│  Load Flow      │  Fetch decision flow config
└────────┬────────┘

┌─────────────────┐
│  Enrich         │  Load customer data from schema tables (Redis cached)
└────────┬────────┘

┌─────────────────┐
│  Compute        │  Run formula-based computed fields per offer
└────────┬────────┘

┌─────────────────┐
│  Filter         │  Apply qualification rules, contact policies
└────────┬────────┘

┌─────────────────┐
│  Score          │  Apply scoring models (scorecard/bayesian/gradient)
└────────┬────────┘

┌─────────────────┐
│  Rank           │  Multi-objective arbitration with weighted scoring
└────────┬────────┘

┌─────────────────┐
│  Experiment     │  Apply holdout groups, track assignments
└────────┬────────┘

    Response with ranked offers + personalization data

Formula Engine

The formula engine (lib/formula-engine.ts) uses a tokenizer and recursive-descent parser. It does not use dynamic code execution — all formulas are parsed into an AST and interpreted safely. Supports arithmetic, comparison, ternary, and built-in functions.

Scoring Engines

Three scoring engines in lib/scoring/:
  • Scorecard — Weighted attribute bins with configurable thresholds
  • Bayesian — Prior probability updates with observed conversion data
  • Gradient Boosted — Feature-based ML scoring with interaction history

Arbitration

Multi-objective arbitration (lib/arbitration.ts) computes a composite score:
finalScore = w_revenue * revenue + w_margin * margin + w_propensity * propensity + w_engagement * engagement + w_priority * priority
Weights are configured per arbitration profile and must sum to 1.0.

Decision Traces

When tracing is enabled, the engine records every stage’s input/output for forensic debugging. Traces are stored in the DecisionTrace table with configurable sample rates.