Skip to content

Strategy Engine

The Strategy Engine is the decision-maker. It takes the classified intent, workload profile, and workspace preferences, and selects an Orchestration Strategy that tells the rest of the system how to prioritize trade-offs between cost, speed, and quality.

StrategyPriorityWhen It’s ChosenKey File
CostMinimise spendBudget-conscious workspaces, simple tasks, batch jobsstrategy/engine.ts
SpeedMinimise latencyAutocomplete, quick fixes, urgent requestsstrategy/engine.ts
QualityMaximise output qualityComplex tasks, code review, architecture discussionstrategy/engine.ts
BalancedEquilibriumDefault fallback, uncertain classificationstrategy/engine.ts
CustomUser-definedAdvanced users who tune per-task preferencesstrategy/registry-db.ts
Intent + Workload + Workspace Profile
|
v
[1] Direct Match Check --> Does workspace have a pinned strategy for this intent?
|
v
[2] Workload-Based --> Select based on complexity + urgency + cost sensitivity
|
v
[3] Fallback Default --> Return balanced strategy
|
v
[4] Build Snapshot --> strategy/buildStrategySnapshot()

The core function resolveExecutionStrategy() in strategy/engine.ts implements this logic.

Strategies aren’t just labels, they carry detailed configuration:

  • Provider priority: Free → Cheap → Standard (never premium unless fallback)
  • Model preference: Smallest capable model
  • Batching: Aggressive, group requests where possible
  • Timeout: Standard (30s)
  • Fallback: Relaxed (any available provider)
  • Provider priority: Lowest latency provider first
  • Model preference: Fast inference models (e.g., GPT-4o-mini, Claude Haiku)
  • Streaming: Enabled
  • Timeout: Fast (5s)
  • Fallback: Strict (same latency tier)
  • Provider priority: Premium providers first (Claude Opus, GPT-4o)
  • Model preference: Largest capable model
  • Streaming: Disabled (for complete responses)
  • Timeout: Deep (120s)
  • Fallback: Relaxed (any model that can handle complexity)
  • Provider priority: Mid-tier providers
  • Model preference: Medium-sized models
  • Streaming: Auto-detect
  • Timeout: Standard (30s)
  • Fallback: Moderate

Strategies are stored in a registry (strategy/registry-db.ts) with:

interface Strategy {
id: string;
slug: 'cost' | 'speed' | 'quality' | 'balanced' | 'custom';
workspaceId: string | null; // null = global default
weights: {
cost: number; // 0.0-1.0
speed: number; // 0.0-1.0
quality: number; // 0.0-1.0
};
constraints: {
maxCostPerRequest: number;
maxLatencyMs: number;
minQualityScore: number;
};
}

Strategies are not static. The Adaptive Calibration Engine (evaluation/calibration/engine.ts) periodically recalibrates strategy weights based on:

  • Outcome scores: Did the chosen strategy produce good results?
  • Cost efficiency: Was the spend justified by the output quality?
  • User feedback: Explicit thumbs-up/down on responses

Functions:

  • calibrateStrategies(), adjusts strategy weights across all workspaces
  • calibrateWorkloads(), discovers which workloads perform best with which strategies
  • buildRecommendations(), suggests strategy changes to workspace admins
FileWhat It Does
strategy/engine.tsMain strategy resolver. Selects strategy based on inputs
strategy/registry-db.tsDatabase layer for strategy CRUD and workspace association
strategy/types.tsType definitions for strategies, weights, and constraints
evaluation/calibration/engine.tsRecalibrates strategies based on historical outcomes
onboarding/optimizationStrategyCatalog.tsPre-built optimization strategy configs
  1. Intent Classification → provides intent signals
  2. Workload Analysis → provides complexity and urgency
  3. Workspace Profiles → provides pinned strategies and constraints
  4. Provider Scoring → receives the strategy to apply scoring weights
  5. Economics → receives strategy for budget-aware provider selection