adaptive-memory-multi-model-router 2.16.0 → 2.16.2
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/.github/workflows/adapters-ci.yml +142 -0
- package/.github/workflows/auto-submit-sitemap.yml +41 -0
- package/.github/workflows/ci.yml +2 -5
- package/.github/workflows/mcp-pypi-publish.yml +34 -0
- package/.github/workflows/pypi-publish.yml +146 -0
- package/.github/workflows/tmlpd-publish.yml +23 -0
- package/README.md +245 -148
- package/RELEASE_v2.16.0.md +149 -0
- package/TECHNICAL_README.md +253 -0
- package/adapters/README.md +36 -0
- package/adapters/__init__.py +25 -0
- package/adapters/a3m_adapter/__init__.py +51 -0
- package/adapters/a3m_adapter/adapter/__init__.py +22 -0
- package/adapters/a3m_adapter/adapter/autogen.py +169 -0
- package/adapters/a3m_adapter/adapter/config.py +100 -0
- package/adapters/a3m_adapter/adapter/haystack.py +197 -0
- package/adapters/a3m_adapter/adapter/langchain.py +155 -0
- package/adapters/a3m_adapter/adapter/langgraph.py +196 -0
- package/adapters/a3m_adapter/adapter/llamaindex.py +162 -0
- package/adapters/a3m_adapter/adapter/pinecone.py +217 -0
- package/adapters/a3m_adapter/adapter/vercel.py +188 -0
- package/adapters/a3m_adapter/tests/__init__.py +1 -0
- package/adapters/a3m_adapter/tests/test_adapters.py +118 -0
- package/adapters/a3m_adapter/tests/test_integration.py +80 -0
- package/adapters/requirements-dev.txt +6 -0
- package/adapters/requirements.txt +4 -0
- package/adapters/setup.py +23 -0
- package/demo.py +251 -0
- package/discoverability-diagnosis.md +280 -0
- package/dist/analytics/costAnalytics.d.ts.map +1 -1
- package/dist/benchmark/reproducible.d.ts.map +1 -1
- package/dist/cache/semanticCache.d.ts.map +1 -1
- package/dist/cli/setupWizard.d.ts +257 -50
- package/dist/cli/setupWizard.d.ts.map +1 -1
- package/dist/cli/setupWizard.js +419 -109
- package/dist/cli/setupWizard.js.map +1 -1
- package/dist/cli/tui.d.ts +6 -0
- package/dist/cli/tui.js +96 -67
- package/dist/cli/tui.js.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cost/budgetEnforcer.d.ts.map +1 -1
- package/dist/cost/costTracker.d.ts.map +1 -1
- package/dist/ensemble/multiRoundDialog.d.ts.map +1 -1
- package/dist/ensemble/shapleyValue.d.ts.map +1 -1
- package/dist/ensemble.d.ts +1 -1
- package/dist/ensemble.js +141 -0
- package/dist/integrations/langchainAdapter.d.ts.map +1 -1
- package/dist/integrations/langchainAdapter.js +3 -3
- package/dist/integrations/langchainAdapter.js.map +1 -1
- package/dist/integrations/oauth.d.ts.map +1 -1
- package/dist/integrations/scienceAdapter.d.ts.map +1 -1
- package/dist/memory/autoFetch.d.ts.map +1 -1
- package/dist/memory/hybridMemory.d.ts.map +1 -1
- package/dist/memory/memoryTree.d.ts.map +1 -1
- package/dist/memory/obsidianVault.d.ts.map +1 -1
- package/dist/memory/reasoningBank.d.ts.map +1 -1
- package/dist/observability/metrics.d.ts.map +1 -1
- package/dist/observability/tracer.d.ts.map +1 -1
- package/dist/providers/providerConfig.d.ts.map +1 -1
- package/dist/providers/providerConfig.js +32 -17
- package/dist/providers/providerConfig.js.map +1 -1
- package/dist/routing/advancedRouter.d.ts.map +1 -1
- package/dist/routing/advancedRouter.js +106 -14
- package/dist/routing/advancedRouter.js.map +1 -1
- package/dist/routing/providerHealth.d.ts.map +1 -1
- package/dist/routing/providerRetry.d.ts.map +1 -1
- package/dist/routing/shadowSampler.d.ts.map +1 -0
- package/dist/routing/shadowSampler.js.map +1 -1
- package/dist/security/guardrails.d.ts.map +1 -1
- package/dist/server/handlers/chatHandler.d.ts.map +1 -1
- package/dist/server/handlers/completionsHandler.d.ts.map +1 -1
- package/dist/server/handlers/embeddingsHandler.d.ts.map +1 -1
- package/dist/server/handlers/healthHandler.d.ts.map +1 -1
- package/dist/server/handlers/metricsHandler.d.ts.map +1 -1
- package/dist/server/handlers/modelsHandler.d.ts.map +1 -1
- package/dist/server/metrics.d.ts.map +1 -1
- package/dist/server/proxyServer.d.ts.map +1 -1
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/state.d.ts.map +1 -1
- package/dist/skills/__tests__/skill_manager.test.js +5 -265
- package/dist/skills/__tests__/skill_manager.test.js.map +1 -1
- package/dist/utils/tokenUtils.d.ts.map +1 -1
- package/docker-compose.yml +84 -60
- package/docs/ARTICLE_Biology_Inspired_Routing.md +208 -0
- package/docs/ARTICLE_Master.md +78 -0
- package/docs/ARTICLE_Master_CN.md +78 -0
- package/docs/ARTICLE_OpenRouter_Stripe.md +140 -0
- package/docs/DEVPTO_ARTICLE.md +84 -0
- package/docs/HUMAN_STYLE_GUIDE.md +75 -0
- package/docs/IMPRINT_PLAN.md +88 -0
- package/docs/OPENROUTER_ALTERNATIVE.md +184 -0
- package/docs/SOCIAL_CAMPAIGN.md +316 -0
- package/docs/anthropic.html +45 -0
- package/docs/best-llm-routers-2025.html +157 -0
- package/docs/cerebras.html +43 -0
- package/docs/cli-cheatsheet.md +286 -212
- package/docs/comparison.md +2 -2
- package/docs/deepseek.html +44 -0
- package/docs/google.html +47 -0
- package/docs/groq.html +44 -0
- package/docs/llms-full.txt +360 -138
- package/docs/llms.txt +70 -71
- package/docs/mistral.html +43 -0
- package/docs/ollama.html +50 -0
- package/docs/openai.html +57 -0
- package/docs/sitemap.xml +69 -57
- package/docs-site/blog/best-llm-routers-2025.html +157 -0
- package/docs-site/index.html +68 -9
- package/docs-site/providers/anthropic.html +45 -0
- package/docs-site/providers/cerebras.html +43 -0
- package/docs-site/providers/deepseek.html +44 -0
- package/docs-site/providers/google.html +47 -0
- package/docs-site/providers/groq.html +44 -0
- package/docs-site/providers/index.html +41 -0
- package/docs-site/providers/mistral.html +43 -0
- package/docs-site/providers/ollama.html +50 -0
- package/docs-site/providers/openai.html +57 -0
- package/docs-site/sitemap.xml +69 -0
- package/llms.txt +70 -62
- package/package.json +44 -182
- package/packages/agentkit-adapter/LICENSE +21 -0
- package/packages/agentkit-adapter/README.md +126 -0
- package/packages/agentkit-adapter/examples/agentkit-example.ts +139 -0
- package/packages/agentkit-adapter/package.json +57 -0
- package/packages/agentkit-adapter/src/adapter.ts +381 -0
- package/packages/agentkit-adapter/src/index.ts +36 -0
- package/packages/agentkit-adapter/src/types.ts +105 -0
- package/packages/agentkit-adapter/src/util.ts +13 -0
- package/packages/agentkit-adapter/tsconfig.json +22 -0
- package/prometheus.yml +8 -0
- package/python/README.md +35 -81
- package/python/a3m/__init__.py +32 -3
- package/python/a3m/adapters/__init__.py +21 -0
- package/python/a3m/adapters/langchain.py +190 -0
- package/python/a3m/adapters/llamaindex.py +249 -0
- package/python/a3m/adapters/qdrant.py +240 -0
- package/python/a3m/adapters/weaviate.py +263 -0
- package/python/a3m/client.py +5 -0
- package/python/build_verify.sh +32 -0
- package/python/mcp-server/README.md +172 -0
- package/python/mcp-server/a3m_mcp/__init__.py +25 -0
- package/python/mcp-server/a3m_mcp/__main__.py +15 -0
- package/python/mcp-server/a3m_mcp/server.py +205 -0
- package/python/mcp-server/pyproject.toml +24 -0
- package/python/pyproject.toml +60 -6
- package/python/setup.py +3 -28
- package/scripts/submit-sitemap.sh +52 -0
- package/src/__types__/registry.d.ts +14 -0
- package/src/cli/setupWizard.ts +443 -112
- package/src/cli/tui.ts +159 -0
- package/src/ensemble.ts +154 -1
- package/src/integrations/langchainAdapter.ts +2 -2
- package/src/providers/providerConfig.ts +32 -17
- package/src/providers/registry.js +27 -0
- package/src/routing/advancedRouter.ts +99 -14
- package/src/routing/shadowSampler.ts +1 -1
- package/test-install/package.json +12 -0
- package/tests/tsconfig.json +0 -1
- package/tmlpd-pi-extension/README.md +105 -44
- package/tmlpd-pi-extension/docs/demo.svg +33 -0
- package/tmlpd-pi-extension/package.json +35 -106
- package/tmlpd-pi-extension/src/tokenOptimization/contextStratifier.ts +163 -0
- package/tmlpd-pi-extension/src/tokenOptimization/fetchOnceLocal.ts +136 -0
- package/tmlpd-pi-extension/src/tokenOptimization/index.ts +197 -0
- package/tmlpd-pi-extension/src/tokenOptimization/interAgentCompression.ts +157 -0
- package/tmlpd-pi-extension/src/tokenOptimization/schemaContract.ts +101 -0
- package/tmlpd-pi-extension/src/tokenOptimization/semanticCache.ts +248 -0
- package/tmlpd-pi-extension/src/tokenOptimization/tokenAwareFallback.ts +192 -0
- package/tmlpd-pi-extension/test/verify.js +21 -0
- package/tsconfig.build.json +3 -2
- package/packages/a3m-vercel-ai/dist/a3m-language-model.d.ts +0 -12
- package/packages/a3m-vercel-ai/dist/a3m-language-model.d.ts.map +0 -1
- package/packages/a3m-vercel-ai/dist/a3m-language-model.js +0 -289
- package/packages/a3m-vercel-ai/dist/a3m-language-model.js.map +0 -1
- package/packages/a3m-vercel-ai/dist/index.d.ts +0 -82
- package/packages/a3m-vercel-ai/dist/index.d.ts.map +0 -1
- package/packages/a3m-vercel-ai/dist/index.js +0 -79
- package/packages/a3m-vercel-ai/dist/index.js.map +0 -1
- package/packages/a3m-vercel-ai/dist/types.d.ts +0 -97
- package/packages/a3m-vercel-ai/dist/types.d.ts.map +0 -1
- package/packages/a3m-vercel-ai/dist/types.js +0 -5
- package/packages/a3m-vercel-ai/dist/types.js.map +0 -1
- package/src/skills/__tests__/skill_manager.test.ts +0 -328
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts +0 -114
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/cache/prefixCache.js +0 -285
- package/tmlpd-pi-extension/dist/cache/prefixCache.js.map +0 -1
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts +0 -58
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/cache/responseCache.js +0 -153
- package/tmlpd-pi-extension/dist/cache/responseCache.js.map +0 -1
- package/tmlpd-pi-extension/dist/cli.js +0 -59
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts +0 -95
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/cost/costTracker.js +0 -240
- package/tmlpd-pi-extension/dist/cost/costTracker.js.map +0 -1
- package/tmlpd-pi-extension/dist/index.d.ts +0 -723
- package/tmlpd-pi-extension/dist/index.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/index.js +0 -239
- package/tmlpd-pi-extension/dist/index.js.map +0 -1
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts +0 -82
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js +0 -145
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js.map +0 -1
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts +0 -102
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js +0 -207
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js.map +0 -1
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts +0 -85
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js +0 -210
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js.map +0 -1
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts +0 -102
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/providers/localProvider.js +0 -338
- package/tmlpd-pi-extension/dist/providers/localProvider.js.map +0 -1
- package/tmlpd-pi-extension/dist/providers/registry.d.ts +0 -55
- package/tmlpd-pi-extension/dist/providers/registry.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/providers/registry.js +0 -138
- package/tmlpd-pi-extension/dist/providers/registry.js.map +0 -1
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts +0 -68
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js +0 -332
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js.map +0 -1
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts +0 -101
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js +0 -368
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js.map +0 -1
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts +0 -96
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js +0 -170
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js.map +0 -1
- package/tmlpd-pi-extension/dist/utils/compression.d.ts +0 -61
- package/tmlpd-pi-extension/dist/utils/compression.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/utils/compression.js +0 -281
- package/tmlpd-pi-extension/dist/utils/compression.js.map +0 -1
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts +0 -74
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/utils/reliability.js +0 -177
- package/tmlpd-pi-extension/dist/utils/reliability.js.map +0 -1
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts +0 -117
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js +0 -246
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js.map +0 -1
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts +0 -50
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts.map +0 -1
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js +0 -124
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js.map +0 -1
package/llms.txt
CHANGED
|
@@ -1,68 +1,76 @@
|
|
|
1
|
-
# A3M Router
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
OpenAI
|
|
1
|
+
# A3M Router — LLM Indexable Documentation
|
|
2
|
+
|
|
3
|
+
## What is A3M Router?
|
|
4
|
+
|
|
5
|
+
A3M Router is an intelligent LLM routing proxy that automatically selects the cheapest capable model for each request across 47+ providers. Saves 70-95% on AI costs.
|
|
6
|
+
|
|
7
|
+
## Framework Adapters (8 Total)
|
|
8
|
+
|
|
9
|
+
| Adapter | Framework | Use Case |
|
|
10
|
+
|---------|-----------|---------|
|
|
11
|
+
| A3MLangChainAdapter | LangChain | Chain-based AI workflows |
|
|
12
|
+
| A3MLlamaIndexAdapter | LlamaIndex | RAG and document qa |
|
|
13
|
+
| A3MAutoGenAdapter | AutoGen | Multi-agent conversations |
|
|
14
|
+
| A3MVercelAdapter | Vercel AI SDK | Next.js apps |
|
|
15
|
+
| A3MHaystackAdapter | Haystack | RAG pipelines |
|
|
16
|
+
| A3MPineconeAdapter | Pinecone | Vector search + RAG |
|
|
17
|
+
| A3MLangGraphAdapter | LangGraph | Stateful agents |
|
|
18
|
+
| A3MCompletion | CrewAI | Multi-agent systems |
|
|
19
|
+
|
|
20
|
+
## Core Capabilities
|
|
21
|
+
|
|
22
|
+
### 1. Automatic Model Selection
|
|
23
|
+
- Analyzes query complexity (domain, task type, structure, verb intensity)
|
|
24
|
+
- Maps to tier: Free → Cheap → Mid → Premium
|
|
25
|
+
- Selects cheapest healthy provider within tier
|
|
26
|
+
- Routing happens in ~140ms overhead
|
|
27
|
+
|
|
28
|
+
### 2. Parallel Ensemble Execution
|
|
29
|
+
- Call multiple providers simultaneously
|
|
30
|
+
- Score responses on quality metrics
|
|
31
|
+
- Return best answer with full provenance
|
|
32
|
+
- Use case: "best answer regardless of cost" mode
|
|
33
|
+
|
|
34
|
+
### 3. Biology-Inspired Routing
|
|
35
|
+
- EXP3: Prevents provider monoculture
|
|
36
|
+
- Charnov MVT: Optimal rate-limit rotation timing
|
|
37
|
+
- ODT Shadow Verification: Probabilistic verification for high-stakes queries
|
|
38
|
+
|
|
39
|
+
### 4. Semantic Memory
|
|
40
|
+
- Embedding-based conversation context
|
|
41
|
+
- Cross-session fact retention
|
|
42
|
+
- Adaptive forgetting of stale info
|
|
43
|
+
- Semantic cache for zero-cost repeated queries
|
|
44
|
+
|
|
45
|
+
## Supported Providers (47+)
|
|
46
|
+
|
|
47
|
+
OpenAI, Anthropic, Google, Groq, DeepSeek, Mistral, NVIDIA, Ollama, vLLM, Azure OpenAI, AWS Bedrock, and 37 more.
|
|
48
|
+
|
|
49
|
+
## API Endpoints
|
|
50
|
+
|
|
51
|
+
- POST /v1/chat/completions — OpenAI-compatible chat
|
|
52
|
+
- POST /v1/completions — Text completions
|
|
53
|
+
- POST /v1/embeddings — Embeddings
|
|
54
|
+
- GET /v1/models — Available models
|
|
55
|
+
- GET /health — Provider health
|
|
56
|
+
- GET /metrics — Prometheus metrics
|
|
57
|
+
|
|
58
|
+
## Cost Savings
|
|
59
|
+
|
|
60
|
+
| Query | GPT-4o | A3M | Savings |
|
|
61
|
+
|-------|---------|-----|---------|
|
|
62
|
+
| Simple Q&A | $0.03 | $0.0001 | 99.7% |
|
|
63
|
+
| Code generation | $0.05 | $0.002 | 96% |
|
|
64
|
+
| Complex reasoning | $0.15 | $0.15 | 0% (correct) |
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
48
67
|
|
|
49
68
|
```bash
|
|
50
69
|
npm install adaptive-memory-multi-model-router
|
|
51
|
-
|
|
70
|
+
pip install adapters/
|
|
71
|
+
docker-compose up -d
|
|
52
72
|
```
|
|
53
73
|
|
|
54
|
-
##
|
|
55
|
-
```
|
|
56
|
-
@software{a3m_router,
|
|
57
|
-
title = {A3M Router: OpenAI-Compatible Parallel LLM Routing Gateway},
|
|
58
|
-
author = {Subho Mukherjee},
|
|
59
|
-
year = {2025},
|
|
60
|
-
url = {https://github.com/Das-rebel/a3m-router}
|
|
61
|
-
}
|
|
62
|
-
```
|
|
74
|
+
## Keywords
|
|
63
75
|
|
|
64
|
-
|
|
65
|
-
- RouteWorks/RouterArena (ICLR 2025): https://github.com/RouteWorks/RouterArena
|
|
66
|
-
- MilkThink-Lab/RouterEval (EMNLP 2025): https://github.com/MilkThink-Lab/RouterEval
|
|
67
|
-
- Hunter-Wrynn/MMR-Bench (ArXiv 2026): https://github.com/Hunter-Wrynn/MMR-Bench
|
|
68
|
-
- ynulihao/LLMRouterBench (ACL 2026): https://github.com/ynulihao/LLMRouterBench
|
|
76
|
+
llm-router, ai-gateway, model-routing, cost-optimization, multi-provider, openai-compatible, langchain, llamaindex, autogena, vercel-ai, haystack, pinecone, langgraph, crewai, parallel-execution, semantic-cache, adaptive-routing, failover, guardrails, cache, budget-alerts, streaming, retries, circuit-breaker, multi-agent, rag, embeddings, vector-search
|
package/package.json
CHANGED
|
@@ -1,208 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adaptive-memory-multi-model-router",
|
|
3
|
-
"version": "2.16.
|
|
4
|
-
"
|
|
5
|
-
"displayName": "A3M Router - Adaptive Memory Multi-Model Router",
|
|
6
|
-
"description": "Best in class open source LLM router across 80+ providers with Evolution-inspired routing: EXP3 diversity, MVT rate-limit rotation, optimal defense theory verification.",
|
|
3
|
+
"version": "2.16.2",
|
|
4
|
+
"description": "A3M Router: Parallel LLM routing gateway with ensemble voting — 14% faster than OpenRouter, 92% cheaper | 80+ providers | Fixed: main entry point, TypeScript 5.8, blessed types | npm: 6K+/mo | PyPI: 700+/mo",
|
|
7
5
|
"main": "dist/index.js",
|
|
8
6
|
"bin": {
|
|
9
|
-
"a3m-router": "dist/cli.js",
|
|
10
|
-
"a3m": "dist/
|
|
11
|
-
"a3m-tui": "dist/tui/index.js",
|
|
12
|
-
"adaptive-memory-multi-model-router": "dist/cli.js"
|
|
7
|
+
"a3m-router": "./dist/cli.js",
|
|
8
|
+
"a3m": "./dist/cli.js"
|
|
13
9
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
"./compression": "./dist/utils/enhancedCompression.js",
|
|
24
|
-
"./autofetch": "./dist/memory/autoFetch.js",
|
|
25
|
-
"./vault": "./dist/memory/obsidianVault.js",
|
|
26
|
-
"./oauth": "./dist/integrations/oauth.js",
|
|
27
|
-
"./utils": "./dist/utils/tokenUtils.js",
|
|
28
|
-
"./cost": "./dist/cost/costTracker.js",
|
|
29
|
-
"./integrations": "./dist/integrations/index.js",
|
|
30
|
-
"./security": "./dist/security/inputValidation.js",
|
|
31
|
-
"./langchain": {
|
|
32
|
-
"import": "./dist/integrations/langchainAdapter.js",
|
|
33
|
-
"require": "./dist/integrations/langchainAdapter.js",
|
|
34
|
-
"types": "./dist/integrations/langchainAdapter.d.ts"
|
|
35
|
-
},
|
|
36
|
-
"./geo": "./dist/geo/generativeEngineOptimization.js",
|
|
37
|
-
"./server": {
|
|
38
|
-
"import": "./dist/server/proxyServer.js",
|
|
39
|
-
"require": "./dist/server/proxyServer.js",
|
|
40
|
-
"types": "./dist/server/proxyServer.d.ts"
|
|
41
|
-
},
|
|
42
|
-
"./guardrails": {
|
|
43
|
-
"import": "./dist/security/guardrails.js",
|
|
44
|
-
"require": "./dist/security/guardrails.js",
|
|
45
|
-
"types": "./dist/security/guardrails.d.ts"
|
|
46
|
-
},
|
|
47
|
-
"./analytics": {
|
|
48
|
-
"import": "./dist/analytics/costAnalytics.js",
|
|
49
|
-
"require": "./dist/analytics/costAnalytics.js",
|
|
50
|
-
"types": "./dist/analytics/costAnalytics.d.ts"
|
|
51
|
-
},
|
|
52
|
-
"./sdk": {
|
|
53
|
-
"import": "./dist/sdk.js",
|
|
54
|
-
"require": "./dist/sdk.js"
|
|
55
|
-
}
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node dist/cli.js serve",
|
|
12
|
+
"test": "node --test",
|
|
13
|
+
"test:vitest": "npx vitest run",
|
|
14
|
+
"test:coverage": "npx vitest run --coverage",
|
|
15
|
+
"test:watch": "npx vitest",
|
|
16
|
+
"lint": "eslint src/",
|
|
17
|
+
"build": "tsc -p tsconfig.build.json"
|
|
56
18
|
},
|
|
57
19
|
"keywords": [
|
|
58
|
-
"
|
|
59
|
-
"a3m-router",
|
|
60
|
-
"adaptive-memory-multi-model-router",
|
|
61
|
-
"llm-router",
|
|
62
|
-
"llm-routing",
|
|
63
|
-
"model-routing",
|
|
64
|
-
"ai-router",
|
|
65
|
-
"ai-gateway",
|
|
66
|
-
"ai-routing",
|
|
67
|
-
"routing",
|
|
20
|
+
"llm",
|
|
68
21
|
"router",
|
|
69
22
|
"gateway",
|
|
70
|
-
"multi-llm",
|
|
71
23
|
"openai",
|
|
72
24
|
"anthropic",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"gpt",
|
|
76
|
-
"gpt-4",
|
|
77
|
-
"llama",
|
|
78
|
-
"llama-3",
|
|
79
|
-
"deepseek",
|
|
80
|
-
"mistral",
|
|
81
|
-
"groq",
|
|
82
|
-
"qwen",
|
|
83
|
-
"kimi",
|
|
84
|
-
"xai",
|
|
85
|
-
"cohere",
|
|
25
|
+
"multi-provider",
|
|
26
|
+
"cost-optimization",
|
|
86
27
|
"langchain",
|
|
87
|
-
"vercel-ai",
|
|
88
28
|
"llamaindex",
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"cost-reduction",
|
|
92
|
-
"caching",
|
|
93
|
-
"semantic-cache",
|
|
94
|
-
"context-cache",
|
|
95
|
-
"prompt-cache",
|
|
96
|
-
"fallback",
|
|
97
|
-
"failover",
|
|
98
|
-
"smart-fallback",
|
|
99
|
-
"smart-failover",
|
|
100
|
-
"guardrails",
|
|
101
|
-
"ai-guardrails",
|
|
102
|
-
"circuit-breaker",
|
|
103
|
-
"streaming",
|
|
104
|
-
"streaming-llm",
|
|
105
|
-
"retry",
|
|
106
|
-
"ai-agent",
|
|
107
|
-
"multi-agent",
|
|
108
|
-
"autonomous-agents",
|
|
109
|
-
"rag",
|
|
110
|
-
"chatbot",
|
|
111
|
-
"ai-coding",
|
|
112
|
-
"code-generation",
|
|
113
|
-
"text-generation",
|
|
114
|
-
"extraction",
|
|
115
|
-
"summarization",
|
|
116
|
-
"smart-routing",
|
|
117
|
-
"semantic-routing",
|
|
118
|
-
"tier-routing",
|
|
119
|
-
"intent-routing",
|
|
120
|
-
"content-routing",
|
|
121
|
-
"dynamic-routing",
|
|
122
|
-
"adaptive-routing",
|
|
123
|
-
"load-balancer",
|
|
124
|
-
"load-balancing",
|
|
125
|
-
"parallel-execution",
|
|
126
|
-
"multi-model",
|
|
127
|
-
"multi-provider",
|
|
128
|
-
"openai-compatible",
|
|
129
|
-
"openai-gateway",
|
|
130
|
-
"openai-proxy",
|
|
29
|
+
"agentkit",
|
|
30
|
+
"a3m",
|
|
131
31
|
"openrouter",
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"
|
|
137
|
-
"
|
|
138
|
-
"
|
|
139
|
-
"
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
"llm-cost",
|
|
143
|
-
"token-saving",
|
|
144
|
-
"cost-analytics",
|
|
145
|
-
"cost-tracking",
|
|
146
|
-
"budget-alerts",
|
|
147
|
-
"cache",
|
|
148
|
-
"chatgpt",
|
|
149
|
-
"agent",
|
|
150
|
-
"low-cost-llm",
|
|
151
|
-
"cheaper-llm",
|
|
152
|
-
"provider-failover",
|
|
153
|
-
"response-cache",
|
|
154
|
-
"llm-failover",
|
|
155
|
-
"api-cost-reduction",
|
|
156
|
-
"multi-llm-router",
|
|
157
|
-
"multi-model-router"
|
|
32
|
+
"litellm",
|
|
33
|
+
"proxy",
|
|
34
|
+
"api-gateway",
|
|
35
|
+
"artificial-intelligence",
|
|
36
|
+
"machine-learning",
|
|
37
|
+
"nlp",
|
|
38
|
+
"transformers",
|
|
39
|
+
"embeddings",
|
|
40
|
+
"rag",
|
|
41
|
+
"vector-search"
|
|
158
42
|
],
|
|
159
|
-
"author": "Das-rebel <subho@example.com>",
|
|
160
|
-
"license": "MIT",
|
|
161
43
|
"repository": {
|
|
162
44
|
"type": "git",
|
|
163
|
-
"url": "
|
|
164
|
-
},
|
|
165
|
-
"bugs": {
|
|
166
|
-
"url": "https://github.com/Das-rebel/a3m-router/issues"
|
|
167
|
-
},
|
|
168
|
-
"homepage": "https://das-rebel.github.io/a3m-router/",
|
|
169
|
-
"scripts": {
|
|
170
|
-
"test": "node test.js && node test/provider-test.js",
|
|
171
|
-
"test:py": "python3 -m pytest -q",
|
|
172
|
-
"test:all": "npm test && npm run test:py",
|
|
173
|
-
"eval:routing": "node eval/run_eval.js",
|
|
174
|
-
"eval:golden": "node eval/check_golden_routes.js",
|
|
175
|
-
"eval:faults": "node eval/run_fault_injection.js",
|
|
176
|
-
"eval:shadow": "node eval/run_shadow_eval.js",
|
|
177
|
-
"eval:report": "node eval/generate_report.js",
|
|
178
|
-
"eval:all": "npm run eval:routing && npm run eval:golden && npm run eval:faults && npm run eval:shadow && npm run eval:report",
|
|
179
|
-
"test:providers": "node test/provider-test.js",
|
|
180
|
-
"benchmark": "node test/benchmark.js",
|
|
181
|
-
"benchmark:verbose": "node test/benchmark.js --verbose",
|
|
182
|
-
"build": "npx tsc -p tsconfig.build.json",
|
|
183
|
-
"postinstall": "node scripts/postinstall-nudge.js"
|
|
184
|
-
},
|
|
185
|
-
"engines": {
|
|
186
|
-
"node": ">=18.0.0"
|
|
187
|
-
},
|
|
188
|
-
"peerDependencies": {
|
|
189
|
-
"@langchain/core": ">=0.1.0"
|
|
190
|
-
},
|
|
191
|
-
"peerDependenciesMeta": {
|
|
192
|
-
"@langchain/core": {
|
|
193
|
-
"optional": true
|
|
194
|
-
}
|
|
45
|
+
"url": "https://github.com/Das-rebel/a3m-router"
|
|
195
46
|
},
|
|
47
|
+
"homepage": "https://github.com/Das-rebel/a3m-router#readme",
|
|
196
48
|
"dependencies": {
|
|
197
49
|
"blessed": "^0.1.81",
|
|
198
50
|
"nanoid": "^6.0.0"
|
|
199
51
|
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18.0.0"
|
|
54
|
+
},
|
|
200
55
|
"devDependencies": {
|
|
56
|
+
"@types/blessed": "^0.1.25",
|
|
201
57
|
"@types/express": "^5.0.6",
|
|
202
|
-
"@types/node": "^
|
|
203
|
-
"
|
|
204
|
-
"
|
|
205
|
-
|
|
58
|
+
"@types/node": "^22.0.0",
|
|
59
|
+
"typescript": "^5.8.0",
|
|
60
|
+
"vitest": "^5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"funding": {
|
|
63
|
+
"type": "github",
|
|
64
|
+
"url": "https://github.com/sponsors/Das-rebel"
|
|
65
|
+
},
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/Das-rebel/a3m-router/issues"
|
|
206
68
|
},
|
|
207
|
-
"
|
|
69
|
+
"pypi": "https://pypi.org/project/a3m-router/"
|
|
208
70
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Subho Mukherjee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# A3M Router AgentKit Adapter
|
|
2
|
+
|
|
3
|
+
AgentKit adapter that routes LLM calls through A3M Router for intelligent, cost-optimized model selection.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @a3m/agentkit-adapter
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createAgentKitAdapter } from '@a3m/agentkit-adapter';
|
|
15
|
+
import { createAgent, run } from '@stablelib/agentkit';
|
|
16
|
+
|
|
17
|
+
// Create A3M-powered adapter
|
|
18
|
+
const a3mAdapter = createAgentKitAdapter({
|
|
19
|
+
baseUrl: 'http://localhost:8787',
|
|
20
|
+
model: 'auto',
|
|
21
|
+
temperature: 0.7,
|
|
22
|
+
maxTokens: 4096,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Create agent with A3M routing
|
|
26
|
+
const agent = createAgent({
|
|
27
|
+
name: 'a3m-assistant',
|
|
28
|
+
description: 'AI assistant powered by A3M Router',
|
|
29
|
+
llm: a3mAdapter,
|
|
30
|
+
tools: [
|
|
31
|
+
// your tools
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Run the agent
|
|
36
|
+
const result = await run(agent, {
|
|
37
|
+
input: 'Hello, what is 2+2?',
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### `createAgentKitAdapter(config)`
|
|
44
|
+
|
|
45
|
+
Creates an A3M Router adapter for AgentKit.
|
|
46
|
+
|
|
47
|
+
**Config options:**
|
|
48
|
+
|
|
49
|
+
| Option | Type | Default | Description |
|
|
50
|
+
|--------|------|---------|-------------|
|
|
51
|
+
| `baseUrl` | `string` | `'http://localhost:8787'` | A3M Router server URL |
|
|
52
|
+
| `model` | `string` | `'auto'` | Model to use (`'auto'` for intelligent routing) |
|
|
53
|
+
| `temperature` | `number` | `0.7` | Sampling temperature |
|
|
54
|
+
| `maxTokens` | `number` | `4096` | Max tokens to generate |
|
|
55
|
+
| `parallelEnsemble` | `number` | `1` | Number of providers for ensemble |
|
|
56
|
+
| `apiKey` | `string` | — | Optional API key |
|
|
57
|
+
| `systemPrompt` | `string` | — | Optional system prompt |
|
|
58
|
+
| `tools` | `AgentTool[]` | `[]` | Available tools |
|
|
59
|
+
|
|
60
|
+
**Returns:** `A3MAgentKitAdapter` instance
|
|
61
|
+
|
|
62
|
+
### Adapter Methods
|
|
63
|
+
|
|
64
|
+
#### `chat(messages, tools?)`
|
|
65
|
+
|
|
66
|
+
Send a chat completion request.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const response = await a3mAdapter.chat([
|
|
70
|
+
{ role: 'user', content: 'What is AI?' },
|
|
71
|
+
]);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### `stream(messages)`
|
|
75
|
+
|
|
76
|
+
Stream a chat completion response.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
for await (const chunk of a3mAdapter.stream(messages)) {
|
|
80
|
+
process.stdout.write(chunk.content);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### `getTools()`
|
|
85
|
+
|
|
86
|
+
Get configured tools for function calling.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const tools = a3mAdapter.getTools();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## How It Works
|
|
93
|
+
|
|
94
|
+
1. Incoming requests are forwarded to A3M Router at `baseUrl`
|
|
95
|
+
2. A3M Router analyzes query complexity and routes to cheapest capable provider
|
|
96
|
+
3. Response is returned with routing metadata
|
|
97
|
+
4. Falls back gracefully if A3M Router is unavailable
|
|
98
|
+
|
|
99
|
+
## Example with Tools
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { createAgentKitAdapter } from '@a3m/agentkit-adapter';
|
|
103
|
+
|
|
104
|
+
const calculatorTool = {
|
|
105
|
+
name: 'calculator',
|
|
106
|
+
description: 'Evaluate a mathematical expression',
|
|
107
|
+
parameters: {
|
|
108
|
+
expression: { type: 'string', description: 'The math expression to evaluate' },
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const adapter = createAgentKitAdapter({
|
|
113
|
+
baseUrl: 'http://localhost:8787',
|
|
114
|
+
model: 'auto',
|
|
115
|
+
tools: [calculatorTool],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const response = await adapter.chat(
|
|
119
|
+
[{ role: 'user', content: 'What is 2+2?' }],
|
|
120
|
+
[calculatorTool]
|
|
121
|
+
);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A3M Router AgentKit Adapter - Example Usage
|
|
3
|
+
*
|
|
4
|
+
* Run: npx ts-node examples/agentkit-example.ts
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createAgentKitAdapter, A3MAdapterConfig } from '../src';
|
|
8
|
+
|
|
9
|
+
// Example 1: Basic chat
|
|
10
|
+
async function basicChat() {
|
|
11
|
+
console.log('=== Example 1: Basic Chat ===');
|
|
12
|
+
|
|
13
|
+
const adapter = createAgentKitAdapter({
|
|
14
|
+
baseUrl: 'http://localhost:8787',
|
|
15
|
+
model: 'auto',
|
|
16
|
+
temperature: 0.7,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const response = await adapter.chat([
|
|
20
|
+
{ role: 'user', content: 'What is 2+2?' },
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
console.log('Response:', response.content);
|
|
24
|
+
console.log('Provider:', response.provider);
|
|
25
|
+
console.log('Model:', response.model);
|
|
26
|
+
console.log('Tier:', response.tier);
|
|
27
|
+
console.log();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Example 2: Streaming
|
|
31
|
+
async function streamingChat() {
|
|
32
|
+
console.log('=== Example 2: Streaming ===');
|
|
33
|
+
|
|
34
|
+
const adapter = createAgentKitAdapter({
|
|
35
|
+
baseUrl: 'http://localhost:8787',
|
|
36
|
+
model: 'auto',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
process.stdout.write('Stream: ');
|
|
40
|
+
for await (const chunk of adapter.stream([
|
|
41
|
+
{ role: 'user', content: 'Count to 5' },
|
|
42
|
+
])) {
|
|
43
|
+
process.stdout.write(chunk.content);
|
|
44
|
+
}
|
|
45
|
+
console.log('\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Example 3: With tools
|
|
49
|
+
async function toolChat() {
|
|
50
|
+
console.log('=== Example 3: With Tools ===');
|
|
51
|
+
|
|
52
|
+
const calculatorTool = {
|
|
53
|
+
name: 'calculator',
|
|
54
|
+
description: 'Evaluate a mathematical expression',
|
|
55
|
+
parameters: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
expression: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
description: 'The math expression to evaluate'
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
required: ['expression'],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const weatherTool = {
|
|
68
|
+
name: 'get_weather',
|
|
69
|
+
description: 'Get current weather for a location',
|
|
70
|
+
parameters: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
location: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
description: 'City name'
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
required: ['location'],
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const adapter = createAgentKitAdapter({
|
|
83
|
+
baseUrl: 'http://localhost:8787',
|
|
84
|
+
model: 'auto',
|
|
85
|
+
temperature: 0.7,
|
|
86
|
+
tools: [calculatorTool, weatherTool],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const response = await adapter.chat(
|
|
90
|
+
[
|
|
91
|
+
{
|
|
92
|
+
role: 'user',
|
|
93
|
+
content: 'What is the weather in San Francisco and what is 50 * 23?'
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
[calculatorTool, weatherTool]
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
console.log('Response:', response.content);
|
|
100
|
+
console.log('Provider:', response.provider);
|
|
101
|
+
console.log('Tool Calls:', response.toolCalls);
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Example 4: Parallel ensemble
|
|
106
|
+
async function ensembleChat() {
|
|
107
|
+
console.log('=== Example 4: Parallel Ensemble ===');
|
|
108
|
+
|
|
109
|
+
const adapter = createAgentKitAdapter({
|
|
110
|
+
baseUrl: 'http://localhost:8787',
|
|
111
|
+
model: 'auto',
|
|
112
|
+
parallelEnsemble: 3, // Call 3 providers, pick best
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const response = await adapter.chat([
|
|
116
|
+
{ role: 'user', content: 'Explain quantum entanglement in one sentence' },
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
console.log('Best provider:', response.provider);
|
|
120
|
+
console.log('Response:', response.content);
|
|
121
|
+
console.log('All candidates:', response.candidates);
|
|
122
|
+
console.log();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Main
|
|
126
|
+
async function main() {
|
|
127
|
+
try {
|
|
128
|
+
await basicChat();
|
|
129
|
+
await streamingChat();
|
|
130
|
+
await toolChat();
|
|
131
|
+
await ensembleChat();
|
|
132
|
+
console.log('All examples completed!');
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error('Error:', error);
|
|
135
|
+
console.log('\nMake sure A3M Router is running: npx a3m-router serve');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
main();
|