adaptive-memory-multi-model-router 1.6.0 → 1.7.1
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 +278 -23
- package/dist/index.js +91 -2
- package/docs/API.md +562 -0
- package/docs/INTEGRATIONS.md +420 -0
- package/docs/QUICKSTART.md +271 -0
- package/package.json +132 -55
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# A3M Router - Integration Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
A3M Router includes **116 integrations** across multiple categories:
|
|
6
|
+
|
|
7
|
+
| Category | Count | Examples |
|
|
8
|
+
|----------|-------|----------|
|
|
9
|
+
| Project Management | 15+ | Asana, Trello, Linear, ClickUp, Monday |
|
|
10
|
+
| CRM & Support | 8+ | HubSpot, Salesforce, Zendesk, Intercom |
|
|
11
|
+
| Marketing | 6+ | Mailchimp, SendGrid, Segment |
|
|
12
|
+
| Analytics | 6+ | Mixpanel, Amplitude, PostHog, Datadog |
|
|
13
|
+
| Communication | 10+ | Slack, Teams, Twilio, Zoom |
|
|
14
|
+
| AI & Vector DBs | 8+ | Pinecone, Weaviate, Qdrant, Chroma |
|
|
15
|
+
| Storage | 5+ | S3, GCS, Azure Blob, Dropbox |
|
|
16
|
+
| Payments | 5+ | Stripe, Square, Braintree, Shopify |
|
|
17
|
+
| Social | 4+ | Twitter, Instagram, LinkedIn |
|
|
18
|
+
| IoT | 5+ | Hue, Wemo, Sonos |
|
|
19
|
+
| DevOps | 10+ | Jenkins, GitLab, Bitbucket, Vercel |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { createIntegration } from 'adaptive-memory-multi-model-router/integrations';
|
|
27
|
+
|
|
28
|
+
// GitHub
|
|
29
|
+
const github = createIntegration('github', { apiKey: 'your-token' });
|
|
30
|
+
await github.createIssue('owner', 'repo', 'Bug fix', 'Description');
|
|
31
|
+
|
|
32
|
+
// Slack
|
|
33
|
+
const slack = createIntegration('slack', { webhookUrl: 'https://hooks.slack.com/...' });
|
|
34
|
+
await slack.sendMessage('#alerts', 'Build complete!');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Project Management Integrations
|
|
40
|
+
|
|
41
|
+
### Asana
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { AsanaIntegration } from 'adaptive-memory-multi-model-router/integrations/asana';
|
|
45
|
+
|
|
46
|
+
const asana = new AsanaIntegration(process.env.ASANA_API_KEY);
|
|
47
|
+
|
|
48
|
+
// Create task
|
|
49
|
+
await asana.createTask(
|
|
50
|
+
workspaceId = '123456',
|
|
51
|
+
projectId = '789012',
|
|
52
|
+
name = 'Implement feature',
|
|
53
|
+
notes = 'Description here'
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Get tasks
|
|
57
|
+
const tasks = await asana.getTasks(projectId);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Trello
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import { TrelloIntegration } from 'adaptive-memory-multi-model-router/integrations/trello';
|
|
64
|
+
|
|
65
|
+
const trello = new TrelloIntegration(
|
|
66
|
+
process.env.TRELLO_API_KEY,
|
|
67
|
+
process.env.TRELLO_TOKEN
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await trello.createCard(boardId, listId, 'New Card', 'Description');
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Linear
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
import { LinearIntegration } from 'adaptive-memory-multi-model-router/integrations/linear';
|
|
77
|
+
|
|
78
|
+
const linear = new LinearIntegration(process.env.LINEAR_API_KEY);
|
|
79
|
+
|
|
80
|
+
await linear.createIssue('Fix bug', 'team-id');
|
|
81
|
+
const teams = await linear.getTeams();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Monday
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
import { MondayIntegration } from 'adaptive-memory-multi-model-router/integrations/monday';
|
|
88
|
+
|
|
89
|
+
const monday = new MondayIntegration(process.env.MONDAY_API_KEY);
|
|
90
|
+
|
|
91
|
+
const boards = await monday.getBoards();
|
|
92
|
+
await monday.createItem(boardId, 'New Item');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## CRM & Customer Support
|
|
98
|
+
|
|
99
|
+
### HubSpot
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
import { HubSpotIntegration } from 'adaptive-memory-multi-model-router/integrations/hubspot';
|
|
103
|
+
|
|
104
|
+
const hubspot = new HubSpotIntegration(process.env.HUBSPOT_API_KEY);
|
|
105
|
+
|
|
106
|
+
const contacts = await hubspot.getContacts(100);
|
|
107
|
+
await hubspot.createContact('customer@example.com', { firstName: 'John' });
|
|
108
|
+
await hubspot.createDeal('New Deal', { amount: 5000 });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Salesforce
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
import { SalesforceIntegration } from 'adaptive-memory-multi-model-router/integrations/salesforce';
|
|
115
|
+
|
|
116
|
+
const sf = new SalesforceIntegration(
|
|
117
|
+
'https://your-instance.salesforce.com',
|
|
118
|
+
process.env.SF_ACCESS_TOKEN
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const contacts = await sf.query("SELECT Id, Name FROM Contact LIMIT 10");
|
|
122
|
+
await sf.createRecord('Contact', { Email: 'test@example.com', LastName: 'Test' });
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Zendesk
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
import { ZendeskIntegration } from 'adaptive-memory-multi-model-router/integrations/zendesk';
|
|
129
|
+
|
|
130
|
+
const zendesk = new ZendeskIntegration(
|
|
131
|
+
'your-company',
|
|
132
|
+
'agent@example.com',
|
|
133
|
+
process.env.ZENDESK_API_TOKEN
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const tickets = await zendesk.getTickets();
|
|
137
|
+
await zendesk.createTicket('Help needed', 'Description of the issue');
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Communication
|
|
143
|
+
|
|
144
|
+
### Slack
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
import { SlackIntegration } from 'adaptive-memory-multi-model-router/integrations/slack';
|
|
148
|
+
|
|
149
|
+
const slack = new SlackIntegration(process.env.SLACK_WEBHOOK_URL);
|
|
150
|
+
|
|
151
|
+
await slack.sendMessage('#dev-team', 'Deployment complete! 🚀');
|
|
152
|
+
await slack.sendMessage('#alerts', { text: 'High latency detected', icon_emoji: ':warning:' });
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Twilio
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
import { TwilioIntegration } from 'adaptive-memory-multi-model-router/integrations/twilio';
|
|
159
|
+
|
|
160
|
+
const twilio = new TwilioIntegration(
|
|
161
|
+
process.env.TWILIO_ACCOUNT_SID,
|
|
162
|
+
process.env.TWILIO_AUTH_TOKEN
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
await twilio.sendMessage('+1234567890', 'Your code is ready!');
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Zoom
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
import { ZoomIntegration } from 'adaptive-memory-multi-model-router/integrations/zoom';
|
|
172
|
+
|
|
173
|
+
const zoom = new ZoomIntegration(
|
|
174
|
+
process.env.ZOOM_API_KEY,
|
|
175
|
+
process.env.ZOOM_API_SECRET
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const meeting = await zoom.createMeeting('Team Standup', 30);
|
|
179
|
+
console.log('Join URL:', meeting.join_url);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## AI & Vector Databases
|
|
185
|
+
|
|
186
|
+
### Pinecone
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
import { PineconeIntegration } from 'adaptive-memory-multi-model-router/integrations/pinecone';
|
|
190
|
+
|
|
191
|
+
const pinecone = new PineconeIntegration(
|
|
192
|
+
process.env.PINECONE_API_KEY,
|
|
193
|
+
'us-west-2'
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
await pinecone.createIndex('my-index', 1536);
|
|
197
|
+
await pinecone.upsertVectors('my-index', [
|
|
198
|
+
{ id: 'vec1', vector: [...], metadata: { text: 'hello' } }
|
|
199
|
+
]);
|
|
200
|
+
|
|
201
|
+
const results = await pinecone.query('my-index', vector, 10);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Weaviate
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
import { WeaviateIntegration } from 'adaptive-memory-multi-model-router/integrations/weaviate';
|
|
208
|
+
|
|
209
|
+
const weaviate = new WeaviateIntegration(
|
|
210
|
+
'http://localhost:8080',
|
|
211
|
+
process.env.WEAVIATE_API_KEY
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
await weaviate.createObject('Article', { title: 'Hello', content: 'World' });
|
|
215
|
+
const articles = await weaviate.getObjects('Article');
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Storage
|
|
221
|
+
|
|
222
|
+
### S3
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
import { S3Integration } from 'adaptive-memory-multi-model-router/integrations/s3';
|
|
226
|
+
|
|
227
|
+
const s3 = new S3Integration(
|
|
228
|
+
process.env.AWS_ACCESS_KEY_ID,
|
|
229
|
+
process.env.AWS_SECRET_ACCESS_KEY,
|
|
230
|
+
'us-east-1'
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
await s3.putObject('my-bucket', 'path/to/file.txt', 'Hello World');
|
|
234
|
+
const data = await s3.getObject('my-bucket', 'path/to/file.txt');
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Dropbox
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
import { DropboxIntegration } from 'adaptive-memory-multi-model-router/integrations/dropbox';
|
|
241
|
+
|
|
242
|
+
const dropbox = new DropboxIntegration(process.env.DROPBOX_ACCESS_TOKEN);
|
|
243
|
+
|
|
244
|
+
await dropbox.uploadFile('/path/to/file.txt', 'File content');
|
|
245
|
+
const content = await dropbox.downloadFile('/path/to/file.txt');
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Payments
|
|
251
|
+
|
|
252
|
+
### Stripe
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
import { StripeIntegration } from 'adaptive-memory-multi-model-router/integrations/stripe';
|
|
256
|
+
|
|
257
|
+
const stripe = new StripeIntegration(process.env.STRIPE_API_KEY);
|
|
258
|
+
|
|
259
|
+
const charge = await stripe.createCharge(1999, 'usd', 'cus_123');
|
|
260
|
+
const charges = await stripe.getCharges(10);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Shopify
|
|
264
|
+
|
|
265
|
+
```javascript
|
|
266
|
+
import { ShopifyIntegration } from 'adaptive-memory-multi-model-router/integrations/shopify';
|
|
267
|
+
|
|
268
|
+
const shopify = new ShopifyIntegration(
|
|
269
|
+
'my-store.myshopify.com',
|
|
270
|
+
process.env.SHOPIFY_ACCESS_TOKEN
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const products = await shopify.getProducts(50);
|
|
274
|
+
const order = await shopify.createOrder([
|
|
275
|
+
{ variant_id: 123, quantity: 2 }
|
|
276
|
+
]);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Analytics & Monitoring
|
|
282
|
+
|
|
283
|
+
### Mixpanel
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
import { MixpanelIntegration } from 'adaptive-memory-multi-model-router/integrations/mixpanel';
|
|
287
|
+
|
|
288
|
+
const mixpanel = new MixpanelIntegration(process.env.MIXPANEL_TOKEN);
|
|
289
|
+
|
|
290
|
+
await mixpanel.track('Purchase', {
|
|
291
|
+
userId: 'user-123',
|
|
292
|
+
value: 99.99,
|
|
293
|
+
item: 'Premium Plan'
|
|
294
|
+
});
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Datadog
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
import { DataDogIntegration } from 'adaptive-memory-multi-model-router/integrations/datadog';
|
|
301
|
+
|
|
302
|
+
const datadog = new DataDogIntegration(
|
|
303
|
+
process.env.DD_API_KEY,
|
|
304
|
+
process.env.DD_APP_KEY
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
await datadog.postMetric('app.latency', 150);
|
|
308
|
+
const metrics = await datadog.getMetrics('app.latency');
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## DevOps
|
|
314
|
+
|
|
315
|
+
### GitHub
|
|
316
|
+
|
|
317
|
+
```javascript
|
|
318
|
+
import { GitHubIntegration } from 'adaptive-memory-multi-model-router/integrations/github';
|
|
319
|
+
|
|
320
|
+
const github = new GitHubIntegration(process.env.GITHUB_TOKEN);
|
|
321
|
+
|
|
322
|
+
const repo = await github.getRepo('owner', 'repo');
|
|
323
|
+
await github.createIssue('owner', 'repo', 'Bug', 'Description');
|
|
324
|
+
await github.createPR('owner', 'repo', 'Feature', 'feature-branch', 'main');
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### GitLab
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
import { GitLabIntegration } from 'adaptive-memory-multi-model-router/integrations/gitlab';
|
|
331
|
+
|
|
332
|
+
const gitlab = new GitLabIntegration(process.env.GITLAB_TOKEN);
|
|
333
|
+
|
|
334
|
+
const projects = await gitlab.getProjects();
|
|
335
|
+
await gitlab.createMR('project-id', 'feature-branch', 'main');
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Jenkins
|
|
339
|
+
|
|
340
|
+
```javascript
|
|
341
|
+
import { JenkinsIntegration } from 'adaptive-memory-multi-model-router/integrations/jenkins';
|
|
342
|
+
|
|
343
|
+
const jenkins = new JenkinsIntegration(
|
|
344
|
+
'https://jenkins.example.com',
|
|
345
|
+
'admin',
|
|
346
|
+
process.env.JENKINS_API_TOKEN
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const jobs = await jenkins.getJobs();
|
|
350
|
+
await jenkins.buildJob('my-job');
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Using OAuth Manager
|
|
356
|
+
|
|
357
|
+
```javascript
|
|
358
|
+
import { OAuthManager } from 'adaptive-memory-multi-model-router/oauth';
|
|
359
|
+
|
|
360
|
+
const oauth = new OAuthManager();
|
|
361
|
+
|
|
362
|
+
// Configure OAuth for Slack
|
|
363
|
+
oauth.configure('slack', {
|
|
364
|
+
clientId: process.env.SLACK_CLIENT_ID,
|
|
365
|
+
clientSecret: process.env.SLACK_CLIENT_SECRET,
|
|
366
|
+
redirectUri: 'https://myapp.com/callback/slack'
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Get authorization URL
|
|
370
|
+
const authUrl = oauth.getAuthUrl('slack');
|
|
371
|
+
|
|
372
|
+
// In your callback handler
|
|
373
|
+
const tokens = await oauth.handleCallback('slack', code, state);
|
|
374
|
+
|
|
375
|
+
// Make authenticated requests
|
|
376
|
+
oauth.apiRequest('slack', '/chat.postMessage', {
|
|
377
|
+
method: 'POST',
|
|
378
|
+
body: JSON.stringify({ channel: '#general', text: 'Hello!' })
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## Error Handling
|
|
385
|
+
|
|
386
|
+
```javascript
|
|
387
|
+
import { createIntegration } from 'adaptive-memory-multi-model-router/integrations';
|
|
388
|
+
|
|
389
|
+
const github = createIntegration('github', { apiKey: 'invalid' });
|
|
390
|
+
|
|
391
|
+
try {
|
|
392
|
+
await github.createIssue('owner', 'repo', 'Title', 'Body');
|
|
393
|
+
} catch (error) {
|
|
394
|
+
console.error('GitHub API Error:', error.message);
|
|
395
|
+
// Handle: retry, fallback, or alert
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## Integration Factory
|
|
402
|
+
|
|
403
|
+
Use `createIntegration` for quick setup:
|
|
404
|
+
|
|
405
|
+
```javascript
|
|
406
|
+
import { createIntegration } from 'adaptive-memory-multi-model-router/integrations';
|
|
407
|
+
|
|
408
|
+
// All integrations available via string name
|
|
409
|
+
const integration = createIntegration('stripe', { apiKey: 'sk_...' });
|
|
410
|
+
const integration2 = createIntegration('slack', { webhookUrl: 'https://...' });
|
|
411
|
+
const integration3 = createIntegration('pinecone', { apiKey: '...', environment: 'us-west-2' });
|
|
412
|
+
|
|
413
|
+
// Supported integration names:
|
|
414
|
+
// github, slack, telegram, notion, linear, jira, gmail, discord, airtable,
|
|
415
|
+
// google-calendar, asana, trello, stripe, shopify, intercom, sendgrid,
|
|
416
|
+
// mailchimp, hubspot, salesforce, zendesk, mixpanel, amplitude, segment,
|
|
417
|
+
// posthog, datadog, newrelic, sentry, grafana, pagerduty, aws-s3, gcs,
|
|
418
|
+
// azureblob, dropbox, jenkins, gitlab, bitbucket, vercel, netlify, pinecone,
|
|
419
|
+
// weaviate, qdrant, chromadb, and 70+ more!
|
|
420
|
+
```
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# A3M Router - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
## 5-Minute Setup
|
|
4
|
+
|
|
5
|
+
### Step 1: Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install adaptive-memory-multi-model-router
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Step 2: Basic Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
import { createA3MRouter } from 'adaptive-memory-multi-model-router';
|
|
15
|
+
|
|
16
|
+
const router = createA3MRouter({
|
|
17
|
+
memory: true,
|
|
18
|
+
costBudget: 0.05
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Route a request
|
|
22
|
+
const result = await router.route({
|
|
23
|
+
prompt: 'Explain quantum entanglement'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(result.output);
|
|
27
|
+
console.log('Provider:', result.provider);
|
|
28
|
+
console.log('Cost:', result.cost);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Step 3: Add Integrations
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import { createIntegration } from 'adaptive-memory-multi-model-router/integrations';
|
|
35
|
+
|
|
36
|
+
// GitHub
|
|
37
|
+
const github = createIntegration('github', { apiKey: process.env.GITHUB_TOKEN });
|
|
38
|
+
await github.createIssue('owner', 'repo', 'Bug', 'Fix this');
|
|
39
|
+
|
|
40
|
+
// Slack
|
|
41
|
+
const slack = createIntegration('slack', { webhookUrl: process.env.SLACK_WEBHOOK });
|
|
42
|
+
await slack.sendMessage('#team', 'Build complete!');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Examples
|
|
48
|
+
|
|
49
|
+
### Example 1: Smart Routing with Memory
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
import { createA3MRouter } from 'adaptive-memory-multi-model-router';
|
|
53
|
+
|
|
54
|
+
const router = createA3MRouter({
|
|
55
|
+
memory: true, // Enable memory tree
|
|
56
|
+
costBudget: 0.05, // Max $0.05 per request
|
|
57
|
+
providers: ['openai', 'groq', 'anthropic', 'cerebras']
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
async function handleUserQuery(query) {
|
|
61
|
+
// Route with context from memory
|
|
62
|
+
const result = await router.route({
|
|
63
|
+
prompt: query,
|
|
64
|
+
context: {
|
|
65
|
+
type: detectIntent(query),
|
|
66
|
+
history: memory.getContext(2000)
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Learn from this interaction
|
|
71
|
+
memory.add({ query, response: result.output, provider: result.provider });
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Example 2: Batch Processing
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
import { batchProcess } from 'adaptive-memory-multi-model-router';
|
|
81
|
+
|
|
82
|
+
const tasks = [
|
|
83
|
+
'Analyze this data',
|
|
84
|
+
'Write unit tests',
|
|
85
|
+
'Document API',
|
|
86
|
+
'Review PR',
|
|
87
|
+
'Write release notes'
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
const results = await batchProcess(tasks, {
|
|
91
|
+
maxParallel: 3,
|
|
92
|
+
provider: 'openai'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
results.forEach((result, i) => {
|
|
96
|
+
console.log(`Task ${i+1}: ${result.output.slice(0, 50)}...`);
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Example 3: Cost-Optimized Routing
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import { createA3MRouter } from 'adaptive-memory-multi-model-router';
|
|
104
|
+
|
|
105
|
+
const router = createA3MRouter({
|
|
106
|
+
costBudget: 0.02, // Very low budget
|
|
107
|
+
providers: ['groq', 'cerebras'] // Fast + free tier
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Simple queries go to fast free providers
|
|
111
|
+
// Complex queries route to best available
|
|
112
|
+
|
|
113
|
+
const queries = [
|
|
114
|
+
'What is 2+2?', // → Groq (fast, free)
|
|
115
|
+
'Explain black holes', // → Cerebras (free tier)
|
|
116
|
+
'Debug my 10k line program' // → Cerebras (best available)
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
for (const query of queries) {
|
|
120
|
+
const result = await router.route({ prompt: query });
|
|
121
|
+
console.log(`${query.slice(0, 30)}... → ${result.provider} ($${result.cost.toFixed(4)})`);
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Example 4: Auto-Fetch for Context
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
import { AutoFetch } from 'adaptive-memory-multi-model-router/autofetch';
|
|
129
|
+
import { MemoryTree } from 'adaptive-memory-multi-model-router/memory';
|
|
130
|
+
|
|
131
|
+
const fetcher = new AutoFetch({
|
|
132
|
+
intervalMs: 20 * 60 * 1000, // 20 minutes
|
|
133
|
+
targets: ['github', 'notion', 'slack']
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const memory = new MemoryTree();
|
|
137
|
+
|
|
138
|
+
fetcher.start();
|
|
139
|
+
|
|
140
|
+
// On each sync, memory automatically updated
|
|
141
|
+
fetcher.on('sync', (target, data) => {
|
|
142
|
+
memory.add(data);
|
|
143
|
+
console.log(`${target} synced, memory now has ${memory.getStats().totalChunks} chunks`);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Now routing has fresh context
|
|
147
|
+
const result = await router.route({
|
|
148
|
+
prompt: userQuery,
|
|
149
|
+
context: { context: memory.getContext(3000) }
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Example 5: Compression for Large Contexts
|
|
154
|
+
|
|
155
|
+
```javascript
|
|
156
|
+
import { EnhancedCompression } from 'adaptive-memory-multi-model-router/compression';
|
|
157
|
+
|
|
158
|
+
const compressor = new EnhancedCompression();
|
|
159
|
+
|
|
160
|
+
// Compress HTML content
|
|
161
|
+
const htmlContent = `
|
|
162
|
+
<html><body>
|
|
163
|
+
<h1>Document Title</h1>
|
|
164
|
+
<p>This is a very long paragraph with a very long URL:
|
|
165
|
+
https://example.com/very/very/very/very/very/long/path/that/should/be/shortened</p>
|
|
166
|
+
</body></html>
|
|
167
|
+
`;
|
|
168
|
+
|
|
169
|
+
const compressed = compressor.compress(htmlContent);
|
|
170
|
+
// Output: '# Document Title\n\nThis is a very long paragraph with a URL: example.com/...'
|
|
171
|
+
|
|
172
|
+
console.log('Reduced from', htmlContent.length, 'to', compressed.length, 'chars');
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Example 6: Obsidian Vault for Audit Trail
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
import { ObsidianVault } from 'adaptive-memory-multi-model-router/vault';
|
|
179
|
+
import { createA3MRouter } from 'adaptive-memory-multi-model-router';
|
|
180
|
+
|
|
181
|
+
const vault = new ObsidianVault({ path: './my-vault' });
|
|
182
|
+
const router = createA3MRouter();
|
|
183
|
+
|
|
184
|
+
router.on('route', async (request, result) => {
|
|
185
|
+
// Save every routing decision
|
|
186
|
+
await vault.saveDecision({
|
|
187
|
+
id: generateId(),
|
|
188
|
+
timestamp: Date.now(),
|
|
189
|
+
prompt: request.prompt,
|
|
190
|
+
selectedProvider: result.provider,
|
|
191
|
+
selectedModel: result.model,
|
|
192
|
+
reasoning: result.reasoning,
|
|
193
|
+
cost: result.cost,
|
|
194
|
+
latency: result.latency
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Later, review routing decisions in Obsidian
|
|
199
|
+
const recent = vault.getRecentDecisions(50);
|
|
200
|
+
// Open ./my-vault/routing-index.md in Obsidian to browse
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## CLI Quick Reference
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Route a query
|
|
209
|
+
a3m-router route "Explain quantum computing"
|
|
210
|
+
|
|
211
|
+
# Parallel execution
|
|
212
|
+
a3m-router parallel "task1" "task2" "task3"
|
|
213
|
+
|
|
214
|
+
# Compare models
|
|
215
|
+
a3m-router compare "Write a haiku"
|
|
216
|
+
|
|
217
|
+
# Cost summary
|
|
218
|
+
a3m-router cost
|
|
219
|
+
|
|
220
|
+
# Token counting
|
|
221
|
+
a3m-router count "Your text here"
|
|
222
|
+
|
|
223
|
+
# Compress text
|
|
224
|
+
a3m-router compress "<html>content</html>"
|
|
225
|
+
|
|
226
|
+
# Local Ollama
|
|
227
|
+
a3m-router local "Write Python hello world"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Environment Variables
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# LLM Providers
|
|
236
|
+
OPENAI_API_KEY=sk-...
|
|
237
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
238
|
+
GROQ_API_KEY=gsk_...
|
|
239
|
+
CEREBRAS_API_KEY=...
|
|
240
|
+
|
|
241
|
+
# Integrations
|
|
242
|
+
GITHUB_TOKEN=ghp_...
|
|
243
|
+
SLACK_WEBHOOK=https://hooks.slack.com/...
|
|
244
|
+
PINECONE_API_KEY=...
|
|
245
|
+
STRIPE_API_KEY=sk_...
|
|
246
|
+
|
|
247
|
+
# Optional
|
|
248
|
+
LOG_LEVEL=info
|
|
249
|
+
CACHE_TTL=3600
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Next Steps
|
|
255
|
+
|
|
256
|
+
1. **Read the full [API Documentation](API.md)**
|
|
257
|
+
2. **Explore [116 Integrations](INTEGRATIONS.md)**
|
|
258
|
+
3. **Deploy to production** with proper monitoring
|
|
259
|
+
4. **Join the community** for support
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Performance Tips
|
|
264
|
+
|
|
265
|
+
| Tip | Impact |
|
|
266
|
+
|-----|--------|
|
|
267
|
+
| Use memory tree | 10x faster routing |
|
|
268
|
+
| Enable compression | 2-5x less tokens |
|
|
269
|
+
| Use batch processing | 3x throughput |
|
|
270
|
+
| Configure cost budgets | 40% cost savings |
|
|
271
|
+
| Use provider caching | 5x fewer API calls |
|