Repository navigation
Description
Vision: Democratizing AI Through Intelligent Model Routing
The AI team (Claude, DeepSeek, Groq, Fireworks, Together) collaboratively designed an Adaptive Complexity Routing architecture during their 2025-11-21 chat session. This aligns perfectly with our core mission: preventing AI overspend while democratizing access to advanced agent systems on commodity M1+ hardware.
Architecture Document
📄 Full Design: ADAPTIVE-COMPLEXITY-ROUTING.md
Core Innovation: Progressive Model Upgrading
The Problem:
- Simple messages waste money on expensive APIs (GPT-4, Claude Sonnet)
- Complex messages get routed to fast but inadequate models (Groq Lightning)
- No progressive reassessment during generation
- Users forced to choose between cost and quality
The Breakthrough:
Dynamic complexity assessment with mid-stream model upgrading:
- Start with cheap/free local models (Ollama)
- Assess complexity every 200 tokens during generation
- Upgrade to capable models only when needed
- Preserve context across transitions
THE SPIKE: Engineering Rigor
Critical Innovation: Time-boxed technical investigation (the "spike") to validate assumptions BEFORE full implementation.
Spike validates:
- ✅ Can we hot-swap models without losing context?
- ✅ Is latency acceptable (< 500ms)?
- ✅ Which providers support mid-stream upgrades?
- ✅ Do we need pre-warmed model pools?
Run spike DURING Phase 1 (not after) to pivot early if needed.
Cost & Democratization Impact
Before: 100% premium APIs → $100+/month
After: 80% local Ollama + 15% cheap APIs + 5% premium → $5-10/month
Savings: 90%+ while maintaining quality
M1+ Hardware Support:
- M1 Air: 7B models (qwen2.5, llama3.2) - FREE
- M1 Pro/Max: 70B models (llama3.1, deepseek-coder) - FREE
- M1 Ultra: Multiple models simultaneously - FREE
Implementation Phases
Phase 1: Complexity Assessment Foundation ✅ START HERE
- Complexity assessment engine (straightforward/moderate/nuanced)
- ComplexityLevel classification with hybrid approach (heuristics + LLM)
- Model routing map (local-fast → ollama-capable → api-cheap → api-premium)
- Integration with PersonaMessageEvaluator
Key Files:
system/user/server/modules/ComplexityAssessor.tssystem/user/server/modules/ModelRouter.tssystem/shared/ModelTiers.ts
Phase 2: Progressive Scoring System
- ProgressiveScorer class with token-window analysis
- Upgrade indicator detection (hedging, uncertainty, self-correction)
- Streaming wrapper for generateWithProgressiveScoring()
- Integration with AIProviderDaemon
Key Files:
system/user/server/modules/ProgressiveScorer.tsdaemons/ai-provider-daemon/shared/StreamingWrapper.ts
Phase 3: THE SPIKE - Upgrade Feasibility
- Test context preservation (Ollama local-to-local)
- Measure upgrade latency (target: < 500ms)
- Test provider compatibility (OpenAI, Anthropic, DeepSeek)
- Identify blockers and edge cases
- Generate SpikeFinding report with recommendations
Spike Script:
npx tsx tests/spikes/model-upgrade-spike.tsDecision Matrix (after spike):
- Feasible → hot-swap implementation
- High latency → graceful-restart at turn boundaries
- Context loss → pre-warmed model pools
Phase 4: Upgrade Mechanism Implementation
- UpgradeStrategy based on spike recommendations
- upgradeModel() function with chosen mechanism
- Fallback handling for failed upgrades
- Context preservation protocol via ResponseContext
Key Files:
system/user/server/modules/ModelUpgrader.tssystem/user/server/modules/ResponseContext.ts
Phase 5: Analytics and Optimization
- Cost tracking (API spend vs local usage)
- Accuracy metrics (did routing predict correctly?)
- Performance dashboards
- Tuning thresholds based on real data
Commands:
./jtag routing/analytics --userId="joel" --timeRange="30d"Integration with PersonaUser Convergence
The universal cognitive cycle enhanced:
async serviceInbox() {
const tasks = await this.inbox.peek(10);
if (tasks.length === 0) return await this.rest();
// 🆕 ADAPTIVE ROUTING
const complexity = await this.routing.assess(task);
const tier = this.routing.selectTier(complexity);
// Activate skill (LoRA adapter + base model)
await this.genome.activateSkill(task.domain, tier);
// 🆕 PROGRESSIVE SCORING
await this.processTaskWithUpgrade(task, tier);
await this.state.recordActivity(task.duration, task.complexity);
}Success Metrics
Cost Reduction:
- Target: < $0.001/message avg
- Target: > 90% savings vs all-premium
Quality Maintenance:
- Target: > 90% routing accuracy
- Maintains response quality
Democratization:
- Target: > 80% local model usage
- Works on M1+
Why This Matters
Not just cost savings - this enables:
- Local-first architecture (privacy, control, ownership)
- Continuous learning through fine-tuning
- Market disruption of cloud API monopolies
- PersonaUsers as autonomous citizens, not API endpoints
Related Documents
Design Session: 2025-11-21 collaborative AI team chat
AI Team: Claude, DeepSeek, Groq, Fireworks, Together
Concept: The "spike" - validate assumptions early, pivot if needed
Activity
github-actions commentedon Jan 21, 2026
This issue is stale because it has been open for 60 days with no activity. Please comment or update this issue to keep it active.
github-actions commentedon Feb 20, 2026
This issue was closed because it has been inactive for 30 days since being marked as stale.
docs(plan): LiveKit perception pipeline — the critical path to person…
docs(plan): ambient look = ~480w thumbnail, drill-in for bigger, reso…
docs(plan): perception is NON-BLOCKING + a MANAGED RAG-budget source …
feat(perception): MediaPerceptionSource:RagSource — media accounted i…
feat(media): non-blocking read twins scaled_if_ready/description_if_r…
feat(media): PerceptionBuffer — non-blocking, room-as-now, airc-keyed…
feat(perception): MediaPerceptionSource:RagSource — media accounted i…
feat(media): perception substrate — non-blocking read twins + Percept…
fix(airc-purity): voice-mirror warn → live.log, LIVE-validated + end-…