AI Engine

The AI engine is an autonomous decision system that manages search strategy, resource allocation, and campaign orchestration. It replaces manual tuning with a unified OODA decision loop that continuously adapts to fleet state, discovery patterns, and cost constraints.

OODA Decision Loop

Every 30 seconds the engine executes a full Observe → Orient → Decide → Act cycle:

┌──────────┐     ┌──────────┐     ┌──────────┐     ┌──────────┐
│ Observe  │────▶│  Orient  │────▶│  Decide  │────▶│   Act    │
│          │     │          │     │          │     │          │
│ Snapshot │     │  Score   │     │  Select  │     │ Execute  │
│ fleet,   │     │  forms,  │     │  best    │     │ start/   │
│ costs,   │     │  weight  │     │  action  │     │ stop/    │
│ records  │     │  drift   │     │  plan    │     │ reconfig │
└──────────┘     └──────────┘     └──────────┘     └──────────┘
      │                                                   │
      └───────────────── Learn ◀──────────────────────────┘

Observe: WorldSnapshot

A single consistent view of the entire system assembled via parallel database queries in ~50ms:

  • Active workers, their capabilities, and current assignments
  • Running searches with progress, rate, and stall detection
  • Recent discoveries and their forms
  • Budget velocity and remaining compute budget
  • World record standings per form (scraped from t5k.org)
  • Cost model coefficients from calibration data

Orient: Scoring Model

Each candidate search form is scored using a 7-component weighted model:

ComponentWeightDescription
record_gapDynamicDistance to current world record — closer means higher payoff
yield_rateDynamicHistorical primes-per-core-hour for this form
cost_efficiencyDynamicExpected cost per discovery using the power-law cost model
opportunity_densityDynamicUntested candidate density in the target range
fleet_fitDynamicHow well the form matches available worker hardware
momentumDynamicRecent discovery trend — reward hot streaks
competitionDynamicExternal search activity on competing platforms

Weights are learned via online gradient descent, comparing predicted outcomes against actual discovery data. The learned weights are persisted in the ai_engine_state database table.

Decide & Act

The decision phase selects from a set of possible actions:

  • Start search — Launch a new search on the highest-scored form
  • Stop search — Terminate a stalled or low-yield search
  • Reconfigure — Adjust sieve depth, worker count, or range parameters
  • Scale — Request more workers or release idle ones
  • Hold — No action needed (system is performing well)

Learn: Outcome Tracking

Every decision is recorded in the ai_engine_decisions table with reasoning text, confidence score, and eventual outcome. This audit trail enables:

  • Weight updates via gradient descent on prediction error
  • Post-hoc analysis of strategy effectiveness
  • Debugging poor decisions with full context replay

Cost Model

The cost model predicts compute time for a work block using a power-law regression fitted to historical data:

text
cost(digits) = a * digits^b

Where:
  a, b  = OLS-fitted coefficients on log-log work block data
  digits = candidate digit count

Fallback defaults (when insufficient data):
  factorial:    a=1e-6,  b=2.5
  kbn:          a=1e-7,  b=2.0
  palindromic:  a=1e-5,  b=2.2
  ...per form

Coefficients are recalibrated automatically as new work block completions arrive. The model is stored in the calibrations database table.

Drift Detection

The engine compares consecutive WorldSnapshots to detect significant changes that require immediate attention:

  • Worker change — Workers joining or leaving the fleet
  • Discovery — New prime found, potentially shifting strategy
  • Stall — Search making no progress for extended period
  • Budget alert — Spend rate exceeding budget velocity target

Safety Checks

Before any action is executed, safety gates are evaluated:

  • Budget gate — Cannot start new searches if remaining budget is below threshold
  • Concurrency limit — Maximum simultaneous searches per form
  • Stall penalty — Penalize forms that have recently stalled
  • Cooldown — Minimum interval between actions to prevent thrashing

Dashboard Integration

The AI engine state is visible in the dashboard at app.darkreach.ai/strategy:

  • Current scoring weights and form rankings
  • Decision history with reasoning and outcomes
  • Cost model curves per form
  • Drift event timeline

Configuration

The AI engine runs automatically when the coordinator starts with a database connection. Key configuration is via environment variables and the ai_engine_state table:

bash
# Tick interval (default: 30s)
AI_ENGINE_TICK_INTERVAL=30

# Budget limit (USD per day)
AI_ENGINE_DAILY_BUDGET=50.0

# Maximum concurrent searches
AI_ENGINE_MAX_CONCURRENT=8