@framers/agentos 0.2.5 → 0.2.7
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/dist/memory-router/MemoryRouter.d.ts +195 -0
- package/dist/memory-router/MemoryRouter.d.ts.map +1 -0
- package/dist/memory-router/MemoryRouter.js +155 -0
- package/dist/memory-router/MemoryRouter.js.map +1 -0
- package/dist/memory-router/backend-costs.d.ts +67 -0
- package/dist/memory-router/backend-costs.d.ts.map +1 -0
- package/dist/memory-router/backend-costs.js +136 -0
- package/dist/memory-router/backend-costs.js.map +1 -0
- package/dist/memory-router/classifier.d.ts +169 -0
- package/dist/memory-router/classifier.d.ts.map +1 -0
- package/dist/memory-router/classifier.js +193 -0
- package/dist/memory-router/classifier.js.map +1 -0
- package/dist/memory-router/dispatcher.d.ts +115 -0
- package/dist/memory-router/dispatcher.d.ts.map +1 -0
- package/dist/memory-router/dispatcher.js +84 -0
- package/dist/memory-router/dispatcher.js.map +1 -0
- package/dist/memory-router/index.d.ts +124 -0
- package/dist/memory-router/index.d.ts.map +1 -0
- package/dist/memory-router/index.js +121 -0
- package/dist/memory-router/index.js.map +1 -0
- package/dist/memory-router/routing-tables.d.ts +125 -0
- package/dist/memory-router/routing-tables.d.ts.map +1 -0
- package/dist/memory-router/routing-tables.js +137 -0
- package/dist/memory-router/routing-tables.js.map +1 -0
- package/dist/memory-router/select-backend.d.ts +136 -0
- package/dist/memory-router/select-backend.d.ts.map +1 -0
- package/dist/memory-router/select-backend.js +210 -0
- package/dist/memory-router/select-backend.js.map +1 -0
- package/dist/sandbox/executor/CodeSandbox.d.ts.map +1 -1
- package/dist/sandbox/executor/CodeSandbox.js +24 -0
- package/dist/sandbox/executor/CodeSandbox.js.map +1 -1
- package/dist/sandbox/executor/ICodeSandbox.d.ts +7 -3
- package/dist/sandbox/executor/ICodeSandbox.d.ts.map +1 -1
- package/dist/sandbox/executor/ICodeSandbox.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file MemoryRouter.ts
|
|
3
|
+
* @description Top-level orchestrator that composes the LLM-as-judge
|
|
4
|
+
* classifier and the pure `selectBackend` decision function into a single
|
|
5
|
+
* per-query routing call.
|
|
6
|
+
*
|
|
7
|
+
* MemoryRouter is deliberately a THIN composition layer. It:
|
|
8
|
+
* 1. Runs the classifier on the incoming query → category + token counts.
|
|
9
|
+
* 2. Resolves the routing table from (preset | custom table | custom mapping).
|
|
10
|
+
* 3. Calls the pure selectBackend to get the routing decision.
|
|
11
|
+
* 4. Returns a {@link MemoryRouterDecision} bundling both.
|
|
12
|
+
*
|
|
13
|
+
* It does NOT execute the recall — backend execution is the job of
|
|
14
|
+
* {@link IMemoryDispatcher}. This split keeps the router pure-enough to
|
|
15
|
+
* be used in both "decide only" flows (benchmarks, dashboards, dry-runs)
|
|
16
|
+
* and "decide + execute" flows (production queries).
|
|
17
|
+
*
|
|
18
|
+
* @module @framers/agentos/memory-router/MemoryRouter
|
|
19
|
+
*/
|
|
20
|
+
import type { IMemoryClassifier, MemoryClassifierResult } from './classifier.js';
|
|
21
|
+
import { type MemoryBackendCostPoint } from './backend-costs.js';
|
|
22
|
+
import { type MemoryBackendId, type MemoryQueryCategory, type MemoryRouterPreset, type RoutingTable } from './routing-tables.js';
|
|
23
|
+
import { type MemoryBudgetMode, type MemoryRoutingDecision } from './select-backend.js';
|
|
24
|
+
import type { IMemoryDispatcher } from './dispatcher.js';
|
|
25
|
+
/**
|
|
26
|
+
* Per-query USD budget policy. Combined into a single nested object so
|
|
27
|
+
* consumers can enable budget enforcement without flat-argument sprawl.
|
|
28
|
+
*/
|
|
29
|
+
export interface MemoryBudgetPolicy {
|
|
30
|
+
/**
|
|
31
|
+
* Budget ceiling per query in USD. When omitted, routing passes
|
|
32
|
+
* through the table's pick regardless of cost.
|
|
33
|
+
*/
|
|
34
|
+
readonly perQueryUsd?: number;
|
|
35
|
+
/**
|
|
36
|
+
* How to handle budget overrun. Default `cheapest-fallback` for
|
|
37
|
+
* production safety (silently downgrades rather than throwing).
|
|
38
|
+
* See {@link MemoryBudgetMode}.
|
|
39
|
+
*/
|
|
40
|
+
readonly mode?: MemoryBudgetMode;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Constructor options for {@link MemoryRouter}.
|
|
44
|
+
*/
|
|
45
|
+
export interface MemoryRouterOptions {
|
|
46
|
+
/** LLM-as-judge classifier. Usually {@link LLMMemoryClassifier}. */
|
|
47
|
+
readonly classifier: IMemoryClassifier;
|
|
48
|
+
/**
|
|
49
|
+
* Shipping preset to use. Defaults to `minimize-cost` — the same
|
|
50
|
+
* Pareto-best-for-cost preset we use on LongMemEval-S Phase B.
|
|
51
|
+
*/
|
|
52
|
+
readonly preset?: MemoryRouterPreset;
|
|
53
|
+
/**
|
|
54
|
+
* Optional custom routing table override. When provided, replaces the
|
|
55
|
+
* preset's default table. The `preset` field is still used for
|
|
56
|
+
* telemetry labeling and must match.
|
|
57
|
+
*/
|
|
58
|
+
readonly routingTable?: RoutingTable;
|
|
59
|
+
/**
|
|
60
|
+
* Optional per-category routing override that patches the resolved
|
|
61
|
+
* routing table. Useful when a workload needs to change a single
|
|
62
|
+
* category's dispatch without rewriting the whole table.
|
|
63
|
+
*/
|
|
64
|
+
readonly mapping?: Partial<Record<MemoryQueryCategory, MemoryBackendId>>;
|
|
65
|
+
/**
|
|
66
|
+
* Optional budget policy. When omitted, no budget is enforced.
|
|
67
|
+
*/
|
|
68
|
+
readonly budget?: MemoryBudgetPolicy;
|
|
69
|
+
/**
|
|
70
|
+
* Optional custom backend cost-points (for workloads whose cost /
|
|
71
|
+
* accuracy profile diverges from LongMemEval-S Phase B). When omitted,
|
|
72
|
+
* uses {@link DEFAULT_MEMORY_BACKEND_COSTS}.
|
|
73
|
+
*/
|
|
74
|
+
readonly backendCosts?: Readonly<Record<MemoryBackendId, MemoryBackendCostPoint>>;
|
|
75
|
+
/**
|
|
76
|
+
* Default for {@link MemoryClassifierClassifyOptions.useFewShotPrompt}
|
|
77
|
+
* on every `decide()` call. Callers can still override per-call.
|
|
78
|
+
*/
|
|
79
|
+
readonly useFewShotPrompt?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Optional dispatcher. When supplied, {@link MemoryRouter.decideAndDispatch}
|
|
82
|
+
* is usable; otherwise callers must use {@link MemoryRouter.decide} and
|
|
83
|
+
* execute the chosen backend themselves.
|
|
84
|
+
*/
|
|
85
|
+
readonly dispatcher?: IMemoryDispatcher<unknown, unknown>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Per-call options for {@link MemoryRouter.decide}.
|
|
89
|
+
*/
|
|
90
|
+
export interface MemoryRouterDecideOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Ground-truth category, passed through to the routing decision for
|
|
93
|
+
* telemetry. Not used in production. Benchmark adapters pass this when
|
|
94
|
+
* the gold label is available so downstream analysis can distinguish
|
|
95
|
+
* classifier misroutes from architectural misses.
|
|
96
|
+
*/
|
|
97
|
+
readonly groundTruthCategory?: MemoryQueryCategory | null;
|
|
98
|
+
/**
|
|
99
|
+
* Per-call override of the few-shot prompt variant. When omitted,
|
|
100
|
+
* inherits the router's constructor-scoped default.
|
|
101
|
+
*/
|
|
102
|
+
readonly useFewShotPrompt?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Bundled result of a `decide()` call. Carries the classifier result
|
|
106
|
+
* (for cost tracking + debugging) alongside the routing decision.
|
|
107
|
+
*/
|
|
108
|
+
export interface MemoryRouterDecision {
|
|
109
|
+
readonly classifier: MemoryClassifierResult;
|
|
110
|
+
readonly routing: MemoryRoutingDecision;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Bundled result of a `decideAndDispatch()` call. Combines the full
|
|
114
|
+
* {@link MemoryRouterDecision} with the dispatched traces so telemetry
|
|
115
|
+
* and answer-generation can consume both in one step.
|
|
116
|
+
*/
|
|
117
|
+
export interface MemoryRouterDispatchedDecision<TTrace> {
|
|
118
|
+
readonly decision: MemoryRouterDecision;
|
|
119
|
+
readonly traces: TTrace[];
|
|
120
|
+
readonly backend: MemoryBackendId;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Thrown when `decideAndDispatch` is called on a router that was
|
|
124
|
+
* constructed without a dispatcher.
|
|
125
|
+
*/
|
|
126
|
+
export declare class MemoryRouterDispatcherMissingError extends Error {
|
|
127
|
+
constructor();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The public MemoryRouter primitive. One instance per memory-recall
|
|
131
|
+
* endpoint; construct once at app startup with the chosen preset and
|
|
132
|
+
* reuse across queries.
|
|
133
|
+
*
|
|
134
|
+
* @example Basic min-cost routing
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { LLMMemoryClassifier, MemoryRouter } from '../memory-router';
|
|
137
|
+
*
|
|
138
|
+
* const router = new MemoryRouter({
|
|
139
|
+
* classifier: new LLMMemoryClassifier({ llm: myOpenAIAdapter }),
|
|
140
|
+
* preset: 'minimize-cost',
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* const decision = await router.decide("What's my current job title?");
|
|
144
|
+
* console.log(decision.classifier.category); // 'knowledge-update'
|
|
145
|
+
* console.log(decision.routing.chosenBackend); // 'canonical-hybrid'
|
|
146
|
+
* console.log(decision.routing.estimatedCostUsd); // 0.0189
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @example With a strict budget
|
|
150
|
+
* ```ts
|
|
151
|
+
* const router = new MemoryRouter({
|
|
152
|
+
* classifier: myClassifier,
|
|
153
|
+
* preset: 'maximize-accuracy',
|
|
154
|
+
* budget: { perQueryUsd: 0.025, mode: 'cheapest-fallback' },
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare class MemoryRouter {
|
|
159
|
+
private readonly classifier;
|
|
160
|
+
private readonly preset;
|
|
161
|
+
private readonly routingTable;
|
|
162
|
+
private readonly budgetPerQuery;
|
|
163
|
+
private readonly budgetMode;
|
|
164
|
+
private readonly backendCosts;
|
|
165
|
+
private readonly defaultUseFewShotPrompt;
|
|
166
|
+
private readonly dispatcher;
|
|
167
|
+
constructor(options: MemoryRouterOptions);
|
|
168
|
+
/**
|
|
169
|
+
* Decide-only routing. Classifies the query, picks a backend, returns
|
|
170
|
+
* both pieces. Does NOT execute the recall — pair with an
|
|
171
|
+
* {@link IMemoryDispatcher} for the end-to-end flow, or call
|
|
172
|
+
* {@link MemoryRouter.decideAndDispatch} if a dispatcher is wired.
|
|
173
|
+
*
|
|
174
|
+
* @param query - The user's memory-recall query text.
|
|
175
|
+
* @param options - Per-call overrides (ground-truth telemetry, prompt variant).
|
|
176
|
+
* @returns A {@link MemoryRouterDecision} bundling classifier + routing results.
|
|
177
|
+
*/
|
|
178
|
+
decide(query: string, options?: MemoryRouterDecideOptions): Promise<MemoryRouterDecision>;
|
|
179
|
+
/**
|
|
180
|
+
* Decide + dispatch in one call. Requires the router to have been
|
|
181
|
+
* constructed with a {@link IMemoryDispatcher}.
|
|
182
|
+
*
|
|
183
|
+
* @typeParam TTrace - Caller's trace shape (passed through verbatim).
|
|
184
|
+
* @typeParam TPayload - Caller's payload shape for the dispatcher.
|
|
185
|
+
* @param query - User memory-recall query.
|
|
186
|
+
* @param dispatchPayload - Optional payload forwarded to the dispatcher's
|
|
187
|
+
* per-backend executor (e.g. topK, retrieval policy).
|
|
188
|
+
* @param options - Per-call overrides (ground-truth telemetry, prompt variant).
|
|
189
|
+
*
|
|
190
|
+
* @throws {@link MemoryRouterDispatcherMissingError} when no dispatcher
|
|
191
|
+
* was supplied at construction.
|
|
192
|
+
*/
|
|
193
|
+
decideAndDispatch<TTrace, TPayload = undefined>(query: string, dispatchPayload?: TPayload, options?: MemoryRouterDecideOptions): Promise<MemoryRouterDispatchedDecision<TTrace>>;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=MemoryRouter.d.ts.map
|
|
@@ -0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M,CACV,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,oBAAoB,CAAC;IAuBhC;;;;;;;;;;;;;OAaG;IACG,iBAAiB,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAClD,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,QAAQ,EAC1B,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;CAkBnD"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file MemoryRouter.ts
|
|
3
|
+
* @description Top-level orchestrator that composes the LLM-as-judge
|
|
4
|
+
* classifier and the pure `selectBackend` decision function into a single
|
|
5
|
+
* per-query routing call.
|
|
6
|
+
*
|
|
7
|
+
* MemoryRouter is deliberately a THIN composition layer. It:
|
|
8
|
+
* 1. Runs the classifier on the incoming query → category + token counts.
|
|
9
|
+
* 2. Resolves the routing table from (preset | custom table | custom mapping).
|
|
10
|
+
* 3. Calls the pure selectBackend to get the routing decision.
|
|
11
|
+
* 4. Returns a {@link MemoryRouterDecision} bundling both.
|
|
12
|
+
*
|
|
13
|
+
* It does NOT execute the recall — backend execution is the job of
|
|
14
|
+
* {@link IMemoryDispatcher}. This split keeps the router pure-enough to
|
|
15
|
+
* be used in both "decide only" flows (benchmarks, dashboards, dry-runs)
|
|
16
|
+
* and "decide + execute" flows (production queries).
|
|
17
|
+
*
|
|
18
|
+
* @module @framers/agentos/memory-router/MemoryRouter
|
|
19
|
+
*/
|
|
20
|
+
import { DEFAULT_MEMORY_BACKEND_COSTS, } from './backend-costs.js';
|
|
21
|
+
import { PRESET_TABLES, } from './routing-tables.js';
|
|
22
|
+
import { selectBackend, } from './select-backend.js';
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when `decideAndDispatch` is called on a router that was
|
|
25
|
+
* constructed without a dispatcher.
|
|
26
|
+
*/
|
|
27
|
+
export class MemoryRouterDispatcherMissingError extends Error {
|
|
28
|
+
constructor() {
|
|
29
|
+
super('MemoryRouter.decideAndDispatch requires a dispatcher. ' +
|
|
30
|
+
'Either pass a dispatcher in options, or call `decide` and dispatch yourself.');
|
|
31
|
+
this.name = 'MemoryRouterDispatcherMissingError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Class
|
|
36
|
+
// ============================================================================
|
|
37
|
+
/**
|
|
38
|
+
* The public MemoryRouter primitive. One instance per memory-recall
|
|
39
|
+
* endpoint; construct once at app startup with the chosen preset and
|
|
40
|
+
* reuse across queries.
|
|
41
|
+
*
|
|
42
|
+
* @example Basic min-cost routing
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { LLMMemoryClassifier, MemoryRouter } from '../memory-router/index.js';
|
|
45
|
+
*
|
|
46
|
+
* const router = new MemoryRouter({
|
|
47
|
+
* classifier: new LLMMemoryClassifier({ llm: myOpenAIAdapter }),
|
|
48
|
+
* preset: 'minimize-cost',
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const decision = await router.decide("What's my current job title?");
|
|
52
|
+
* console.log(decision.classifier.category); // 'knowledge-update'
|
|
53
|
+
* console.log(decision.routing.chosenBackend); // 'canonical-hybrid'
|
|
54
|
+
* console.log(decision.routing.estimatedCostUsd); // 0.0189
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example With a strict budget
|
|
58
|
+
* ```ts
|
|
59
|
+
* const router = new MemoryRouter({
|
|
60
|
+
* classifier: myClassifier,
|
|
61
|
+
* preset: 'maximize-accuracy',
|
|
62
|
+
* budget: { perQueryUsd: 0.025, mode: 'cheapest-fallback' },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export class MemoryRouter {
|
|
67
|
+
constructor(options) {
|
|
68
|
+
this.classifier = options.classifier;
|
|
69
|
+
this.preset = options.preset ?? 'minimize-cost';
|
|
70
|
+
this.dispatcher = options.dispatcher ?? null;
|
|
71
|
+
// Resolve routing table: explicit > preset's default.
|
|
72
|
+
const baseTable = options.routingTable ?? PRESET_TABLES[this.preset];
|
|
73
|
+
// Apply optional per-category mapping override.
|
|
74
|
+
if (options.mapping) {
|
|
75
|
+
const patched = {
|
|
76
|
+
...baseTable.defaultMapping,
|
|
77
|
+
};
|
|
78
|
+
for (const key of Object.keys(options.mapping)) {
|
|
79
|
+
const override = options.mapping[key];
|
|
80
|
+
if (override)
|
|
81
|
+
patched[key] = override;
|
|
82
|
+
}
|
|
83
|
+
this.routingTable = Object.freeze({
|
|
84
|
+
preset: baseTable.preset,
|
|
85
|
+
defaultMapping: Object.freeze(patched),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.routingTable = baseTable;
|
|
90
|
+
}
|
|
91
|
+
this.budgetPerQuery = options.budget?.perQueryUsd ?? null;
|
|
92
|
+
this.budgetMode = options.budget?.mode ?? 'cheapest-fallback';
|
|
93
|
+
this.backendCosts = options.backendCosts ?? DEFAULT_MEMORY_BACKEND_COSTS;
|
|
94
|
+
this.defaultUseFewShotPrompt = options.useFewShotPrompt ?? false;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Decide-only routing. Classifies the query, picks a backend, returns
|
|
98
|
+
* both pieces. Does NOT execute the recall — pair with an
|
|
99
|
+
* {@link IMemoryDispatcher} for the end-to-end flow, or call
|
|
100
|
+
* {@link MemoryRouter.decideAndDispatch} if a dispatcher is wired.
|
|
101
|
+
*
|
|
102
|
+
* @param query - The user's memory-recall query text.
|
|
103
|
+
* @param options - Per-call overrides (ground-truth telemetry, prompt variant).
|
|
104
|
+
* @returns A {@link MemoryRouterDecision} bundling classifier + routing results.
|
|
105
|
+
*/
|
|
106
|
+
async decide(query, options) {
|
|
107
|
+
const useFewShot = options?.useFewShotPrompt ?? this.defaultUseFewShotPrompt;
|
|
108
|
+
const classifierOptions = useFewShot
|
|
109
|
+
? { useFewShotPrompt: true }
|
|
110
|
+
: undefined;
|
|
111
|
+
const classifier = await this.classifier.classify(query, classifierOptions);
|
|
112
|
+
const routing = selectBackend({
|
|
113
|
+
predictedCategory: classifier.category,
|
|
114
|
+
groundTruthCategory: options?.groundTruthCategory ?? null,
|
|
115
|
+
config: {
|
|
116
|
+
table: this.routingTable,
|
|
117
|
+
budgetPerQuery: this.budgetPerQuery,
|
|
118
|
+
budgetMode: this.budgetMode,
|
|
119
|
+
backendCosts: this.backendCosts,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
return { classifier, routing };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Decide + dispatch in one call. Requires the router to have been
|
|
126
|
+
* constructed with a {@link IMemoryDispatcher}.
|
|
127
|
+
*
|
|
128
|
+
* @typeParam TTrace - Caller's trace shape (passed through verbatim).
|
|
129
|
+
* @typeParam TPayload - Caller's payload shape for the dispatcher.
|
|
130
|
+
* @param query - User memory-recall query.
|
|
131
|
+
* @param dispatchPayload - Optional payload forwarded to the dispatcher's
|
|
132
|
+
* per-backend executor (e.g. topK, retrieval policy).
|
|
133
|
+
* @param options - Per-call overrides (ground-truth telemetry, prompt variant).
|
|
134
|
+
*
|
|
135
|
+
* @throws {@link MemoryRouterDispatcherMissingError} when no dispatcher
|
|
136
|
+
* was supplied at construction.
|
|
137
|
+
*/
|
|
138
|
+
async decideAndDispatch(query, dispatchPayload, options) {
|
|
139
|
+
if (!this.dispatcher) {
|
|
140
|
+
throw new MemoryRouterDispatcherMissingError();
|
|
141
|
+
}
|
|
142
|
+
const decision = await this.decide(query, options);
|
|
143
|
+
const dispatched = (await this.dispatcher.dispatch({
|
|
144
|
+
backend: decision.routing.chosenBackend,
|
|
145
|
+
query,
|
|
146
|
+
payload: dispatchPayload,
|
|
147
|
+
}));
|
|
148
|
+
return {
|
|
149
|
+
decision,
|
|
150
|
+
traces: dispatched.traces,
|
|
151
|
+
backend: dispatched.backend,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=MemoryRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryRouter.js","sourceRoot":"","sources":["../../src/memory-router/MemoryRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EACL,4BAA4B,GAE7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,GAKd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,aAAa,GAGd,MAAM,qBAAqB,CAAC;AAkH7B;;;GAGG;AACH,MAAM,OAAO,kCAAmC,SAAQ,KAAK;IAC3D;QACE,KAAK,CACH,wDAAwD;YACtD,8EAA8E,CACjF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IACnD,CAAC;CACF;AAED,+EAA+E;AAC/E,QAAQ;AACR,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,YAAY;IAYvB,YAAY,OAA4B;QACtC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;QAE7C,sDAAsD;QACtD,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAErE,gDAAgD;QAChD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,OAAO,GAAiD;gBAC5D,GAAG,SAAS,CAAC,cAAc;aAC5B,CAAC;YACF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAA0B,EAAE,CAAC;gBACxE,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;g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IAAI,CAAC,UAAU;gBAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;aAChC;SACF,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,iBAAiB,CACrB,KAAa,EACb,eAA0B,EAC1B,OAAmC;QAEnC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,kCAAkC,EAAE,CAAC;QACjD,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnD,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjD,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,aAAa;YACvC,KAAK;YACL,OAAO,EAAE,eAA0B;SACpC,CAAC,CAAiC,CAAC;QAEpC,OAAO;YACL,QAAQ;YACR,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,OAAO,EAAE,UAAU,CAAC,OAAO;SAC5B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file backend-costs.ts
|
|
3
|
+
* @description Per-backend per-category cost-accuracy-latency points
|
|
4
|
+
* measured on LongMemEval-S Phase B (N=500). The {@link MemoryRouter} uses
|
|
5
|
+
* these to:
|
|
6
|
+
* - estimate the per-query USD cost of a routing decision before executing,
|
|
7
|
+
* - apply budget constraints (`hard` / `soft` / `cheapest-fallback`),
|
|
8
|
+
* - pick the cheapest backend that fits a budget when downgrading.
|
|
9
|
+
*
|
|
10
|
+
* Numbers come from the canonical Phase B run JSONs:
|
|
11
|
+
* - canonical-hybrid: results/runs/2026-04-20T20-03-14-675 (Tier 1)
|
|
12
|
+
* - observational-memory-v10: results/runs/2026-04-23T04-14-40-609 (Tier 2a v10)
|
|
13
|
+
* - observational-memory-v11: results/runs/2026-04-23T17-27-28-793 (Tier 2b v11)
|
|
14
|
+
*
|
|
15
|
+
* The per-tier `avgCostPerQuery` is the totalUsd-divided-by-n_cases
|
|
16
|
+
* average; on routed configurations the actual per-call cost depends on
|
|
17
|
+
* which backend the dispatcher picked and which category the call hit, so
|
|
18
|
+
* the per-category breakdown below is what the router actually consumes.
|
|
19
|
+
*
|
|
20
|
+
* @module @framers/agentos/memory-router/backend-costs
|
|
21
|
+
*/
|
|
22
|
+
import type { MemoryBackendId, MemoryQueryCategory } from './routing-tables.js';
|
|
23
|
+
/**
|
|
24
|
+
* Cost-accuracy-latency point for one backend across the six categories.
|
|
25
|
+
* The router compares these to make budget-aware decisions.
|
|
26
|
+
*/
|
|
27
|
+
export interface MemoryBackendCostPoint {
|
|
28
|
+
readonly backend: MemoryBackendId;
|
|
29
|
+
/** Average USD per query across all categories (Phase B aggregate). */
|
|
30
|
+
readonly avgCostPerQuery: number;
|
|
31
|
+
/** Per-category accuracy at this backend (Phase B N=500). */
|
|
32
|
+
readonly perCategoryAccuracy: Readonly<Record<MemoryQueryCategory, number>>;
|
|
33
|
+
/** Per-category USD per query at this backend (Phase B N=500). */
|
|
34
|
+
readonly perCategoryCostPerQuery: Readonly<Record<MemoryQueryCategory, number>>;
|
|
35
|
+
/** Per-category average latency in ms at this backend (Phase B N=500). */
|
|
36
|
+
readonly perCategoryLatencyMs: Readonly<Record<MemoryQueryCategory, number>>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* canonical-hybrid: BM25 + dense + RRF + Cohere rerank-v3.5 over raw
|
|
40
|
+
* memory traces. Phase B measured 73.2% [69.2, 77.0] aggregate at
|
|
41
|
+
* $0.0213/correct.
|
|
42
|
+
*/
|
|
43
|
+
export declare const TIER_1_CANONICAL_COSTS: MemoryBackendCostPoint;
|
|
44
|
+
/**
|
|
45
|
+
* observational-memory-v10: synthesized observation log + classifier-driven
|
|
46
|
+
* dispatch inside the OM pipeline (no verbatim citation). Phase B measured
|
|
47
|
+
* 74.6% [70.8, 78.4] aggregate at $0.3265/correct, 12s avg latency.
|
|
48
|
+
*/
|
|
49
|
+
export declare const TIER_2A_V10_COSTS: MemoryBackendCostPoint;
|
|
50
|
+
/**
|
|
51
|
+
* observational-memory-v11: v10 + conditional verbatim citation rule for
|
|
52
|
+
* knowledge-update and single-session-user categories. Phase B measured
|
|
53
|
+
* 75.4% [71.6, 79.0] aggregate at $0.4362/correct, 14s avg latency.
|
|
54
|
+
*/
|
|
55
|
+
export declare const TIER_2B_V11_COSTS: MemoryBackendCostPoint;
|
|
56
|
+
/**
|
|
57
|
+
* Default cost-points registry. Indexed by {@link MemoryBackendId} so the
|
|
58
|
+
* router can look up the picked backend's cost on any category.
|
|
59
|
+
*
|
|
60
|
+
* Custom deployments can substitute their own cost-points by passing a
|
|
61
|
+
* different `backendCosts` map into the {@link MemoryRouter} config —
|
|
62
|
+
* useful when a workload diverges from the LongMemEval-S Phase B
|
|
63
|
+
* distribution and the calibrator wants to plug in measurements from
|
|
64
|
+
* their own benchmark.
|
|
65
|
+
*/
|
|
66
|
+
export declare const DEFAULT_MEMORY_BACKEND_COSTS: Readonly<Record<MemoryBackendId, MemoryBackendCostPoint>>;
|
|
67
|
+
//# sourceMappingURL=backend-costs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-costs.d.ts","sourceRoot":"","sources":["../../src/memory-router/backend-costs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEhF;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,uEAAuE;IACvE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,6DAA6D;IAC7D,QAAQ,CAAC,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5E,kEAAkE;IAClE,QAAQ,CAAC,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC,CAAC;IAChF,0EAA0E;IAC1E,QAAQ,CAAC,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC,CAAC;CAC9E;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBA2BT,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,sBA2BJ,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,sBA2BJ,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CACjD,MAAM,CAAC,eAAe,EAAE,sBAAsB,CAAC,CAK/C,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file backend-costs.ts
|
|
3
|
+
* @description Per-backend per-category cost-accuracy-latency points
|
|
4
|
+
* measured on LongMemEval-S Phase B (N=500). The {@link MemoryRouter} uses
|
|
5
|
+
* these to:
|
|
6
|
+
* - estimate the per-query USD cost of a routing decision before executing,
|
|
7
|
+
* - apply budget constraints (`hard` / `soft` / `cheapest-fallback`),
|
|
8
|
+
* - pick the cheapest backend that fits a budget when downgrading.
|
|
9
|
+
*
|
|
10
|
+
* Numbers come from the canonical Phase B run JSONs:
|
|
11
|
+
* - canonical-hybrid: results/runs/2026-04-20T20-03-14-675 (Tier 1)
|
|
12
|
+
* - observational-memory-v10: results/runs/2026-04-23T04-14-40-609 (Tier 2a v10)
|
|
13
|
+
* - observational-memory-v11: results/runs/2026-04-23T17-27-28-793 (Tier 2b v11)
|
|
14
|
+
*
|
|
15
|
+
* The per-tier `avgCostPerQuery` is the totalUsd-divided-by-n_cases
|
|
16
|
+
* average; on routed configurations the actual per-call cost depends on
|
|
17
|
+
* which backend the dispatcher picked and which category the call hit, so
|
|
18
|
+
* the per-category breakdown below is what the router actually consumes.
|
|
19
|
+
*
|
|
20
|
+
* @module @framers/agentos/memory-router/backend-costs
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* canonical-hybrid: BM25 + dense + RRF + Cohere rerank-v3.5 over raw
|
|
24
|
+
* memory traces. Phase B measured 73.2% [69.2, 77.0] aggregate at
|
|
25
|
+
* $0.0213/correct.
|
|
26
|
+
*/
|
|
27
|
+
export const TIER_1_CANONICAL_COSTS = Object.freeze({
|
|
28
|
+
backend: 'canonical-hybrid',
|
|
29
|
+
avgCostPerQuery: 0.0156,
|
|
30
|
+
perCategoryAccuracy: Object.freeze({
|
|
31
|
+
'single-session-user': 0.971,
|
|
32
|
+
'single-session-assistant': 0.893,
|
|
33
|
+
'single-session-preference': 0.600,
|
|
34
|
+
'knowledge-update': 0.868,
|
|
35
|
+
'multi-session': 0.549,
|
|
36
|
+
'temporal-reasoning': 0.702,
|
|
37
|
+
}),
|
|
38
|
+
perCategoryCostPerQuery: Object.freeze({
|
|
39
|
+
'single-session-user': 0.0191,
|
|
40
|
+
'single-session-assistant': 0.0175,
|
|
41
|
+
'single-session-preference': 0.0206,
|
|
42
|
+
'knowledge-update': 0.0189,
|
|
43
|
+
'multi-session': 0.0196,
|
|
44
|
+
'temporal-reasoning': 0.0202,
|
|
45
|
+
}),
|
|
46
|
+
perCategoryLatencyMs: Object.freeze({
|
|
47
|
+
'single-session-user': 104837,
|
|
48
|
+
'single-session-assistant': 55252,
|
|
49
|
+
'single-session-preference': 58373,
|
|
50
|
+
'knowledge-update': 82807,
|
|
51
|
+
'multi-session': 131188,
|
|
52
|
+
'temporal-reasoning': 100881,
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* observational-memory-v10: synthesized observation log + classifier-driven
|
|
57
|
+
* dispatch inside the OM pipeline (no verbatim citation). Phase B measured
|
|
58
|
+
* 74.6% [70.8, 78.4] aggregate at $0.3265/correct, 12s avg latency.
|
|
59
|
+
*/
|
|
60
|
+
export const TIER_2A_V10_COSTS = Object.freeze({
|
|
61
|
+
backend: 'observational-memory-v10',
|
|
62
|
+
avgCostPerQuery: 0.2436,
|
|
63
|
+
perCategoryAccuracy: Object.freeze({
|
|
64
|
+
'single-session-user': 0.971,
|
|
65
|
+
'single-session-assistant': 0.839,
|
|
66
|
+
'single-session-preference': 0.600,
|
|
67
|
+
'knowledge-update': 0.859,
|
|
68
|
+
'multi-session': 0.602,
|
|
69
|
+
'temporal-reasoning': 0.710,
|
|
70
|
+
}),
|
|
71
|
+
perCategoryCostPerQuery: Object.freeze({
|
|
72
|
+
'single-session-user': 0.0214,
|
|
73
|
+
'single-session-assistant': 0.0195,
|
|
74
|
+
'single-session-preference': 0.0206,
|
|
75
|
+
'knowledge-update': 0.0306,
|
|
76
|
+
'multi-session': 0.0308,
|
|
77
|
+
'temporal-reasoning': 0.0206,
|
|
78
|
+
}),
|
|
79
|
+
perCategoryLatencyMs: Object.freeze({
|
|
80
|
+
'single-session-user': 7649,
|
|
81
|
+
'single-session-assistant': 5668,
|
|
82
|
+
'single-session-preference': 4469,
|
|
83
|
+
'knowledge-update': 19569,
|
|
84
|
+
'multi-session': 21360,
|
|
85
|
+
'temporal-reasoning': 4236,
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* observational-memory-v11: v10 + conditional verbatim citation rule for
|
|
90
|
+
* knowledge-update and single-session-user categories. Phase B measured
|
|
91
|
+
* 75.4% [71.6, 79.0] aggregate at $0.4362/correct, 14s avg latency.
|
|
92
|
+
*/
|
|
93
|
+
export const TIER_2B_V11_COSTS = Object.freeze({
|
|
94
|
+
backend: 'observational-memory-v11',
|
|
95
|
+
avgCostPerQuery: 0.3289,
|
|
96
|
+
perCategoryAccuracy: Object.freeze({
|
|
97
|
+
'single-session-user': 0.986,
|
|
98
|
+
'single-session-assistant': 0.839,
|
|
99
|
+
'single-session-preference': 0.633,
|
|
100
|
+
'knowledge-update': 0.872,
|
|
101
|
+
'multi-session': 0.617,
|
|
102
|
+
'temporal-reasoning': 0.692,
|
|
103
|
+
}),
|
|
104
|
+
perCategoryCostPerQuery: Object.freeze({
|
|
105
|
+
'single-session-user': 0.0212,
|
|
106
|
+
'single-session-assistant': 0.0192,
|
|
107
|
+
'single-session-preference': 0.0206,
|
|
108
|
+
'knowledge-update': 0.0307,
|
|
109
|
+
'multi-session': 0.0336,
|
|
110
|
+
'temporal-reasoning': 0.0209,
|
|
111
|
+
}),
|
|
112
|
+
perCategoryLatencyMs: Object.freeze({
|
|
113
|
+
'single-session-user': 6676,
|
|
114
|
+
'single-session-assistant': 6879,
|
|
115
|
+
'single-session-preference': 8822,
|
|
116
|
+
'knowledge-update': 21085,
|
|
117
|
+
'multi-session': 27423,
|
|
118
|
+
'temporal-reasoning': 5025,
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Default cost-points registry. Indexed by {@link MemoryBackendId} so the
|
|
123
|
+
* router can look up the picked backend's cost on any category.
|
|
124
|
+
*
|
|
125
|
+
* Custom deployments can substitute their own cost-points by passing a
|
|
126
|
+
* different `backendCosts` map into the {@link MemoryRouter} config —
|
|
127
|
+
* useful when a workload diverges from the LongMemEval-S Phase B
|
|
128
|
+
* distribution and the calibrator wants to plug in measurements from
|
|
129
|
+
* their own benchmark.
|
|
130
|
+
*/
|
|
131
|
+
export const DEFAULT_MEMORY_BACKEND_COSTS = Object.freeze({
|
|
132
|
+
'canonical-hybrid': TIER_1_CANONICAL_COSTS,
|
|
133
|
+
'observational-memory-v10': TIER_2A_V10_COSTS,
|
|
134
|
+
'observational-memory-v11': TIER_2B_V11_COSTS,
|
|
135
|
+
});
|
|
136
|
+
//# sourceMappingURL=backend-costs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-costs.js","sourceRoot":"","sources":["../../src/memory-router/backend-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