adaptive-memory-multi-model-router 2.14.13 → 2.14.14
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/.well-known/ai-plugin.json +4 -4
- package/LAUNCH_SNAPSHOT.md +260 -0
- package/README.md.bak +836 -0
- package/ai-plugin.json +16 -0
- package/articles/CHINESE_DIRECTORIES.md +100 -0
- package/articles/NEWSLETTER_SUBMISSIONS.md +112 -0
- package/articles/REDDIT_POST.md +67 -0
- package/assets/a3m_3blue1brown.mp4 +0 -0
- package/demo/3blue1brown_video.py +285 -0
- package/demo/3blue1brown_video_v2.py +310 -0
- package/demo/a3m_3blue1brown.mp4 +0 -0
- package/demo/product-video-v1.mp4 +0 -0
- package/dist/cli/setupWizard.d.ts.map +1 -0
- package/dist/cost/budgetEnforcer.d.ts.map +1 -0
- package/dist/observability/changeWatch.d.ts.map +1 -0
- package/dist/observability/fatigueDetector.d.ts.map +1 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/middleware.d.ts.map +1 -0
- package/dist/observability/tracer.d.ts.map +1 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/routing/crossModelValidation.d.ts.map +1 -0
- package/dist/routing/providerHealth.d.ts.map +1 -0
- package/dist/routing/providerRetry.d.ts.map +1 -0
- package/dist/tui/dashboard.d.ts.map +1 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/docs/.well-known/ai-plugin.json +16 -0
- package/docs/CITATIONS.md +74 -0
- package/docs/GEO_ROOT_CAUSE.md +136 -0
- package/docs/GEO_STATUS.md +199 -0
- package/docs/GEO_TEST_RESULTS.md +176 -0
- package/docs/LANGCHAIN_INTEGRATION.md +147 -0
- package/docs/VERCEL_AI_SDK.md +209 -0
- package/docs/ai-plugin.json +16 -0
- package/docs/compare.md +109 -0
- package/docs/index.html +51 -0
- package/docs/openapi.json +1 -1
- package/docs/well-known/ai-plugin.json +16 -0
- package/docs/wellknown/ai-plugin.json +16 -0
- package/huggingface_space/README.md +35 -0
- package/huggingface_space/app.py +126 -0
- package/huggingface_space/create_space.py +208 -0
- package/huggingface_space/requirements.txt +1 -0
- package/llms.txt +1 -1
- package/package.json +6 -2
- package/research/FINDING_005_knowledge_gap_orthogonality.md +34 -0
- package/research/PUBLISH_LOG.md +0 -3
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# A3M Router — GEO (Generative Engine Optimization) Status
|
|
2
|
+
|
|
3
|
+
**Generated:** Sat May 31 18:30 IST 2026
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## What is GEO?
|
|
8
|
+
|
|
9
|
+
GEO = Getting your brand/product cited by AI engines (ChatGPT, Perplexity, Claude, Gemini, Google AI Overviews).
|
|
10
|
+
|
|
11
|
+
Unlike SEO (Google ranking), GEO is about being the **source cited in AI answers**.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Current GEO Assets Status
|
|
16
|
+
|
|
17
|
+
### ✅ WORKING - AI Can Discover These
|
|
18
|
+
|
|
19
|
+
| Asset | URL | Purpose | Status |
|
|
20
|
+
|-------|-----|---------|--------|
|
|
21
|
+
| **llms.txt** | https://das-rebel.github.io/a3m-router/llms.txt | AI-readable summary (19KB) | ✅ Working |
|
|
22
|
+
| **sitemap.xml** | https://das-rebel.github.io/a3m-router/sitemap.xml | AI crawler guidance | ✅ Working |
|
|
23
|
+
| **robots.txt** | https://das-rebel.github.io/a3m-router/robots.txt | AI bot permissions | ✅ Working |
|
|
24
|
+
| **benchmark-chart.png** | https://das-rebel.github.io/a3m-router/benchmark-chart.png | Visual proof for citations | ✅ Working |
|
|
25
|
+
| **openapi.json** | https://das-rebel.github.io/a3m-router/docs/openapi.json | API spec for ChatGPT plugins | ✅ Working |
|
|
26
|
+
|
|
27
|
+
### ❌ BROKEN - Need Fixes
|
|
28
|
+
|
|
29
|
+
| Asset | URL | Problem |
|
|
30
|
+
|-------|-----|---------|
|
|
31
|
+
| **ai-plugin.json** | https://das-rebel.github.io/a3m-router/.well-known/ai-plugin.json | GitHub Pages doesn't serve hidden directories |
|
|
32
|
+
| **llms-full.txt** | https://das-rebel.github.io/a3m-router/llms-full.txt | 404 - not deployed |
|
|
33
|
+
| **JSON-LD** | https://das-rebel.github.io/a3m-router/docs/index.html | May not be valid |
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## AI Bot Access (robots.txt)
|
|
38
|
+
|
|
39
|
+
✅ **All AI bots allowed:**
|
|
40
|
+
```
|
|
41
|
+
User-agent: GPTBot (OpenAI)
|
|
42
|
+
User-agent: ChatGPT-User (ChatGPT)
|
|
43
|
+
User-agent: ClaudeBot (Anthropic)
|
|
44
|
+
User-agent: PerplexityBot (Perplexity)
|
|
45
|
+
User-agent: Google-Extended (Google AI)
|
|
46
|
+
User-agent: anthropic-ai (Anthropic)
|
|
47
|
+
User-agent: Cohere-AI (Cohere)
|
|
48
|
+
User-agent: CCBot (Common Crawl)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## What's Missing (Action Items)
|
|
54
|
+
|
|
55
|
+
### 1. Fix ai-plugin.json
|
|
56
|
+
**Problem:** GitHub Pages doesn't serve `.well-known/` directory.
|
|
57
|
+
|
|
58
|
+
**Solution:** Create `docs/.well-known/` and copy files there.
|
|
59
|
+
|
|
60
|
+
**Files to create:**
|
|
61
|
+
- `docs/.well-known/ai-plugin.json` → URL: `/docs/.well-known/ai-plugin.json`
|
|
62
|
+
- Update the URL reference in ai-plugin.json to point to `/docs/openapi.json`
|
|
63
|
+
|
|
64
|
+
### 2. Deploy llms-full.txt
|
|
65
|
+
**Problem:** Only `llms.txt` (2KB) is deployed, not `llms-full.txt` (9KB).
|
|
66
|
+
|
|
67
|
+
**Solution:** Copy `llms-full.txt` to `docs/llms-full.txt`
|
|
68
|
+
|
|
69
|
+
### 3. Verify JSON-LD
|
|
70
|
+
**Problem:** Need to verify the JSON-LD in index.html is valid and complete.
|
|
71
|
+
|
|
72
|
+
**Solution:** Run JSON-LD validator on the page.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## How AI Engines Discover A3M Router
|
|
77
|
+
|
|
78
|
+
### Discovery Path 1: Direct Crawl
|
|
79
|
+
- Bot visits `das-rebel.github.io/a3m-router/`
|
|
80
|
+
- Reads `llms.txt` (AI-optimized summary)
|
|
81
|
+
- Reads `robots.txt` (permissions)
|
|
82
|
+
- Indexes content
|
|
83
|
+
|
|
84
|
+
### Discovery Path 2: npm Registry
|
|
85
|
+
- Bot crawls `npmjs.com/package/adaptive-memory-multi-model-router`
|
|
86
|
+
- Reads description, keywords (65 keywords!)
|
|
87
|
+
- Finds GitHub link
|
|
88
|
+
|
|
89
|
+
### Discovery Path 3: GitHub Topics
|
|
90
|
+
- Bot reads repo metadata
|
|
91
|
+
- Sees topics: `llm-router, ai-gateway, openai-proxy, benchmark, ...`
|
|
92
|
+
- 20 topics for discoverability
|
|
93
|
+
|
|
94
|
+
### Discovery Path 4: ChatGPT Plugin
|
|
95
|
+
- User searches for "LLM router" in ChatGPT
|
|
96
|
+
- If ai-plugin.json deployed, shows as plugin
|
|
97
|
+
- Currently broken ❌
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## GEO Optimization Recommendations
|
|
102
|
+
|
|
103
|
+
### High Priority (Fix Now)
|
|
104
|
+
|
|
105
|
+
1. **Fix ai-plugin.json deployment**
|
|
106
|
+
```bash
|
|
107
|
+
mkdir -p docs/.well-known
|
|
108
|
+
cp .well-known/ai-plugin.json docs/.well-known/
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
2. **Deploy llms-full.txt** (comprehensive docs for AI)
|
|
112
|
+
```bash
|
|
113
|
+
cp llms-full.txt docs/llms-full.txt
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
3. **Add structured data to README.md**
|
|
117
|
+
- GitHub reads README for AI summaries
|
|
118
|
+
- Ensure benchmark numbers are prominent
|
|
119
|
+
|
|
120
|
+
### Medium Priority (Next Week)
|
|
121
|
+
|
|
122
|
+
4. **Verify JSON-LD in index.html**
|
|
123
|
+
- Test at: https://validator.schema.org/
|
|
124
|
+
- Ensure FAQPage schema is valid
|
|
125
|
+
|
|
126
|
+
5. **Add citation-friendly content**
|
|
127
|
+
- Create "CITATIONS.md" with fact sheets
|
|
128
|
+
- Include verbatim numbers AI can cite
|
|
129
|
+
|
|
130
|
+
6. **Register with AI directories**
|
|
131
|
+
- ChatGPT Plugin directory
|
|
132
|
+
- Anthropic model registry
|
|
133
|
+
- Perplexity publisher program
|
|
134
|
+
|
|
135
|
+
### Low Priority (Later)
|
|
136
|
+
|
|
137
|
+
7. **Create dedicated landing page for AI engines**
|
|
138
|
+
- Minimal, citation-friendly content
|
|
139
|
+
- No JavaScript, pure HTML
|
|
140
|
+
|
|
141
|
+
8. **Add Schema.org FAQPage**
|
|
142
|
+
- Target "What is the best LLM router?" queries
|
|
143
|
+
- 8-10 Q&As with citation-ready answers
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## How to Test GEO
|
|
148
|
+
|
|
149
|
+
### Test 1: Ask ChatGPT
|
|
150
|
+
> "What's the best open-source LLM router?"
|
|
151
|
+
|
|
152
|
+
Does A3M Router appear? If not, why?
|
|
153
|
+
|
|
154
|
+
### Test 2: Ask Perplexity
|
|
155
|
+
> "Compare LLM routing tools"
|
|
156
|
+
|
|
157
|
+
Does A3M Router appear with correct benchmark numbers?
|
|
158
|
+
|
|
159
|
+
### Test 3: Check Claude Citation
|
|
160
|
+
> "What LLM router saves the most money?"
|
|
161
|
+
|
|
162
|
+
Does Claude cite A3M Router with "$0.047/1K"?
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Current npm Keywords (GEO Signals)
|
|
167
|
+
|
|
168
|
+
65 keywords targeting AI search:
|
|
169
|
+
```
|
|
170
|
+
llm-router, llm-gateway, ai-gateway, openai-proxy, llm-proxy,
|
|
171
|
+
model-routing, openai-compatible, semantic-cache, guardrails,
|
|
172
|
+
cost-optimization, groq, cerebras, deepseek, ollama, anthropic,
|
|
173
|
+
langchain, routellm, litellm, multi-provider, ai, artificial-intelligence,
|
|
174
|
+
api-gateway, budget-control, circuit-breaker, free-llm, llm-cost,
|
|
175
|
+
parallel-execution, provider-routing, llm-routing, ...
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Next Steps
|
|
181
|
+
|
|
182
|
+
1. **Fix ai-plugin.json** → Copy to docs/.well-known/
|
|
183
|
+
2. **Deploy llms-full.txt** → Copy to docs/
|
|
184
|
+
3. **Test with AI** → Ask ChatGPT/Claude about LLM routers
|
|
185
|
+
4. **Monitor** → Track if A3M appears in AI answers
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Vault Insights on GEO
|
|
190
|
+
|
|
191
|
+
From vault learnings:
|
|
192
|
+
|
|
193
|
+
> "SEO is slowly losing its dominance. Welcome to GEO.
|
|
194
|
+
> In the age of ChatGPT, Perplexity, and Claude, Generative Engine Optimization is positioned to become the new playbook for brand visibility.
|
|
195
|
+
> It's not about gaming the algorithm — it's about being cited by it."
|
|
196
|
+
|
|
197
|
+
> "Now people ask AI, not Google and if you're not in the answer, you don't exist."
|
|
198
|
+
|
|
199
|
+
> "Add this 1 small file to your website to get your brand in any LLM" → ai-plugin.json
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# A3M Router — GEO Test Results
|
|
2
|
+
|
|
3
|
+
**Date:** Sat May 31 18:45 IST 2026
|
|
4
|
+
**Source:** ChatGPT + Claude responses to "best LLM router for cost savings"
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🚨 THE PROBLEM: A3M NOT BEING CITED
|
|
9
|
+
|
|
10
|
+
AI engines are recommending **LiteLLM, RouteLLM, Bifrost, NadirClaw** but **NOT A3M**.
|
|
11
|
+
|
|
12
|
+
**Why?** The AI explicitly said:
|
|
13
|
+
> "A3M wasn't included because it is not present in any of the academic benchmarks (LLMRouterBench, RouterArena, RouterEval, or the RouteLLM head-to-heads)"
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## AI Feedback Summary
|
|
18
|
+
|
|
19
|
+
### ChatGPT (Initial Response)
|
|
20
|
+
```
|
|
21
|
+
❌ NOT CITED initially
|
|
22
|
+
✅ Later corrected when challenged
|
|
23
|
+
⚠️ "best emerging standalone cost-router: A3M"
|
|
24
|
+
⚠️ "A3M belongs in the shortlist for cost-savings"
|
|
25
|
+
⚠️ "Resume builder - best asset"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Claude (Comprehensive Analysis)
|
|
29
|
+
```
|
|
30
|
+
❌ "A3M not present in any academic benchmarks"
|
|
31
|
+
⚠️ "99.5% accuracy = ±1 tier (loose definition)"
|
|
32
|
+
⚠️ "Self-reported numbers vs independent validation"
|
|
33
|
+
⚠️ "Different niche: deterministic vs learning-based routers"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Why A3M Is Not Being Cited
|
|
39
|
+
|
|
40
|
+
### 1. Missing from Benchmarks
|
|
41
|
+
- Not in LLMRouterBench (400K+ instances)
|
|
42
|
+
- Not in RouterArena leaderboard
|
|
43
|
+
- Not in RouterEval (200M+ records)
|
|
44
|
+
- **PR open at RouterArena but not merged** ⚠️
|
|
45
|
+
|
|
46
|
+
### 2. Unverified Claims
|
|
47
|
+
- "99.5% accuracy" uses ±1 tier definition (not exact match)
|
|
48
|
+
- Self-reported numbers not trusted
|
|
49
|
+
- No third-party validation
|
|
50
|
+
|
|
51
|
+
### 3. Different Category
|
|
52
|
+
- A3M is "deterministic rule-based routing"
|
|
53
|
+
- AI engines compare to "learning-based routers"
|
|
54
|
+
- Category confusion
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## What AI Engines ARE Citing
|
|
59
|
+
|
|
60
|
+
### Routers with academic citations:
|
|
61
|
+
1. **RouteLLM** - LMSYS/Anyscale paper, 70% cost reduction cited
|
|
62
|
+
2. **LiteLLM** - Production gateway maturity
|
|
63
|
+
3. **Bifrost** - Enterprise gateway (50x faster)
|
|
64
|
+
4. **NadirClaw** - Explicit cost-optimizer proxy
|
|
65
|
+
|
|
66
|
+
### Why they get cited:
|
|
67
|
+
- Published benchmark results
|
|
68
|
+
- Academic papers
|
|
69
|
+
- Third-party validation
|
|
70
|
+
- "Research-backed routing"
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Action Items (Priority Order)
|
|
75
|
+
|
|
76
|
+
### 🔴 CRITICAL (Fix Now)
|
|
77
|
+
|
|
78
|
+
**1. Get A3M into RouterArena**
|
|
79
|
+
- PR is open: https://github.com/RouteWorks/RouterArena/pull/113
|
|
80
|
+
- Not merged yet
|
|
81
|
+
- This is the #1 GEO blocker
|
|
82
|
+
|
|
83
|
+
**2. Change "99.5% accuracy" claim**
|
|
84
|
+
- Currently: "99.5% ±1 tier"
|
|
85
|
+
- AI sees this as misleading
|
|
86
|
+
- Better: "76.43 RouterArena score, $0.047/1K"
|
|
87
|
+
- Remove "accuracy" until we have ±0 tier metrics
|
|
88
|
+
|
|
89
|
+
**3. Add third-party validation**
|
|
90
|
+
- Publish on LLMRouterBench
|
|
91
|
+
- Submit to RouterEval
|
|
92
|
+
- Get independent benchmark run
|
|
93
|
+
|
|
94
|
+
### 🟡 MEDIUM (Next Week)
|
|
95
|
+
|
|
96
|
+
**4. Fix claim language**
|
|
97
|
+
- "no ML dependencies" → good, clear
|
|
98
|
+
- "99.5% accuracy" → sounds like BS
|
|
99
|
+
- Better: "rule-based routing, 0ms overhead, no training data needed"
|
|
100
|
+
|
|
101
|
+
**5. Create citation-friendly FAQ**
|
|
102
|
+
```
|
|
103
|
+
Q: How is A3M different from RouteLLM?
|
|
104
|
+
A: A3M is a production gateway with deterministic rule-based
|
|
105
|
+
routing. RouteLLM uses ML. A3M uses multi-signal heuristic
|
|
106
|
+
classification (12 signals, 5 dimensions) without any model
|
|
107
|
+
training. Best for: cost-critical production, zero ML overhead.
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**6. Add to academic benchmarks**
|
|
111
|
+
- Submit to LLMRouterBench (ACL 2026)
|
|
112
|
+
- Register at RouterEval
|
|
113
|
+
- Get cited in routing research
|
|
114
|
+
|
|
115
|
+
### 🟢 LOW (Later)
|
|
116
|
+
|
|
117
|
+
**7. Create comparison page**
|
|
118
|
+
- Compare A3M vs LiteLLM vs RouteLLM
|
|
119
|
+
- Honest strengths/weaknesses
|
|
120
|
+
- Make it easy for AI to cite
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Honest Ranking from AI (Current)
|
|
125
|
+
|
|
126
|
+
| Rank | Router | Why Cited |
|
|
127
|
+
|------|--------|-----------|
|
|
128
|
+
| 1 | LiteLLM + RouteLLM | Production proven, research-backed |
|
|
129
|
+
| 2 | RouteLLM alone | 70% cost reduction cited |
|
|
130
|
+
| 3 | Bifrost | Enterprise gateway |
|
|
131
|
+
| 4 | **A3M** | Not cited (missing benchmarks) |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## What A3M Does Well (According to AI)
|
|
136
|
+
|
|
137
|
+
✅ "best story for Subhajit" (resume/portfolio)
|
|
138
|
+
✅ "proves he understands AI infra"
|
|
139
|
+
✅ "very goblin-core efficiency" (interesting approach)
|
|
140
|
+
✅ "47+ providers, budget enforcement, semantic cache"
|
|
141
|
+
✅ "OpenAI-compatible proxy"
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Recommended Claim Changes
|
|
146
|
+
|
|
147
|
+
### BEFORE (Sounds Like BS)
|
|
148
|
+
> "99.5% routing accuracy"
|
|
149
|
+
> "Best LLM router"
|
|
150
|
+
> "Top performer"
|
|
151
|
+
|
|
152
|
+
### AFTER (Citation-Friendly)
|
|
153
|
+
> "76.43 on RouterArena (arXiv:2510.00202)"
|
|
154
|
+
> "#1 on cost-efficiency benchmark"
|
|
155
|
+
> "$0.047/1K vs GPT-5 $10/1K"
|
|
156
|
+
> "19.5KB, zero ML dependencies, no training data"
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Vault Insights on GEO (From Earlier)
|
|
161
|
+
|
|
162
|
+
> "It's not about gaming the algorithm — it's about being cited by it."
|
|
163
|
+
|
|
164
|
+
> "Now people ask AI, not Google and if you're not in the answer, you don't exist."
|
|
165
|
+
|
|
166
|
+
**Current status:** A3M is NOT in the answer. We need to fix this.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Next Steps
|
|
171
|
+
|
|
172
|
+
1. **Check RouterArena PR status** - Why not merged?
|
|
173
|
+
2. **Reframe claims** - Remove "accuracy", use benchmark numbers
|
|
174
|
+
3. **Submit to more benchmarks** - LLMRouterBench, RouterEval
|
|
175
|
+
4. **Create comparison page** - Honest A3M vs competitors
|
|
176
|
+
5. **Get cited** - This is the goal
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# LangChain Provider Integration for A3M Router
|
|
2
|
+
|
|
3
|
+
This document outlines how to integrate A3M Router with LangChain as a custom LLM provider.
|
|
4
|
+
|
|
5
|
+
## Option 1: OpenAI-Compatible API (Recommended)
|
|
6
|
+
|
|
7
|
+
A3M Router is OpenAI-compatible, so you can use it with LangChain's OpenAI integration:
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from langchain_openai import OpenAI
|
|
11
|
+
from langchain.chains import LLMChain
|
|
12
|
+
from langchain.prompts import PromptTemplate
|
|
13
|
+
|
|
14
|
+
# Configure A3M Router as OpenAI-compatible endpoint
|
|
15
|
+
llm = OpenAI(
|
|
16
|
+
model="auto", # A3M will route automatically
|
|
17
|
+
openai_api_base="http://localhost:8787/v1", # A3M Router
|
|
18
|
+
openai_api_key="your-api-key", # Required by A3M but not used for routing
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
# Simple usage
|
|
22
|
+
chain = LLMChain(
|
|
23
|
+
llm=llm,
|
|
24
|
+
prompt=PromptTemplate.from_template("Explain {topic} in {style}.")
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
result = chain.run(topic="quantum computing", style="a haiku")
|
|
28
|
+
print(result)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Option 2: Custom LangChain Callback Integration
|
|
32
|
+
|
|
33
|
+
For more control over routing decisions:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from langchain.callbacks.base import BaseCallbackHandler
|
|
37
|
+
from langchain_openai import OpenAI
|
|
38
|
+
from typing import Any, Dict, List
|
|
39
|
+
import requests
|
|
40
|
+
|
|
41
|
+
class A3MRouterCallback(BaseCallbackHandler):
|
|
42
|
+
"""Callback that logs A3M routing decisions"""
|
|
43
|
+
|
|
44
|
+
def __init__(self):
|
|
45
|
+
self.routing_history = []
|
|
46
|
+
|
|
47
|
+
def on_llm_start(self, serialized: Dict, prompts: List[str], **kwargs):
|
|
48
|
+
query = prompts[0] if prompts else ""
|
|
49
|
+
# Get routing decision before LLM call
|
|
50
|
+
response = requests.post(
|
|
51
|
+
"http://localhost:8787/v1/route",
|
|
52
|
+
json={"query": query}
|
|
53
|
+
)
|
|
54
|
+
if response.ok:
|
|
55
|
+
decision = response.json()
|
|
56
|
+
self.routing_history.append(decision)
|
|
57
|
+
print(f"🔀 Routed to: {decision.get('model')} "
|
|
58
|
+
f"(${decision.get('cost')})")
|
|
59
|
+
|
|
60
|
+
# Use with LangChain
|
|
61
|
+
llm = OpenAI(
|
|
62
|
+
model="auto",
|
|
63
|
+
openai_api_base="http://localhost:8787/v1",
|
|
64
|
+
callbacks=[A3MRouterCallback()]
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Option 3: A3M Router as LangChain Tool
|
|
69
|
+
|
|
70
|
+
Use A3M's routing as a tool in LangChain agents:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from langchain.agents import initialize_agent, AgentType
|
|
74
|
+
from langchain.tools import Tool
|
|
75
|
+
from langchain_openai import OpenAI
|
|
76
|
+
import requests
|
|
77
|
+
|
|
78
|
+
def get_routing_decision(query: str) -> str:
|
|
79
|
+
"""Get A3M routing decision for a query"""
|
|
80
|
+
response = requests.post(
|
|
81
|
+
"http://localhost:8787/v1/route",
|
|
82
|
+
json={"query": query}
|
|
83
|
+
)
|
|
84
|
+
if response.ok:
|
|
85
|
+
data = response.json()
|
|
86
|
+
return f"Model: {data.get('model')}, Tier: {data.get('tier')}, Cost: ${data.get('cost')}"
|
|
87
|
+
return "Error: A3M Router not available"
|
|
88
|
+
|
|
89
|
+
routing_tool = Tool(
|
|
90
|
+
name="A3M Router",
|
|
91
|
+
func=get_routing_decision,
|
|
92
|
+
description="Useful for determining the best LLM for a task"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Create agent with routing tool
|
|
96
|
+
llm = OpenAI(temperature=0)
|
|
97
|
+
agent = initialize_agent(
|
|
98
|
+
tools=[routing_tool],
|
|
99
|
+
llm=llm,
|
|
100
|
+
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
|
101
|
+
verbose=True
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
agent.run("What model should I use for a Python debugging task?")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Installation
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pip install langchain langchain-openai requests
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Environment Setup
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
export OPENAI_API_KEY="your-key" # Required for LangChain
|
|
117
|
+
# A3M Router runs separately at localhost:8787
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## A3M Router + LangChain Flow
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
User Query → LangChain Agent → A3M Router (/v1/route)
|
|
124
|
+
↓
|
|
125
|
+
Optimal Model Selected
|
|
126
|
+
↓
|
|
127
|
+
Provider API (Groq, DeepSeek, etc.)
|
|
128
|
+
↓
|
|
129
|
+
Response Returned
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Cost Tracking
|
|
133
|
+
|
|
134
|
+
A3M Router automatically tracks costs. In LangChain:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from langchain.callbacks import get_openai_callback
|
|
138
|
+
|
|
139
|
+
with get_openai_callback() as cb:
|
|
140
|
+
chain.run("Explain quantum computing")
|
|
141
|
+
print(f"Total tokens: {cb.total_tokens}")
|
|
142
|
+
print(f"Total cost: ${cb.total_cost}")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
For more info: https://github.com/Das-rebel/a3m-router
|