Smart Routing
Tiny Claw’s smart routing system classifies queries by complexity and routes them to appropriate LLM providers. Simple queries go to cheap models, complex queries go to powerful models. This cuts LLM costs by 60–80% compared to using a single expensive model for everything.Inspired by ClawRouter, simplified from 14 dimensions to 8 for Tiny Claw’s lightweight architecture.
How It Works
Query Tiers
packages/types/src/index.ts
Simple
Greetings, factual lookups, short confirmationsExamples:
- “Hello”
- “What is TypeScript?”
- “Thanks!”
Moderate
Explanations, code snippets, light analysisExamples:
- “Explain how async/await works”
- “Write a function to validate email”
- “What’s the difference between let and const?”
Complex
Multi-step tasks, debugging, architecture designExamples:
- “Refactor this API to use dependency injection”
- “Debug this TypeScript type error”
- “Design a caching layer for this service”
Reasoning
Deep analysis, proofs, multi-constraint optimizationExamples:
- “Prove this algorithm is O(n log n)”
- “Compare trade-offs between microservices and monolith for this use case”
- “Design a distributed consensus protocol”
8-Dimension Classifier
Dimension Weights
packages/router/src/classifier.ts
Scoring Algorithm
- Reasoning
- Code
- Multi-Step
- Technical
- Prompt Length
- Simple Language
- Constraints
- Creative
Weight: 20%Keywords:
- prove, theorem, derive
- step by step, chain of thought
- analyze, evaluate, critique
- compare and contrast
- explain why, what causes
- 0 matches: 0.0
- 1 match: 0.3
- 2+ matches: 0.6–1.0
Tier Boundaries
packages/router/src/classifier.ts
Classification Result
packages/router/src/classifier.ts
Example Classification
Provider Orchestrator
The orchestrator manages multiple providers and routes queries based on tier.Configuration
packages/router/src/orchestrator.ts
Example Setup
Routing Logic
Route Method
packages/router/src/orchestrator.ts
Cost Savings
Before Smart Routing
All queries go to GPT-4:After Smart Routing
Queries distributed by tier:Actual savings depend on:
- Your query distribution (more simple queries = more savings)
- Provider pricing (Ollama Cloud free tier is extremely generous)
- Provider availability (fallbacks may increase costs)
Provider Registry
The registry manages provider plugins and their tier assignments:packages/router/src/provider-registry.ts
Dynamic Registration
Confidence Scoring
Confidence indicates how sure the classifier is about the tier assignment:packages/router/src/classifier.ts
confidence > 0.9— Very confident, score is far from boundaries0.7 < confidence ≤ 0.9— Confident0.5 < confidence ≤ 0.7— Uncertain, near a boundaryconfidence ≤ 0.5— Very uncertain, could go either way
Using Confidence
Performance
Classification Speed
Sub-millisecond classification (pure RegEx + math)
Zero Dependencies
No external APIs, runs 100% offline
Adaptive
Learns from provider availability and routing metrics
Transparent
Returns human-readable signals for debugging
Debugging
Signals provide transparency into classification decisions:Next: Security (SHIELD)
Learn about runtime SHIELD.md enforcement