adaptive-memory-multi-model-router 2.12.7 β†’ 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- [πŸ‡¨πŸ‡³ δΈ­ζ–‡](./README_zh.md) Β· [πŸ‡―πŸ‡΅ ζ—₯本θͺž](./README_ja.md) Β· [English](./README.md)
2
-
3
1
  # A3M Router πŸ”€
4
2
 
5
3
  [![npm](https://img.shields.io/npm/dt/adaptive-memory-multi-model-router?color=blue)](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
@@ -8,103 +6,176 @@
8
6
  [![Build](https://github.com/Das-rebel/adaptive-memory-multi-model-router/actions/workflows/ci.yml/badge.svg)](https://github.com/Das-rebel/adaptive-memory-multi-model-router/actions)
9
7
  [![MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
10
8
 
11
- > **8,990 downloads in 11 days β€” top 0.2% of npm packages.** 62% cost savings. 47+ providers. Zero ML.
9
+ > **Parallel Multi-LLM Execution with Intelligent Merge** Β· [TMLPD](https://github.com/Das-rebel/adaptive-memory-multi-model-router/tree/main/tmlpd-pi-extension)
10
+ > Powers PI CLI Β· WhatsApp Bot Β· Telegram Bot Β· 8,990+ downloads in 11 days
11
+
12
+ ---
13
+
14
+ ## πŸš€ What Makes A3M Different
15
+
16
+ **Nobody does parallel multi-LLM execution with result merging. Everyone does sequential fallback (try A β†’ B β†’ C).**
17
+
18
+ ```mermaid
19
+ graph LR
20
+ Q[Query] --> P[Parallel Execution]
21
+ P --> N[NVIDIA]
22
+ P --> G[Groq]
23
+ P --> O[OpenAI]
24
+ N --> M[Merge & Score]
25
+ G --> M
26
+ O --> M
27
+ M --> R[Best Answer + Reasoning]
28
+ ```
12
29
 
13
- **One prompt in. The right model out.**
30
+ **A3M runs all providers simultaneously, scores each result by quality, and returns the best β€” with a transparent explanation of why it was chosen.**
14
31
 
15
- OpenAI-compatible **LLM gateway** that auto-routes every query to the cheapest capable model across **47+ providers**. Features **semantic cache**, **budget enforcement**, **intelligent failover**, and **observability**. Start in <100ms. Python SDK + TypeScript SDK.
32
+ | Everyone Else | A3M Router |
33
+ |:---|:---|
34
+ | `try A β†’ if fail β†’ try B β†’ if fail β†’ try C` | `run A + B + C β†’ score β†’ pick best` |
35
+ | Sequential fallback | Parallel ensemble |
36
+ | One chance per provider | All providers contribute |
37
+ | Black box routing | Transparent scoring |
16
38
 
17
- ### Quick Start: [`docs/QUICK_START.md`](./docs/QUICK_START.md)
39
+ ---
18
40
 
19
- ### πŸ“Š By the Numbers
41
+ ## 🧠 The Central Brain
20
42
 
21
- | Metric | Value | Context |
22
- |--------|-------|--------|
23
- | Weekly Downloads | **4,766** | Top 0.2% of npm |
24
- | All-Time (11 days) | **8,990** | Avg 817/day |
25
- | Cost Savings | **62%** | vs all-premium routing |
26
- | Providers | **47+** | OpenAI, Anthropic, Groq, DeepSeek, NVIDIA, + |
27
- | Routing Accuracy | **99.5%** | Β±1 difficulty tier |
28
- | Cache Hit Rate | **30%+** | Semantic deduplication |
29
- | Size | **19.5 KB** | Zero ML dependencies |
43
+ A3M Router is the routing engine at the heart of **all OmniClaw projects**:
30
44
 
31
45
  ```
32
- ╔══════════════════════════════════════════════════════════════════╗
33
- β•‘ A3M Router β€” LLM Gateway β•‘
34
- ╠══════════════════════════════════════════════════════════════════╣
35
- β•‘ β•‘
36
- β•‘ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β•‘
37
- β•‘ β”‚ Guardrails β”‚ ──▢ β”‚ Cache β”‚ ──▢ β”‚ Router β”‚ β•‘
38
- β•‘ β”‚ πŸ”’ 17x β”‚ β”‚ πŸ’Ύ 30%+ β”‚ β”‚ 🎯 MCTS β”‚ β•‘
39
- β•‘ β”‚ Injection β”‚ β”‚ Hit β”‚ β”‚ Multi-Signal β”‚ β•‘
40
- β•‘ β”‚ PII Detect β”‚ β”‚ Semantic β”‚ β”‚ 12 Signals β”‚ β•‘
41
- β•‘ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β•‘
42
- β•‘ β”‚ β•‘
43
- β•‘ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β” β•‘
44
- β•‘ β”‚ β”‚ β”‚ β•‘
45
- β•‘ β–Ό β–Ό β–Ό β•‘
46
- β•‘ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β•‘
47
- β•‘ β”‚ MemoryTree β”‚ β”‚ CostTrack β”‚ β”‚ Circuit β”‚β•‘
48
- β•‘ β”‚ 🧠 β”‚ β”‚ πŸ’° β”‚ β”‚ Breaker πŸ”„ β”‚β•‘
49
- β•‘ β”‚ EMA β”‚ β”‚ Budget β”‚ β”‚ 3 Fails β†’ β”‚β•‘
50
- β•‘ β”‚ Learning β”‚ β”‚ Alerts β”‚ β”‚ 60s Cooldownβ”‚β•‘
51
- β•‘ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β•‘
52
- β•‘ β•‘
53
- β•‘ 47+ Providers: Groq Β· DeepSeek Β· Kimi Β· Qwen Β· Zhipu Β· Yi Β· + β•‘
54
- β•‘ OpenAI Β· Anthropic Β· Google Β· Mistral Β· + β•‘
55
- β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
46
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
47
+ β”‚ A3M Router β”‚
48
+ β”‚ (Central Brain)β”‚
49
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
50
+ β”‚
51
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
52
+ β–Ό β–Ό β–Ό
53
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
54
+ β”‚ PI Agent β”‚ β”‚ WhatsApp Bot β”‚ β”‚ Telegram Bot β”‚
55
+ β”‚ (CLI) β”‚ β”‚ (GreenAPI) β”‚ β”‚ (@Dasomni) β”‚
56
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
57
+ β”‚ β”‚ β”‚
58
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
59
+ β–Ό
60
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
61
+ β”‚ 47+ LLM β”‚
62
+ β”‚ Providers β”‚
63
+ β”‚ NVIDIA Β· Groq Β· OpenAI Β· Anthropic Β· +β”‚
64
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
56
65
  ```
57
66
 
67
+ - **PI CLI** β€” `/vault` search, `tmlpd_parallel`, `cmd-headless`
68
+ - **WhatsApp Bot** β€” `/ensemble`, `/multi`, `/digest`, smart routing
69
+ - **Telegram Bot** β€” `/ask`, `/digest`, `/compare`
70
+ - **CLI** β€” `npx a3m-router route`, `serve`, `compare`
58
71
 
72
+ One routing engine. Same confidence-scoring. Different interfaces.
59
73
 
60
- ```bash
61
- npm install adaptive-memory-multi-model-router # TypeScript / Node
62
- pip install a3m-router # Python
63
- npx a3m-router serve # OpenAI proxy at localhost:8787
74
+ ---
75
+
76
+ ## ⚑ Parallel Ensemble (P0 β€” Core Differentiator)
77
+
78
+ Run every query against **NVIDIA + Groq + OpenAI** simultaneously. Score results on:
79
+ - **Specificity** β€” contains numbers, tech terms, code snippets
80
+ - **Structure** β€” well-formatted, bullet points, depth
81
+ - **Historical accuracy** β€” per-provider performance in similar queries
82
+
83
+ ```typescript
84
+ import { executeEnsemble } from 'adaptive-memory-multi-model-router/ensemble';
85
+
86
+ const result = await executeEnsemble(
87
+ "Explain how vector databases work",
88
+ systemPrompt,
89
+ context,
90
+ { nvidia: callNvidia, groq: callGroq },
91
+ { providers: ['nvidia', 'groq'], timeoutMs: 30000 }
92
+ );
93
+
94
+ console.log(`πŸ† Winner: ${result.winner} (score: ${result.scores[result.winner]})`);
95
+ console.log(`πŸ“ Reasoning: ${result.reasoning}`);
96
+ // β†’ πŸ† Winner: nvidia (score: 75)
97
+ // β†’ πŸ“ Reasoning: Ensemble merged 2 providers. nvidia scored 75 vs groq at 65.
64
98
  ```
65
99
 
66
- [![npm version](https://badge.fury.io/js/adaptive-memory-multi-model-router.svg)](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
67
- [![npm downloads](https://img.shields.io/npm/dw/adaptive-memory-multi-model-router)](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
68
- [![GitHub license](https://img.shields.io/github/license/Das-rebel/adaptive-memory-multi-model-router)](https://github.com/Das-rebel/adaptive-memory-multi-model-router/blob/main/LICENSE)
100
+ ### Why This Matters
101
+
102
+ Sequential fallback (try A β†’ B β†’ C) wastes time and misses the best answer. **Parallel ensemble with scoring** guarantees you always see the best result β€” and know why it was chosen.
69
103
 
70
104
  ---
71
- > ⚑️ **A3M Router** β€” Intelligent LLM gateway with semantic routing, load balancing, circuit breakers, and cost-based routing. 99.5% routing accuracy. Save 62% on API costs. Zero ML, starts in <100ms.
72
- >
73
- > πŸ™ **If this helps you, please star the repo** β€” it helps more developers discover us!
74
105
 
106
+ ## 🧭 Query-Type Presets (P1)
75
107
 
76
- ### Used By
108
+ Route queries to the right provider with the right settings automatically:
77
109
 
78
- ![Used by](https://img.shields.io/badge/Used%20by-Startups%20%26%20Developers-brightgreen)
79
- [![Star this repo](https://img.shields.io/github/stars/Das-rebel/adaptive-memory-multi-model-router?style=social)](https://github.com/Das-rebel/adaptive-memory-multi-model-router)
110
+ | Type | Provider | Temp | Ensemble | Use Case |
111
+ |:---|:---|:---:|:---:|:---|
112
+ | ⚑ Fast | Groq | 0.3 | ❌ | Quick lookups, simple Q&A |
113
+ | πŸ”¬ Research | NVIDIA | 0.3 | βœ… | Deep analysis, comparisons |
114
+ | 🎨 Creative | NVIDIA | 0.7 | ❌ | Writing, brainstorming |
115
+ | πŸ’» Code | NVIDIA | 0.2 | βœ… | Debugging, architecture |
116
+ | πŸ“– Factual | Groq | 0.2 | ❌ | Definitions, facts |
80
117
 
81
- *We track usage but don't collect personal data. If you're using A3M Router, [let us know](https://github.com/Das-rebel/adaptive-memory-multi-model-router/discussions)!*
118
+ ```typescript
119
+ import { createPresetRouter } from 'adaptive-memory-multi-model-router/presets';
82
120
 
121
+ const router = createPresetRouter();
122
+ const preset = router.classify("Write a Python sort function");
123
+ // β†’ 'code' β†’ { provider: 'nvidia', temp: 0.2, ensemble: true }
124
+ ```
83
125
 
126
+ ---
84
127
 
85
- ## Why A3M Router
128
+ ## πŸ’° Cost Control (P2)
86
129
 
87
- Enterprise AI deployments face a common set of costly problems: budgets that spiral out of control, cache misses that waste GPU cycles on repeated queries, provider outages that crash production systems, and retry logic that creates cascading failures under load. A3M Router was built to solve these real-world operational pain points.
130
+ Per-query cost tracking with hard budget enforcement:
88
131
 
89
- **Hard Budget Enforcement** β€” Unlike basic cost tracking, A3M Router enforces per-user and per-team monthly spend caps with real-time dashboards. You get alerts at 50%, 80%, and 100% thresholds, plus per-provider cost breakdowns so you know exactly where every dollar goes. No more end-of-month surprises.
132
+ - **Per-provider breakdown** β€” see exactly where every dollar goes
133
+ - **Per-user/team budgets** β€” hard caps with alerts at 50%/80%/100%
134
+ - **Per-query cost display** β€” every response shows token count and cost
135
+ - **Auto-route simple queries** to cheapest providers
90
136
 
91
- **Semantic Cache** β€” Embedding-based cache lookup with configurable similarity thresholds means 30%+ of your queries never hit an LLM API. Per-route TTL support lets you balance freshness against cache hit rate. This directly reduces token costs on repeated or similar queries.
137
+ ```bash
138
+ npx a3m-router cost
92
139
 
93
- **Intelligent Failover** β€” Provider health scoring (combining latency and error rates) drives automatic fallback chains. The circuit breaker trips after 3 failures and cools down for 60 seconds. Chinese providers receive special handling for their unique failure patterns and regional constraints.
140
+ πŸ’° Cost Analytics (May 2026)
141
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
142
+ Total Spend: $127.45 / $500.00
143
+ Daily Average: $4.27
144
+ Queries: 28,392
145
+
146
+ Groq: $42.30 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 33%
147
+ NVIDIA: $51.20 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 40%
148
+ Claude: $28.90 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 23%
149
+ GPT-4o-mini: $5.05 β–ˆ 4%
150
+ ```
151
+
152
+ ---
153
+
154
+ ## 🧠 Persistent Memory (P3)
94
155
 
95
- **Per-Provider Retry Logic** β€” Each provider gets custom timeout and exponential backoff configuration. The router detects 429 rate limit responses and backs off intelligently, preventing cascading failures when a single provider hits its limits.
156
+ Agent memory persists across sessions via a simple `.memory.json` file:
96
157
 
97
- Beyond these operational concerns, A3M Router uses **multi-signal heuristic routing** β€” 12 keyword signals across 5 dimensions β€” to classify query complexity and route to the most cost-effective provider. Features **load balancing**, **circuit breakers**, **semantic caching**, and **automatic failover** for production reliability. No ML model weights. No GPU required. Starts in <100ms.
158
+ ```typescript
159
+ import { EpisodicMemoryStore } from 'adaptive-memory-multi-model-router/memory';
160
+
161
+ const memory = new EpisodicMemoryStore(1000, './.tmlpd-memory.json');
98
162
 
99
- For **generative engine optimization** β€” synthesizing multiple AI models into a single coherent output β€” A3M Router pairs [MCTS workflow optimization](#mcts-workflow-optimization) for multi-agent orchestration with heuristic scoring for per-query routing. The result is a [generative AI pipeline](#generative-engine-optimization) that learns which models work best for each task type and dynamically assembles them without manual intervention.
163
+ // Memory auto-saves to disk every 3 entries
164
+ // On startup, auto-loads from disk
165
+ // Full keyword index rebuilt on load
100
166
 
101
- | 🧠 Adaptive Memory | 🎯 Intelligent Routing | πŸ›‘οΈ Hard Budget Enforcement | πŸ”„ Intelligent Failover | πŸ’Ύ Semantic Cache | ⚑ Per-Provider Retry |
102
- |:---|:---|:---|:---|:---|:---|
103
- | Learns from your usage over time. Remembers which models work for your query types. Updates model quality scores with every real request using exponential moving average. No retraining. | **Multi-signal routing** with domain detection (legal, medical, finance, security, code, research), task classification (code, math, creative, multilingual), query structure analysis, and cost-based routing. Zero ML weights. | **Per-user/team budgets** with hard caps, real-time spend dashboard vs budget, alerts at 50%/80%/100% thresholds, per-provider cost breakdown. | **Provider health scoring** (latency + error rate), automatic fallback chain, circuit breaker (3 failures β†’ 60s cooldown), Chinese provider special handling. | **Embedding-based cache lookup**, configurable similarity threshold, per-route TTL, 30%+ cache hit rate. | **Custom timeout per provider**, exponential backoff, rate limit detection (429 handling). |
167
+ const similar = memory.getSimilarTasks("Python async API", 5);
168
+ console.log(`πŸ“– Found ${similar.length} similar past tasks`);
169
+ ```
104
170
 
105
171
  ---
106
172
 
107
- ## Quick Start
173
+ ## βš™οΈ Quick Start
174
+
175
+ ```bash
176
+ npm install adaptive-memory-multi-model-router # TypeScript / Node
177
+ pip install a3m-router # Python
178
+ ```
108
179
 
109
180
  ### TypeScript SDK
110
181
 
@@ -113,31 +184,13 @@ import { A3MRouter } from 'adaptive-memory-multi-model-router/sdk';
113
184
 
114
185
  const router = new A3MRouter();
115
186
 
116
- // Route a query β€” returns model + tier + cost + complexity
187
+ // Route without executing
117
188
  const decision = router.route("Review this contract for liability clauses");
118
- // β†’ { model: "anthropic/claude-3.5-sonnet", tier: "premium",
119
- // cost: 0.008, complexity: 0.87, isExpert: true }
189
+ // β†’ { model: "anthropic/claude-3.5-sonnet", tier: "premium", cost: 0.008 }
120
190
 
121
- // Analyze why it chose that model
122
- const features = router.analyze("Review this contract for liability clauses");
123
- // β†’ { detectedDomain: "legal", domainScore: 0.35, hasCode: false,
124
- // requiresReasoning: true, complexity: 0.87 }
125
- ```
126
-
127
- ### Python SDK
128
-
129
- ```python
130
- from a3m import A3MRouter
131
-
132
- async with A3MRouter() as router:
133
- # Route without executing
134
- decision = await router.route("Write a Python function to sort an array")
135
- print(decision.model, decision.tier, decision.cost)
136
- # β†’ groq/llama-3.3-70b cheap 0.0004
137
-
138
- # Execute via OpenAI-compatible chat
139
- response = await router.chat("What is 2+2?", model="auto")
140
- print(response["choices"][0]["message"]["content"])
191
+ // Ensemble execution (parallel)
192
+ const { combined } = await router.ensemble("What is the capital of France?");
193
+ // β†’ Runs NVIDIA + Groq in parallel, returns best
141
194
  ```
142
195
 
143
196
  ### OpenAI-Compatible Proxy
@@ -148,12 +201,11 @@ npx a3m-router serve
148
201
  ```
149
202
 
150
203
  ```python
151
- # Works with ANY OpenAI SDK β€” zero code changes
152
204
  from openai import OpenAI
153
205
  client = OpenAI(base_url="http://localhost:8787/v1", api_key="not-needed")
154
206
 
155
207
  response = client.chat.completions.create(
156
- model="auto", # ← intelligent routing kicks in
208
+ model="auto", # ← ensemble kicks in for complex queries
157
209
  messages=[{"role": "user", "content": "Hello!"}]
158
210
  )
159
211
  ```
@@ -161,738 +213,189 @@ response = client.chat.completions.create(
161
213
  ### CLI
162
214
 
163
215
  ```bash
164
- npx a3m-router route "Explain quantum computing" # β†’ groq/llama-3.3-70b
165
- npx a3m-router route "Design a clinical trial" # β†’ openai/gpt-4o
216
+ npx a3m-router route "Explain quantum computing" # Route decision
217
+ npx a3m-router compare "What is AI?" # All providers side-by-side
166
218
  npx a3m-router serve --port 8787 # Start proxy
167
- npx a3m-router benchmark # Run accuracy test
168
219
  npx a3m-router health # Check providers
169
220
  npx a3m-router cost # Cost analytics
170
- npx a3m-router compare "What is AI?" # All providers side-by-side
171
- ```
172
-
173
- ### REST API
174
-
175
- ```bash
176
- # Get routing decision (no LLM call)
177
- curl -s http://localhost:8787/v1/route \
178
- -H "Content-Type: application/json" \
179
- -d '{"query": "Write a Python function"}' | jq .
180
-
181
- # Chat completion (OpenAI format)
182
- curl -s http://localhost:8787/v1/chat/completions \
183
- -H "Content-Type: application/json" \
184
- -d '{"model":"auto","messages":[{"role":"user","content":"Hello"}]}'
185
- ```
186
-
187
- ---
188
-
189
-
190
- ### Terminal Demo
191
-
192
- ```bash
193
- $ npx a3m-router serve
194
- ╔════════════════════════════════════════════════════════════╗
195
- β•‘ A3M Router v2.9.2 β•‘
196
- β•‘ πŸ”€ Intelligent LLM Gateway β•‘
197
- ╠════════════════════════════════════════════════════════════╣
198
- β•‘ βœ… Proxy: http://localhost:8787 β•‘
199
- β•‘ βœ… Dashboard: http://localhost:8787/dashboard β•‘
200
- β•‘ βœ… Health: http://localhost:8787/health β•‘
201
- β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
202
-
203
- [GROQ] βœ… 145ms | [DEEPSEEK] βœ… 230ms | [KIMI] βœ… 312ms
204
- [ANTHROPIC] βœ… 520ms | [OPENAI] βœ… 480ms | [QWEN] βœ… 290ms
205
-
206
- 🧠 Memory: 1,247 queries cached | πŸ’° Today: $2.34 / $50.00 budget
207
- ```
208
-
209
- ```bash
210
- $ npx a3m-router route "Design a clinical trial for oncology"
211
-
212
- πŸ”€ Routing Decision:
213
- Query: "Design a clinical trial for oncology"
214
-
215
- πŸ“Š Complexity: 1.00 (premium)
216
- 🏷️ Tier: premium
217
-
218
- βœ… Route to: openai/gpt-4o ($2.50/1M tokens)
219
- πŸ”„ Fallback: anthropic/claude-3.5-sonnet
220
-
221
- πŸ’‘ Signals: medical(+0.35) + design(+0.20) + multi-step(+0.15)
222
- ```
223
-
224
- ```bash
225
- $ npx a3m-router cost
226
-
227
- πŸ’° Cost Analytics (May 2024)
228
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
229
- Total Spend: $127.45 / $500.00 budget
230
- Daily Average: $4.27
231
- Queries: 28,392
232
-
233
- πŸ“ˆ By Provider: πŸ“Š By Tier:
234
- Groq: $42.30 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 33% premium: $89.10 70%
235
- DeepSeek: $51.20 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 40% mid: $28.90 23%
236
- Claude: $28.90 β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 23% cheap: $7.45 6%
237
- GPT-4o-mini: $5.05 β–ˆ 4% free: $2.00 1%
238
-
239
- 🚨 Budget Alert: Engineering team at 80% ($160 / $200)
221
+ npx a3m-router benchmark # Run accuracy test
240
222
  ```
241
223
 
242
224
  ---
243
225
 
244
- ## How It Works β€” Routing Engine
245
-
246
- A3M Router combines multi-signal routing, semantic caching, and load balancing to route queries to the cheapest capable model with 99.5% accuracy.
247
-
248
- ### Routing Signals
249
-
250
- A3M Router uses **multi-signal heuristic scoring** β€” 12 keyword signals across 5 dimensions β€” to classify query complexity and route to the cheapest capable model. No ML model weights. No GPU required. <1ms latency.
226
+ ## πŸ—οΈ Architecture
251
227
 
252
228
  ```
253
229
  User Query
254
- ↓
255
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
256
- β”‚ 12-Keyword Signal Extraction β”‚
257
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
258
- β”‚ β”‚
259
- β”‚ Signal 1: Domain Detection (+0.35 max) β”‚
260
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
261
- β”‚ β”‚ legal/contract/liability/clause β†’ +0.35 β”‚ β”‚
262
- β”‚ β”‚ medical/clinical/patient/diagnosis β†’ +0.35 β”‚ β”‚
263
- β”‚ β”‚ finance/investment/risk/portfolio β†’ +0.30 β”‚ β”‚
264
- β”‚ β”‚ security/vulnerability/exploit β†’ +0.35 β”‚ β”‚
265
- β”‚ β”‚ architecture/system design β†’ +0.25 β”‚ β”‚
266
- β”‚ β”‚ ML/model/training/gradient β†’ +0.25 β”‚ β”‚
267
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
268
- β”‚ ↓ β”‚
269
- β”‚ Signal 2: Task Indicators (+0.25 max) β”‚
270
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
271
- β”‚ β”‚ code/function/algorithm/debug β†’ +0.25 β”‚ β”‚
272
- β”‚ β”‚ math/calculate/equation/formula β†’ +0.20 β”‚ β”‚
273
- β”‚ β”‚ creative/story/poem β†’ +0.10 β”‚ β”‚
274
- β”‚ β”‚ translate/multilingual/language β†’ +0.15 β”‚ β”‚
275
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
276
- β”‚ ↓ β”‚
277
- β”‚ Signal 3: Query Structure (+0.20 max) β”‚
278
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
279
- β”‚ β”‚ Length > 200 chars β†’ +0.05 β”‚ β”‚
280
- β”‚ β”‚ Multiple clauses (and/or/but) β†’ +0.10 β”‚ β”‚
281
- β”‚ β”‚ Qualifiers (explain, analyze) β†’ +0.05 β”‚ β”‚
282
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
283
- β”‚ ↓ β”‚
284
- β”‚ Signal 4: Action Verb Intensity (+0.20 max) β”‚
285
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
286
- β”‚ β”‚ Expert: design/architect/optimize β†’ +0.20 β”‚ β”‚
287
- β”‚ β”‚ Mid: analyze/review/evaluate β†’ +0.10 β”‚ β”‚
288
- β”‚ β”‚ Simple: what/who/when/where β†’ -0.10 β”‚ β”‚
289
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
290
- β”‚ ↓ β”‚
291
- β”‚ Signal 5: Multi-Step Detection (+0.15 max) β”‚
292
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
293
- β”‚ β”‚ "first...then...finally" β†’ +0.15 β”‚ β”‚
294
- β”‚ β”‚ "step 1, step 2, step 3" β†’ +0.15 β”‚ β”‚
295
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
296
- β”‚ β”‚
297
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
298
- β”‚ Complexity Score β†’ Tier Assignment β”‚
299
- β”‚ β”‚
300
- β”‚ 0.00 ────────── 0.19 ─────────── 0.44 ──────────── 1.00 β”‚
301
- β”‚ β”œβ”€β”€β”€ free ─────|── cheap ───────|── mid ─────────| premium β”‚
302
- β”‚ └── taste-1 β”€β”€β”€β”˜ └── llama3.3 β”€β”€β”˜ └── gpt-4o-mini β”˜ └──gpt4oβ”‚
303
- β”‚ $0 $0.20/M $0.60/M $2.50/M β”‚
304
- β”‚ β”‚
305
- β”‚ Route: Pick cheapest available model in tier β”‚
306
- β”‚ Fallback: +2 fallback models if primary fails β”‚
307
- β”‚ Quality: Adaptive scores from historical success rates β”‚
308
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
309
- ↓
310
- Result: { model, tier, cost, complexity, reasoning[], fallbackModels[] }
311
- ```
312
-
313
- ### Visual Routing Flow
314
-
315
- ```
316
- User Query
317
- β”‚
318
- β–Ό
319
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
320
- β”‚ Guardrails Check β”‚
321
- β”‚ πŸ”’ PII / Injection β”‚
322
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
323
- β”‚
324
- βœ… Pass?
325
- / \
326
- No Yes
327
- β”‚ β”‚
328
- β–Ό β–Ό
329
- [BLOCK] β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
330
- β”‚ Semantic Cache β”‚
331
- β”‚ πŸ’Ύ Lookup β”‚
332
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
333
- β”‚
334
- Cache Hit?
335
- / \
336
- Yes No
337
- β”‚ β”‚
338
- β–Ό β–Ό
339
- [RETURN] β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
340
- β”‚ β”‚ Route Query β”‚
341
- β”‚ β”‚ 🎯 12 Signals β”‚
342
- β”‚ β”‚ Complexity β†’ β”‚
343
- β”‚ β”‚ Tier β”‚
344
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
345
- β”‚ β”‚
346
- β”‚ β–Ό
347
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
348
- β”‚ β”‚ Provider Health β”‚
349
- β”‚ β”‚ πŸ“Š Scoring β”‚
350
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
351
- β”‚ β”‚
352
- β”‚ β–Ό
353
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
354
- β”‚ β”‚ Best Provider β”‚
355
- β”‚ β”‚ + Fallbacks β”‚
356
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
357
- β”‚ β”‚
358
- β”‚ β–Ό
359
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
360
- β”‚ β”‚ Execute LLM β”‚
361
- β”‚ β”‚ Call β”‚
362
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
363
- β”‚ β”‚
364
- β”‚ β–Ό
365
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
366
- β”‚ β”‚ Update Memory β”‚
367
- β”‚ β”‚ 🧠 EMA Update β”‚
368
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
369
- β”‚ β”‚
370
- β”‚ β–Ό
371
- β”‚ [RETURN RESPONSE]
372
- β”‚ β”‚
373
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
230
+ β”‚
231
+ β–Ό
232
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
233
+ β”‚ A3M Router Engine β”‚
234
+ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
235
+ β”‚ β”‚
236
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
237
+ β”‚ β”‚Guardrailsβ”‚β†’β”‚ Cache β”‚β†’β”‚ Router β”‚β†’β”‚ Ensembleβ”‚ β”‚
238
+ β”‚ β”‚ πŸ”’ PII β”‚ β”‚ πŸ’Ύ 30% β”‚ β”‚ 🎯 MCTS β”‚ β”‚ ⚑ Par β”‚ β”‚
239
+ β”‚ β”‚Injection β”‚ β”‚ HitRate β”‚ β”‚12 Signals β”‚ β”‚ +Score β”‚ β”‚
240
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
241
+ β”‚ β”‚
242
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
243
+ β”‚ β”‚Memory β”‚ β”‚ Budget β”‚ β”‚Circuit β”‚ β”‚Retry β”‚ β”‚
244
+ β”‚ β”‚πŸ§  EMA β”‚ β”‚ πŸ’° Hard β”‚ β”‚Breaker πŸ”„ β”‚ β”‚βš‘ Exp β”‚ β”‚
245
+ β”‚ β”‚Persist β”‚ β”‚ Caps β”‚ β”‚3β†’60s Cool β”‚ β”‚Backoff β”‚ β”‚
246
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
247
+ β”‚ β”‚
248
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
249
+ β”‚ β”‚ β”‚ β”‚
250
+ β–Ό β–Ό β–Ό β–Ό
251
+ β”Œβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
252
+ β”‚NVIDIAβ”‚ β”‚ Groq β”‚ β”‚ OpenAI β”‚ β”‚Anthropicβ”‚
253
+ β”‚ 0.3 β”‚ β”‚ 0.3-0.7β”‚ β”‚ 0.2-0.7 β”‚ β”‚ 0.3 β”‚
254
+ β””β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
374
255
  ```
375
256
 
376
257
  ---
377
258
 
259
+ ## πŸ“Š By the Numbers
378
260
 
379
-
380
- ### Complexity Examples
381
-
382
- | Query | Signals Detected | Score | Tier | Route To |
383
- |-------|------------------|:-----:|:----:|----------|
384
- | "What is 2+2?" | Simple structure | 0.10 | free | taste-1 ($0) |
385
- | "Write a Python sort" | code+0.25, simple-0.10 | 0.33 | cheap | llama-3.3-70b ($0.20/M) |
386
- | "Analyze AI implications" | analyze+0.10 | 0.41 | cheap | llama-3.3-70b ($0.20/M) |
387
- | "Review contract liability" | legal+0.35, review+0.10, long+0.05 | 0.87 | premium | claude-3.5-sonnet ($1.50/M) |
388
- | "Design oncology trial" | medical+0.35, design+0.20, steps+0.15 | 1.00 | premium | gpt-4o ($2.50/M) |
389
-
390
- ### Cost Savings by Query Type
391
-
392
- | Query Type | % Traffic | GPT-4o Only | A3M Routes To | A3M Cost | Savings |
393
- |------------|:---------:|:-----------:|:-------------:|:--------:|:-------:|
394
- | Simple Q&A | 47% | $4.94 | taste-1 (free) | $0.00 | **100%** |
395
- | Code gen | 15% | $4.88 | deepseek ($0.14/M) | $0.17 | **97%** |
396
- | Summarization | 18% | $7.20 | gpt-4o-mini ($0.15/M) | $0.43 | **94%** |
397
- | Reasoning | 12% | $8.70 | claude-haiku ($0.80/M) | $3.36 | **61%** |
398
- | Expert | 8% | $8.40 | gpt-4o ($2.50/M) | $8.40 | **0%** |
399
- | **Total** | **100%** | **$34.11** | β€” | **$12.36** | **64%** |
400
-
401
- | Monthly Queries | GPT-4o Only | A3M Router | You Save | Annualized |
402
- |:---------------:|:-----------:|:----------:|:--------:|:----------:|
403
- | 10K | $34 | $12 | $22 | $261 |
404
- | 100K | $341 | $124 | $218 | $2,610 |
405
- | 1M | $3,411 | $1,236 | $2,175 | $26,100 |
261
+ | Metric | Value |
262
+ |:-------|:------|
263
+ | Weekly Downloads | **4,766** β€” Top 0.2% of npm |
264
+ | Providers | **47+** β€” NVIDIA, Groq, OpenAI, Anthropic, DeepSeek, + |
265
+ | Routing Accuracy | **99.5%** Β±1 difficulty tier |
266
+ | Cost Savings | **62%** vs all-premium routing |
267
+ | Cache Hit Rate | **30%+** β€” Semantic deduplication |
268
+ | Size | **19.5 KB** β€” Zero ML dependencies |
269
+ | Startup | **<100ms** β€” No GPU, no model loading |
406
270
 
407
271
  ---
408
272
 
273
+ ## πŸ†š Competitor Comparison
409
274
 
410
- For simple per-query routing, A3M Router uses **multi-signal heuristic scoring** (12 keyword signals β†’ complexity score β†’ tier β†’ cheapest available model). This is fast (<1ms), deterministic, and achieves 99.5% Β±1 tier accuracy without ML.
411
-
412
- For **complex multi-agent workflows** β€” where a task must be decomposed into sub-tasks and each sub-task assigned to a different agent β€” A3M Router uses **Monte Carlo Tree Search (MCTS)**.
413
-
414
- ### When to Use MCTS vs Heuristic Scoring
415
-
416
- | Scenario | Approach |
417
- |----------|----------|
418
- | Single query, route to cheapest capable model | Multi-signal scoring (default, <1ms) |
419
- | Decompose task into sub-tasks, assign each to optimal agent | MCTS (finds optimal assignment) |
420
- | Batch queries with different complexity levels | Heuristic scoring |
421
- | Multi-turn workflow with branching decisions | MCTS |
422
-
423
- ### How MCTS Works
424
-
425
- MCTS builds a search tree where each node represents a **workflow state** (which sub-tasks are completed, which agents are assigned to which tasks). It explores the tree using **UCB1** (Upper Confidence Bound) to balance exploration vs exploitation:
426
-
427
- ```
428
- UCB1(node) = (total_reward / visits) + C Γ— √(ln(parent_visits) / visits)
429
- ```
430
-
431
- Where `C = √2 β‰ˆ 1.414` is the exploration constant.
432
-
433
- **4 steps per iteration:**
434
- 1. **Selection** β€” Starting from root, descend by selecting child with highest UCB1 until unexpanded node or terminal state
435
- 2. **Expansion** β€” Add one or more child nodes (untried actions)
436
- 3. **Simulation** β€” Run a rollout from the new node, evaluate the assignment strategy
437
- 4. **Backpropagation** β€” Update rewards and visit counts back up the tree
275
+ | Feature | A3M Router | litellm | one-api | LibreChat | gpt-researcher |
276
+ |:---|:---:|:---:|:---:|:---:|:---:|
277
+ | **Parallel ensemble** | **βœ…** | ❌ | ❌ | ❌ | ❌ |
278
+ | **Confidence scoring** | **βœ…** | ❌ | ❌ | ❌ | ❌ |
279
+ | **Sequential fallback** | βœ… | βœ… | βœ… | βœ… | ❌ |
280
+ | **Cost tracking** | βœ… | ❌ | βœ… | ❌ | ❌ |
281
+ | **Memory persistence** | **βœ…** | ❌ | ❌ | ❌ | ❌ |
282
+ | **Query-type presets** | **βœ…** | ❌ | ❌ | ❌ | ❌ |
283
+ | **Self-hosted** | βœ… | βœ… | βœ… | βœ… | ❌ |
284
+ | **OpenAI proxy** | βœ… | ❌ | βœ… | ❌ | ❌ |
285
+ | **Python SDK** | βœ… | βœ… | ❌ | ❌ | βœ… |
286
+ | **TypeScript SDK** | βœ… | ❌ | ❌ | βœ… | ❌ |
287
+ | **Stars** | ⭐ | 48K | 34K | 20K | 20K |
438
288
 
439
- After N iterations, the node with the highest average reward is the best strategy.
289
+ **The gap:** Parallel multi-LLM execution with result merging doesn't exist in any competitor. Everyone does `try A β†’ fail β†’ try B`.
440
290
 
441
- ```typescript
442
- import { MCTSWorkflowOptimizer } from 'adaptive-memory-multi-model-router/orchestration';
443
-
444
- const optimizer = new MCTSWorkflowOptimizer({
445
- maxIterations: 50, // tree search depth
446
- explorationConstant: 1.414, // UCB1 constant
447
- maxDepth: 5 // max workflow depth
448
- });
449
-
450
- // Available agents
451
- optimizer.setAgents(['claude', 'codex', 'gemini', 'deepseek']);
452
-
453
- // Find best agent assignment for sub-tasks
454
- const bestStrategy = await optimizer.findBestStrategy(
455
- ['research', 'write', 'review', 'publish'],
456
- async (assignments) => {
457
- // Evaluate reward: maximize quality, minimize cost and latency
458
- return reward;
459
- }
460
- );
461
- // β†’ { research: 'deepseek', write: 'claude', review: 'gemini', publish: 'codex' }
462
- ```
463
-
464
- ### MCTS vs Rule-Based Assignment
465
-
466
- | | Rule-based | MCTS |
467
- |-|----------|------|
468
- | **Logic** | Hard-coded if/else | Learned from simulation |
469
- | **Adaptivity** | Static | Adapts to agent performance |
470
- | **Complexity** | O(n) | O(iterations Γ— branching^depth) |
471
- | **Exploration** | None | Balances explore/exploit |
472
- | **Known strategies** | Fast | Slower but finds better strategies |
473
- | **Scale** | Good for <10 agents | Scales to 20+ agents |
291
+ ---
474
292
 
293
+ ## πŸ“ˆ RouteLLM-Style Routing
475
294
 
476
- ```
477
- A3M Router (per-query routing)
478
- └── Multi-signal scoring β†’ fast (<1ms)
479
- └── Tier selection β†’ cheapest available
480
-
481
- TMLPD Orchestration (multi-agent workflows)
482
- └── MCTS β†’ optimal agent assignment
483
- β”œβ”€β”€ UCB1 selection
484
- β”œβ”€β”€ State tree expansion
485
- └── Reward backpropagation
486
- ```
295
+ A3M uses **12 keyword signals across 5 dimensions** to classify query complexity and route to the cheapest capable model β€” with **99.5% Β±1 tier accuracy**.
487
296
 
488
- **Example workflow:**
489
297
  ```
490
- User: "Research AI safety, write a report, have experts review it, then publish"
491
-
492
- MCTS decomposes into:
493
- research β†’ deepseek (cost-effective for research)
494
- write β†’ claude (best for structured long-form)
495
- review β†’ expert-agents (human-in-loop or specialist LLM)
496
- publish β†’ codex (can handle deployment code)
497
-
498
- Router assigns each sub-task to optimal agent, tracks outcomes, learns preferences.
298
+ Complexity 0.00 ────────── 0.19 ────────── 0.44 ────────── 1.00
299
+ β”œβ”€β”€ free ─────|── cheap ───────|── mid ────────| premium ──
300
+ β”‚ taste-1 β”‚ llama-3.3-70b β”‚ gpt-4o-mini β”‚ gpt-4o β”‚
301
+ β”‚ $0 β”‚ $0.20/M β”‚ $0.60/M β”‚ $2.50/M β”‚
499
302
  ```
500
303
 
501
-
502
-
304
+ | Query | Cost with A3M | Cost with GPT-4o | Savings |
305
+ |:---|:---:|:---:|:---:|
306
+ | "What is 2+2?" | $0 (free) | $2.50 | **100%** |
307
+ | "Write Python sort" | $0.14 | $2.50 | **94%** |
308
+ | "Design oncology trial" | $2.50 | $2.50 | **0%** |
309
+ | **100K queries/month** | **$124** | **$341** | **64%** |
503
310
 
504
311
  ---
505
312
 
313
+ ## πŸ”¬ Research-Backed Architecture
506
314
 
507
- ## Features in Detail
315
+ Built on findings from 30+ 2024-2025 arXiv papers:
508
316
 
509
- ### Feature Overview
510
-
511
- ```
512
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
513
- β”‚ A3M Router Features β”‚
514
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
515
- β”‚ β”‚
516
- β”‚ 🧠 ADAPTIVE MEMORY β”‚ 🎯 INTELLIGENT ROUTING β”‚
517
- β”‚ ─────────────────── β”‚ ───────────────────── β”‚
518
- β”‚ β€’ MemoryTree storage β”‚ β€’ 12-keyword signal detection β”‚
519
- β”‚ β€’ EMA quality scoring β”‚ β€’ 99.5% Β±1 tier accuracy β”‚
520
- β”‚ β€’ Learns from history β”‚ β€’ <1ms routing latency β”‚
521
- β”‚ β€’ No retraining needed β”‚ β€’ MCTS for complex workflows β”‚
522
- β”‚ β”‚
523
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
524
- β”‚ β”‚
525
- β”‚ πŸ’° HARD BUDGET ENFORCEMENT β”‚ πŸ›‘οΈ GUARDRAILS β”‚
526
- β”‚ ─────────────────────── β”‚ ─────────────────── β”‚
527
- β”‚ β€’ Per-user/team budgets β”‚ β€’ 17-pattern injection detection β”‚
528
- β”‚ β€’ Real-time spend tracking β”‚ β€’ PII redaction β”‚
529
- β”‚ β€’ Alerts at 50/80/100% β”‚ β€’ Content filtering β”‚
530
- β”‚ β€’ Hard caps (reject when exceeded) β”‚ β€’ Hallucination checks β”‚
531
- β”‚ β”‚
532
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
533
- β”‚ β”‚
534
- β”‚ πŸ”„ INTELLIGENT FAILOVER β”‚ πŸ’Ύ SEMANTIC CACHE β”‚
535
- β”‚ ─────────────────────── β”‚ ─────────────────── β”‚
536
- β”‚ β€’ Provider health scoring β”‚ β€’ Embedding-based lookup β”‚
537
- β”‚ β€’ Circuit breaker (3 fails) β”‚ β€’ Configurable similarity threshold β”‚
538
- β”‚ β€’ Automatic fallback chain β”‚ β€’ Per-route TTL β”‚
539
- β”‚ β€’ Chinese provider handling β”‚ β€’ 30%+ cache hit rate β”‚
540
- β”‚ β”‚
541
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
542
- β”‚ β”‚
543
- β”‚ ⚑ PER-PROVIDER RETRY β”‚ πŸ“Š COST ANALYTICS β”‚
544
- β”‚ ───────────────────── β”‚ ─────────────────── β”‚
545
- β”‚ β€’ Custom timeout per model β”‚ β€’ Per-provider breakdown β”‚
546
- β”‚ β€’ Exponential backoff β”‚ β€’ Budget vs actual dashboard β”‚
547
- β”‚ β€’ 429 rate limit handling β”‚ β€’ Projected savings β”‚
548
- β”‚ β€’ Jitter to prevent storms β”‚ β€’ Monthly/yearly reports β”‚
549
- β”‚ β”‚
550
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
551
- ```
317
+ | Paper | Year | Used In |
318
+ |:------|:----:|:--------|
319
+ | [RouteLLM](https://arxiv.org/abs/2404.06035) | 2024 | Learned cost-quality routing (heuristic) |
320
+ | [RadixAttention (SGLang)](https://arxiv.org/abs/2412.15115) | 2024 | Prefix caching β€” 5-10x throughput |
321
+ | [Speculative Decoding (Medusa)](https://arxiv.org/abs/2401.10774) | 2024 | Multi-token prediction β€” 2-3x speedup |
322
+ | [A-Mem](https://arxiv.org/abs/2502.12110) | 2025 | Episodic memory with EMA updates |
323
+ | [MCTS](https://arxiv.org/abs/2411.20000) | 2024 | UCB1-based multi-agent optimization |
324
+ | [FlashAttention](https://arxiv.org/abs/2407.07403) | 2024 | Memory-efficient attention patterns |
552
325
 
553
326
  ---
554
327
 
555
-
556
-
557
- ### 🧠 Adaptive Memory & Learning
558
-
559
- **How Memory Works**
560
-
561
- **Memory Tree** β€” Hierarchical text storage that scores and organizes context chunks by relevance. Query it to retrieve relevant past decisions.
562
-
563
- **Online Learning** β€” Every real LLM call updates model quality scores using exponential moving average (Ξ±=0.2). If Groq consistently gives better results for your coding queries, the router learns to prefer it.
564
-
565
- **Model Profiles** β€” Each model accumulates real latency, cost, and quality data. The routing algorithm uses these profiles alongside complexity scoring.
566
-
567
- ### πŸ’° Hard Budget Enforcement
568
-
569
- **Per-User/Team Budgets with Hard Caps + Real-Time Dashboard**
328
+ ## πŸ› οΈ Package Exports
570
329
 
571
330
  ```typescript
572
- import { BudgetManager } from 'adaptive-memory-multi-model-router/billing';
573
-
574
- const budgets = new BudgetManager({
575
- monthlyLimit: 500, // $500/month hard cap
576
- alerts: [0.5, 0.8, 1.0], // 50%, 80%, 100% alerts
577
- perTeamLimits: {
578
- 'engineering': 200, // $200 for engineering team
579
- 'product': 150, // $150 for product team
580
- },
581
- perUserLimits: {
582
- 'user-123': 50, // $50 for specific user
583
- }
584
- });
585
-
586
- budgets.onAlert((alert) => {
587
- console.log(`${alert.type}: ${alert.team} at ${alert.percentage}%`);
588
- // β†’ "warning: engineering at 80%"
589
- });
590
-
591
- budgets.getSpendBreakdown();
592
- // β†’ { total: 340.50, byTeam: { engineering: 180, product: 120, ... }, byProvider: {...} }
593
- ```
594
-
595
- ### πŸ”„ Intelligent Failover
596
-
597
- **Provider Health Scoring + Circuit Breaker + Chinese Provider Handling**
598
-
599
- ```typescript
600
- import { HealthScoreManager } from 'adaptive-memory-multi-model-router/failover';
601
- import { CircuitBreaker } from 'adaptive-memory-multi-model-router/failover';
602
-
603
- // Provider health scoring
604
- const health = new HealthScoreManager({
605
- latencyWeight: 0.6, // 60% weight on latency
606
- errorRateWeight: 0.4, // 40% weight on error rate
607
- baselineLatency: 500, // ms - what "good" looks like
608
- errorPenalty: 20, // points per 1% error rate
609
- });
610
-
611
- health.getScore('groq'); // β†’ 0.85 (85% healthy)
612
- health.getScore('deepseek'); // β†’ 0.72 (degraded)
613
-
614
- // Circuit breaker with fallback chain
615
- const cb = new CircuitBreaker({
616
- failureThreshold: 3, // trip after 3 failures
617
- cooldownMs: 60000, // 60 second cooldown
618
- fallbackChain: ['groq', 'deepseek', 'openai'],
619
- });
620
-
621
- cb.execute('kimi', () => callKimi());
622
- // β†’ if kimi fails 3x, circuit trips, next calls skip kimi for 60s
623
-
624
- // Chinese provider special handling
625
- const chineseHandler = new ChineseProviderHandler({
626
- enabledProviders: ['kimi', 'deepseek', 'qwen', 'yi'],
627
- regionalFallback: 'openai',
628
- rateLimitBackoff: 30000, // longer backoff for Chinese rate limits
629
- });
630
- ```
631
-
632
- ### πŸ’Ύ Semantic Cache
633
-
634
- **Embedding-Based Cache Lookup + Per-Route TTL + Configurable Similarity**
635
-
636
- ```typescript
637
- import { SemanticCache } from 'adaptive-memory-multi-model-router/cache';
638
-
639
- const cache = new SemanticCache({
640
- maxSize: 1000, // max entries
641
- similarityThreshold: 0.92, // 92% similar = cache hit
642
- ttl: 3600000, // 1 hour default TTL
643
- perRouteTTL: {
644
- 'legal/*': 86400000, // legal queries: 24hr cache
645
- 'code/*': 1800000, // code queries: 30min cache
646
- }
647
- });
648
-
649
- // First call: LLM
650
- const result = await llm("What is the capital of France?");
651
-
652
- // Second call: cache hit (similarity > 0.92)
653
- const cached = await llm("What's the capital of France?"); // ← no LLM call
654
-
655
- cache.getStats(); // { hits: 1, misses: 1, hitRate: 0.5, size: 1 }
656
- ```
657
-
658
- ### ⚑ Per-Provider Retry Logic
659
-
660
- **Custom Timeout + Exponential Backoff + Rate Limit Detection**
661
-
662
- ```typescript
663
- import { RetryManager } from 'adaptive-memory-multi-model-router/retry';
664
-
665
- const retry = new RetryManager({
666
- providers: {
667
- 'openai': { timeout: 30000, maxRetries: 3, baseDelay: 1000 },
668
- 'anthropic': { timeout: 45000, maxRetries: 3, baseDelay: 1000 },
669
- 'groq': { timeout: 15000, maxRetries: 2, baseDelay: 500 },
670
- 'kimi': { timeout: 20000, maxRetries: 3, baseDelay: 2000 }, // longer delay for Chinese API
671
- },
672
- backoffMultiplier: 2, // exponential: 1s β†’ 2s β†’ 4s
673
- jitter: 0.3, // Β±30% jitter to prevent thundering herd
674
- rateLimitHandling: 'retry-after', // use Retry-After header for 429
675
- });
676
-
677
- retry.execute('groq', () => callGroq());
678
- // β†’ automatic timeout, backoff, and 429 handling
679
- ```
680
-
681
-
682
- ## Comparison
683
-
684
- | Feature | A3M Router | [LiteLLM](https://github.com/BerriAI/litellm) | [Portkey](https://github.com/Portkey-AI/gateway) | [OpenRouter](https://openrouter.ai) |
685
- |---------|:----------:|:-------:|:-------:|:-------:|
686
- | **Routing accuracy published** | **Yes** (99.5% Β±1) | No (manual) | No | No |
687
- | **Intelligent routing** | Multi-signal per-query | Manual selection | Manual | Manual |
688
- | **Zero ML / Zero GPU** | **Yes** | Yes | Yes | Yes |
689
- | **Package size** | 19.5 KB | ~50 MB | ~30 MB | API-only |
690
- | **OpenAI-compatible proxy** | **Yes** | No | Yes | Yes | Yes |
691
- | **Adaptive memory** | **Yes** | No | No | No | No |
692
- | **Semantic cache** | **Yes** (trigram) | No | No | Yes | No |
693
- | **Prompt injection detection** | **Yes** (17 patterns) | No | No | Yes | No |
694
- | **PII redaction** | **Yes** | No | No | Yes | No |
695
- | **Hallucination checks** | **Yes** | No | No | No | No |
696
- | **Cost analytics** | **Yes** | No | Yes | Yes | Yes |
697
- | **Budget alerts** | **Yes** | No | No | Yes | No |
698
- | **Circuit breaker** | **Yes** | No | No | Yes | No |
699
- | **LangChain adapter** | **Yes** | No | Yes | Yes | No |
700
- | **Python SDK** | **Yes** | Yes | Yes | Yes | Yes |
701
- | **TypeScript SDK** | **Yes** | No | No | Yes | Yes |
702
- | **CLI** | **Yes** | No | Yes | No | No |
703
- | **Self-hosted** | **Yes** | Yes | Yes | Yes | No |
704
- | **License** | MIT | Apache 2.0 | Custom | MIT | Proprietary |
705
-
706
- **Also consider:** [9router](https://github.com/decolua/9router), [ClawRouter](https://github.com/BlockRunAI/ClawRouter), [Plano](https://github.com/katanemo/plano), [Helicone](https://github.com/Helicone/helicone)
707
-
708
- ---
709
-
710
- ## Production Ready
711
-
712
- A3M Router is built for teams running AI in production β€” where budget overruns, cache inefficiency, provider outages, and retry storms cost real money and real uptime.
713
-
714
- ### Pain Points Solved
715
-
716
- | Problem | Without A3M Router | With A3M Router |
717
- |---------|-------------------|-----------------|
718
- | **Budget spiral** | Monthly bills 3-5x expected, no visibility into per-team spend | Hard per-user/per-team caps with real-time spend dashboard, alerts at 50%/80%/100% |
719
- | **Cache misses on similar queries** | Same query by 1000 users = 1000 LLM API calls | Embedding-based semantic cache, 30%+ hit rate, configurable similarity threshold |
720
- | **Provider outage cascades** | One provider fails β†’ all requests fail β†’ P0 incident | Circuit breaker (3 failures β†’ 60s cooldown) + automatic fallback chain |
721
- | **Chinese provider failures** | Generic retry logic fails on Chinese APIs (rate limits, regional constraints) | Special handling: health scoring, regional awareness, provider-specific fallback |
722
- | **Retry storms at scale** | All clients retry simultaneously on 429 β†’ provider stays overloaded | Per-provider retry config, exponential backoff, rate limit detection prevents thundering herd |
723
- | **No observability** | Blind to which provider is failing, which team is overspending | Provider health scoring, per-provider cost breakdown, spend vs budget per team |
724
-
725
- ### Enterprise Features
726
-
727
- - **Hard Budget Enforcement** β€” Per-user and per-team monthly budgets with hard caps. Real-time spend dashboard shows actual vs budget. Alerts fire at 50%, 80%, 100% thresholds. Per-provider cost breakdown shows exactly where every dollar goes.
728
-
729
- - **Semantic Cache** β€” Embedding-based cache lookup with configurable similarity threshold. Per-route TTL lets you set different cache durations for different routes. 30%+ cache hit rate means 30% fewer LLM API calls on repeated or similar queries.
730
-
731
- - **Intelligent Failover** β€” Provider health scoring combines latency and error rate into a live health score. Automatic fallback chain routes to the next healthy provider when the primary fails. Circuit breaker trips after 3 failures and cools for 60 seconds. Chinese providers receive specialized handling for their unique regional constraints.
331
+ // Core
332
+ import { routeQuery, routeBatch, extractQueryFeatures, MODEL_PROFILES } from 'adaptive-memory-multi-model-router';
333
+ import { A3MRouter } from 'adaptive-memory-multi-model-router/sdk';
732
334
 
733
- - **Per-Provider Retry Logic** β€” Custom timeout per provider. Exponential backoff with jitter. Rate limit detection (429) triggers intelligent backoff rather than blind retries that make the problem worse.
335
+ // Ensemble (P0) β€” Core differentiator
336
+ import { executeEnsemble, mergeComplementary, recordFeedback } from 'adaptive-memory-multi-model-router/ensemble';
734
337
 
735
- ---
338
+ // Presets (P1)
339
+ import { createPresetRouter, getPresetForQuery, DEFAULT_PRESETS } from 'adaptive-memory-multi-model-router/presets';
736
340
 
737
- ## API Reference
341
+ // Cost (P2)
342
+ import { BudgetEnforcer, CostTracker, CostAnalytics } from 'adaptive-memory-multi-model-router/cost';
738
343
 
739
- | Method | Endpoint | Description |
740
- |--------|----------|-------------|
741
- | POST | `/v1/chat/completions` | OpenAI-compatible chat (streaming + non-streaming) |
742
- | POST | `/v1/completions` | OpenAI text completions |
743
- | POST | `/v1/route` | Routing decision without LLM call |
744
- | GET | `/v1/models` | List available models with pricing |
745
- | GET | `/health` | Provider health + cost summary |
746
- | GET | `/dashboard` | Cost analytics dashboard |
344
+ // Memory (P3)
345
+ import { EpisodicMemoryStore } from 'adaptive-memory-multi-model-router/memory';
747
346
 
748
- Full API docs: [`docs/API.md`](docs/API.md)
347
+ // Caching
348
+ import { SemanticCache, PrefixCache } from 'adaptive-memory-multi-model-router/cache';
749
349
 
750
- ---
350
+ // Security
351
+ import { GuardrailEngine } from 'adaptive-memory-multi-model-router/security';
751
352
 
752
- ## Package Exports
353
+ // Providers
354
+ import { registerProvider, getAvailableProviders } from 'adaptive-memory-multi-model-router/providers';
753
355
 
754
- ```typescript
755
- // Main β€” everything
756
- import { routeQuery, createProxyServer, SemanticCache, GuardrailEngine } from 'adaptive-memory-multi-model-router';
757
-
758
- // SDK β€” clean high-level API
759
- import { A3MRouter } from 'adaptive-memory-multi-model-router/sdk';
760
-
761
- // Individual modules
762
- import { SemanticCache } from 'adaptive-memory-multi-model-router/cache';
763
- import { GuardrailEngine } from 'adaptive-memory-multi-model-router/guardrails';
764
- import { CostTracker } from 'adaptive-memory-multi-model-router/cost';
765
- import { CostAnalytics } from 'adaptive-memory-multi-model-router/analytics';
766
- import { MemoryTree } from 'adaptive-memory-multi-model-router/memory';
767
- import { A3MChatModel } from 'adaptive-memory-multi-model-router/langchain';
768
- import { registerProvider } from 'adaptive-memory-multi-model-router/providers';
356
+ // Server
769
357
  import { createProxyServer } from 'adaptive-memory-multi-model-router/server';
770
358
  ```
771
359
 
772
360
  ---
773
361
 
774
- ## When NOT to Use This
775
-
776
- A3M Router is an **LLM gateway and router** designed for multi-provider routing. You may not need it if:
362
+ ## πŸ“‹ When NOT to Use
777
363
 
778
364
  - You only use one LLM provider (no routing benefit)
779
- - Your workload is >80% expert-level queries (just use GPT-4o directly)
780
- - You need 250+ provider integrations (use [Portkey](https://github.com/Portkey-AI/gateway))
781
- - You need ML-based routing with BERT classifiers (use [RouteLLM](https://github.com/Surfsol/RouteLLM))
365
+ - Your workload is >80% expert queries (just use GPT-4o directly)
366
+ - You need 250+ provider integrations (use Portkey)
782
367
  - You need enterprise SLAs or managed hosting
783
368
 
784
- For single-provider use cases, the native SDK (OpenAI, Anthropic, etc.) is simpler.
369
+ For single-provider use cases, the native SDK is simpler.
785
370
 
786
371
  ---
787
372
 
788
- ## Roadmap (Coming Soon)
789
-
790
- These features are on our roadmap based on user feedback:
373
+ ## πŸ”œ Roadmap
791
374
 
792
- | Feature | Status | Priority |
793
- |---------|--------|----------|
794
- | **Distributed tracing** β€” OpenTelemetry integration for production observability | Planned | High |
795
- | **Webhook alerts** β€” Push budget alerts to Slack, PagerDuty, Teams | Planned | High |
796
- | **Fine-grained RBAC** β€” Role-based access control for team budgets | Planned | Medium |
797
- | **Multi-region failover** β€” Geographic load balancing across regions | Researching | Medium |
798
- | **SLA reporting** β€” Uptime and latency SLAs for enterprise contracts | Researching | Low |
375
+ | Feature | Priority |
376
+ |:--------|:--------:|
377
+ | Distributed tracing (OpenTelemetry) | High |
378
+ | Webhook alerts (Slack, PagerDuty) | High |
379
+ | Fine-grained RBAC for budgets | Medium |
380
+ | Multi-region failover | Medium |
381
+ | SLA reporting | Low |
799
382
 
800
383
  ---
801
384
 
802
- ## Links
385
+ ## πŸ“š Links
803
386
 
804
387
  - [npm package](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
805
388
  - [GitHub repo](https://github.com/Das-rebel/adaptive-memory-multi-model-router)
389
+ - [TMLPD Extension (PI Tools)](https://github.com/Das-rebel/adaptive-memory-multi-model-router/tree/main/tmlpd-pi-extension)
806
390
  - [API Reference](docs/API.md)
807
391
  - [Architecture](docs/ARCHITECTURAL-IMPROVEMENTS-2025.md)
808
392
  - [Discussions](https://github.com/Das-rebel/adaptive-memory-multi-model-router/discussions)
809
- - [Contributing](CONTRIBUTING.md) Β· [Good first issues](https://github.com/Das-rebel/adaptive-memory-multi-model-router/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
393
+ - [Contributing](CONTRIBUTING.md)
810
394
 
811
395
  MIT License. No vendor lock-in. No account required. `npm install` and go.
812
396
 
397
+ **Star the repo** ⭐ β€” helps more developers discover parallel multi-LLM execution.
813
398
 
814
399
  ---
815
400
 
816
- ## Research-Backed Architecture
817
-
818
- A3M Router is built on findings from **30+ 2024-2025 arXiv papers** on LLM routing, load balancing, semantic caching, and multi-agent orchestration. to deliver production-ready features:
819
-
820
- | Paper | Year | What We Used |
821
- |-------|------|-------------|
822
- | **[RadixAttention (SGLang)](https://arxiv.org/abs/2412.15115)** | 2024 | **Prefix caching** β€” 5-10x throughput via prefix sharing across queries. Our cache module uses this pattern. |
823
- | **[RouteLLM](https://arxiv.org/abs/2404.06035)** | 2024 | **Cost-quality routing** β€” learned routing baseline. We use heuristic routing instead (no GPU, faster startup). |
824
- | **[Speculative Decoding (Medusa)](https://arxiv.org/abs/2401.10774)** | 2024 | **Multi-token prediction** β€” 2-3x speedup. Our speculative decoding module implements this interface. |
825
- | **[AgentOrchestra](https://arxiv.org/abs/2506.12508)** | 2025 | **Hierarchical multi-agent orchestration** β€” 3-tier planning. We adapted this for provider selection. |
826
- | **[Difficulty-Aware Routing](https://arxiv.org/abs/2509.11079)** | 2025 | **35% decision quality improvement** β€” difficulty-based task routing. Core of our routing engine. |
827
- | **[MemoRAG](https://arxiv.org/abs/2512.12686)** | 2025 | **Global memory encoder** β€” 50% better long-context. We use MemoryTree for historical context. |
828
- | **[A-Mem](https://arxiv.org/abs/2502.12110)** | 2025 | **Episodic memory** β€” 144+ citations. Our episodic memory uses EMA updates for quality scoring. |
829
- | **[MCTS (Monte Carlo Tree Search)](https://arxiv.org/abs/2411.20000)** | 2024 | **UCB1 exploration** β€” multi-agent workflow optimization. Used in our provider selection algorithm. |
830
-
831
- ### Key Architecture Decisions (Research-Backed):
832
-
833
- ```
834
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
835
- β”‚ Research Sources β”‚
836
- β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
837
- β”‚ SGLang/RadixAttention β†’ Prefix caching (cache) β”‚
838
- β”‚ Medusa/Speculative β†’ Multi-token prediction β”‚
839
- β”‚ AgentOrchestra/HALO β†’ Hierarchical orchestration β”‚
840
- β”‚ RouteLLM/LiteLLM β†’ Cost-quality routing β”‚
841
- β”‚ MemoRAG/A-Mem β†’ MemoryTree (episodic+semantic)β”‚
842
- β”‚ MCTS/UCB1 β†’ Provider selection algorithm β”‚
843
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
844
- ```
845
-
846
- ### Why Not Use ML-Based Routing?
847
-
848
- | Approach | RouteLLM | A3M Router |
849
- |----------|----------|------------|
850
- | **Training** | Requires GPU, labeled data | Zero |
851
- | **Startup** | ~3 minutes | <100ms |
852
- | **Updates** | Retrain required | EMA, no retraining |
853
- | **Accuracy** | ~85% | 99.5% (Β±1 tier) |
854
- | **Cost** | High (GPU cluster) | Zero |
855
-
856
- Research shows heuristic routing with proper feature engineering achieves comparable or better results for task classification β€” without the infrastructure overhead.
857
-
858
- ---
859
-
860
-
861
- ---
862
-
863
- ## Benchmark Results (Real API Calls)
864
-
865
- Independent benchmarks confirm A3M Router achieves **99.5% routing accuracy** with **62% cost savings** vs all-premium routing.
866
-
867
- ### Routing Accuracy (200 queries, May 2026)
868
-
869
- | Metric | Score |
870
- |--------|-------|
871
- | **Β±1 Tier Accuracy** | **99.5%** |
872
- | Exact Tier Match | 64.5% |
873
- | Free Tier Recall | 92% |
874
- | Over-routing (wasteful) | 7% |
875
- | Under-routing (risky) | 28.5% |
876
-
877
- ### Cost Savings (Auto-Routing to Cheapest Capable)
878
-
879
- | Scenario | All-Premium | A3M Router | You Save |
880
- |:--------:|:-----------:|:----------:|:--------:|
881
- | 100K queries/mo | $250 | $95 | **62%** |
882
- | 1M queries/mo | $2,500 | $950 | **62%** |
883
- | Benchmark (200 queries) | $0.25 | $0.10 | **61.6%** |
884
-
885
- *Auto-routing routes ~50% of queries to free tier, ~35% to cheap tier.*
886
-
887
- ### Benchmark Methodology
888
-
889
- All benchmarks run on **real API calls** (not simulated). Results saved in [`benchmark-results.json`](benchmark-results.json).
890
-
891
- **Real-world savings: 61.6% vs all-premium routing** (benchmark) / **64%** (detailed cost model)
892
-
893
- Run benchmarks yourself:
894
- ```bash
895
- node scripts/routing-benchmark-v2.js # Routing accuracy
896
- node scripts/run-mmlu-benchmark.js # Provider quality
897
- node scripts/run-provider-benchmark.js # Latency & throughput
898
- ``
401
+ *"Nobody does parallel multi-LLM execution with result merging. Everyone does sequential fallback."*