feat: implement smart model routing (length + tools + perplexity + OH CRAP escalate) #2
Labels
No labels
blocked:gate-research
blocked:needs-decision
blocked:needs-human
blocked:no-changes
bug
documentation
enhancement
feature-request
in-progress
quickfix
research
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/infrastructure#2
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Feature Request: Smart Model Routing
Date: 2026-05-04
Status: Proposed
Summary
Implement smart model routing beyond the existing dead-config keys. Current smart_model_routing config is accepted but has no implementation.
Routing Criteria (3-stage)
1. Length Threshold
len(msg) <= max_simple_chars AND word_count <= max_simple_words
2. Tool Complexity Heuristic
No tool calls needed -> cheap model
Complex multi-step / many tools -> primary (powerful) model
3. Perplexity Scoring (optional)
Use a small local model to score message simplicity (cross-entropy). If perplexity > perplexity_threshold -> escalate to primary. Config: perplexity_model: Qwen3.5-0.8B-Q4KM (local, no API cost).
Escalation Path (OH CRAP)
When cheap model fails, automatically retry with primary model:
Proposed Config
smart_model_routing:
enabled: true
max_simple_chars: 160
max_simple_words: 28
perplexity_threshold: 2.5
perplexity_model: Qwen3.5-0.8B-Q4KM
cheap_model:
provider: vllm-mm
model: GPT-OSS-20B-Q4KM
escalate_on_error: true
Implementation
File: run_agent.py
Hook: After conversation turn log (~line 10281), before first LLM call
Swap self.model + self.provider if conditions met
Escalation: catch crash/429/timeout, retry with saved primary model
Evidence (Bug Report)
See: issues/smart-model-routing-not-implemented.md
Tags
#hermes #feature #routing #cost-optimization