adaptive-model-cascade
Expert guide for intelligent model cascading and routing — complexity-scored task routing from Flash/Haiku to Sonnet/Opus/Astra, dynamic escalation with quality gates, 40-60% token cost reduction while maintaining output quality / Panduan ahli untuk kaskade dan routing model cerdas — routing tugas berbasis skor kompleksitas dari Flash/Haiku ke Sonnet/Opus/Astra, eskalasi dinamis dengan gerbang kualitas, pengurangan biaya token 40-60% dengan kualitas output terjaga.
Roedy Rustam · Static checks on file
Installation
Read the source and dependencies before running a command. Copying does not install or execute anything.
npx skills add roedyrustam/vibes-plug --skill adaptive-model-cascadeAbout this skill
name: adaptive-model-cascade description: "Expert guide for intelligent model cascading and routing — complexity-scored task routing from Flash/Haiku to Sonnet/Opus/Astra, dynamic escalation with quality gates, 40-60% token cost reduction while maintaining output quality / Panduan ahli untuk kaskade dan routing model cerdas — routing tugas berbasis skor kompleksitas dari Flash/Haiku ke Sonnet/Opus/Astra, eskalasi dinamis dengan gerbang kualitas, pengurangan biaya token 40-60% dengan kualitas output terjaga." author: "Roedy Rustam" version: "4.2.0"
adaptive-model-cascade — vibes-plug Skill
English
Orchestration & Integration
Connects and orchestrates with llm-finops-router, frontier-ai-models-expert, context-window-engineer, kv-cache-prefix-optimizer, llm-observability-expert, ai-llm-integration-expert, vercel-ai-sdk-expert, and test-time-compute-optimizer to implement cost-optimal model selection across all AI-powered features.
Description
Production architecture for routing AI requests to the optimal model tier based on real-time task complexity assessment. Instead of sending every request to the most expensive frontier model, this skill implements a cascade: try the fastest/cheapest model first, evaluate output quality via automated judges, and escalate to more capable (expensive) models only when the cheaper tier fails the quality gate. Achieves 40-60% cost reduction for typical production workloads where 60-70% of requests are simple enough for smaller models.
Trigger Conditions
Activate this skill when:
- Running AI features in production with significant token spend (>$500/month).
- Building applications where response quality varies by task complexity (some queries need GPT Astra 6, others need only Flash).
- Implementing cost optimization for multi-model AI architectures.
- Designing fallback and retry strategies across model providers.
Core Concepts & Patterns
1. The Model Cascade Architecture
USER REQUEST
│
▼
┌──────────────────────┐
│ COMPLEXITY SCORER │ Classify request complexity: LOW / MEDIUM / HIGH / ULTRA
│ (Fast heuristic or │
│ lightweight model) │
└──────┬───────────────┘
│
├── LOW ──────────► Gemini 4 Flash-Lite / Claude Haiku ($0.025/1M)
│ │
│ ┌────▼────┐
│ │ QUALITY │ Pass? → Return response
│ │ GATE │ Fail? → Escalate to MEDIUM
│ └─────────┘
│
├── MEDIUM ───────► Gemini 4 Flash / Claude Sonnet ($0.30/1M)
│ │
│ ┌────▼────┐
│ │ QUALITY │ Pass? → Return response
│ │ GATE │ Fail? → Escalate to HIGH
│ └─────────┘
│
├── HIGH ─────────► Gemini 4 Pro / Claude Opus ($3-15/1M)
│ │
│ ┌────▼────┐
│ │ QUALITY │ Pass? → Return response
│ │ GATE │ Fail? → Escalate to ULTRA
│ └─────────┘
│
└── ULTRA ────────► GPT Astra 6 + Extended Thinking ($15/1M)
│
Return response (final tier, no escalation)
2. Complexity Scorer (TypeScript Implementation)
export type ComplexityLevel = 'LOW' | 'MEDIUM' | 'HIGH' | 'ULTRA';
export interface ComplexitySignals {
tokenCount: number;
hasCodeGeneration: boolean;
requiresReasoning: boolean;
hasMultiStep: boolean;
domainSpecificity: 'general' | 'technical' | 'specialized';
requiresCreativity: boolean;
hasToolCalls: boolean;
contextSize: number;
}
export function scoreComplexity(signals: ComplexitySignals): ComplexityLevel {
let score = 0;
if (signals.tokenCount > 2000) score += 1;
if (signals.tokenCount > 8000) score += 1;
if (signals.hasCodeGeneration) score += 2;
if (signals.requiresReasoning) score += 2;
if (signals.hasMultiStep) score += 1;
if (signals.domainSpecificity === 'technical') score += 1;
if (signals.domainSpecificity === 'specialized') score += 2;
if (signals.requiresCreativity) score += 1;
if (signals.hasToolCalls) score += 1;
if (signals.contextSize > 100_000) score += 1;
if (signals.contextSize > 500_000) score += 2;
if (score <= 2) return 'LOW';
if (score <= 5) return 'MEDIUM';
if (score <= 8) return 'HIGH';
return 'ULTRA';
}
3. Quality Gate Evaluator
export interface QualityGateResult {
passed: boolean;
score: number;
reasons: string[];
}
export async function evaluateQualityGate(
request: string,
response: string,
tier: ComplexityLevel
): Promise<QualityGateResult> {
const checks: Array<{ name: string; passed: boolean }> = [];
// Structural completeness: does the response address all parts of the request?
const hasSubstance = response.length > 50 && !response.includes("I don't know");
checks.push({ name: 'substance', passed: hasSubstance });
// Code validity: if code was requested, does the output contain valid-looking code blocks?
if (request.toLowerCase().includes('code') || request.toLowerCase().includes('function')) {
const hasCodeBlocks = /```[\s\S]+```/.test(response);
checks.push({ name: 'code_blocks', passed: hasCodeBlocks });
}
// Refusal detection: did the model refuse or hedge excessively?
const refusalPatterns = /i('m| am) (unable|not able|can't|cannot)\s+(to|help)/i;
const noRefusal = !refusalPatterns.test(response);
checks.push({ name: 'no_refusal', passed: noRefusal });
// Length adequacy: response should be proportional to request complexity
const minExpectedLength = tier === 'LOW' ? 100 : tier === 'MEDIUM' ? 300 : 500;
const adequateLength = response.length >= minExpectedLen
Read the complete source ↗