@framers/agentos 0.2.7 → 0.2.9

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.
Files changed (69) hide show
  1. package/dist/cognitive-pipeline/index.d.ts +197 -0
  2. package/dist/cognitive-pipeline/index.d.ts.map +1 -0
  3. package/dist/cognitive-pipeline/index.js +193 -0
  4. package/dist/cognitive-pipeline/index.js.map +1 -0
  5. package/dist/ingest-router/IngestRouter.d.ts +72 -0
  6. package/dist/ingest-router/IngestRouter.d.ts.map +1 -0
  7. package/dist/ingest-router/IngestRouter.js +98 -0
  8. package/dist/ingest-router/IngestRouter.js.map +1 -0
  9. package/dist/ingest-router/classifier.d.ts +63 -0
  10. package/dist/ingest-router/classifier.d.ts.map +1 -0
  11. package/dist/ingest-router/classifier.js +111 -0
  12. package/dist/ingest-router/classifier.js.map +1 -0
  13. package/dist/ingest-router/costs.d.ts +48 -0
  14. package/dist/ingest-router/costs.d.ts.map +1 -0
  15. package/dist/ingest-router/costs.js +63 -0
  16. package/dist/ingest-router/costs.js.map +1 -0
  17. package/dist/ingest-router/dispatcher.d.ts +35 -0
  18. package/dist/ingest-router/dispatcher.d.ts.map +1 -0
  19. package/dist/ingest-router/dispatcher.js +32 -0
  20. package/dist/ingest-router/dispatcher.js.map +1 -0
  21. package/dist/ingest-router/index.d.ts +43 -0
  22. package/dist/ingest-router/index.d.ts.map +1 -0
  23. package/dist/ingest-router/index.js +37 -0
  24. package/dist/ingest-router/index.js.map +1 -0
  25. package/dist/ingest-router/routing-tables.d.ts +122 -0
  26. package/dist/ingest-router/routing-tables.d.ts.map +1 -0
  27. package/dist/ingest-router/routing-tables.js +145 -0
  28. package/dist/ingest-router/routing-tables.js.map +1 -0
  29. package/dist/ingest-router/select-strategy.d.ts +67 -0
  30. package/dist/ingest-router/select-strategy.d.ts.map +1 -0
  31. package/dist/ingest-router/select-strategy.js +100 -0
  32. package/dist/ingest-router/select-strategy.js.map +1 -0
  33. package/dist/memory-router/adaptive.d.ts +142 -0
  34. package/dist/memory-router/adaptive.d.ts.map +1 -0
  35. package/dist/memory-router/adaptive.js +202 -0
  36. package/dist/memory-router/adaptive.js.map +1 -0
  37. package/dist/memory-router/index.d.ts +2 -0
  38. package/dist/memory-router/index.d.ts.map +1 -1
  39. package/dist/memory-router/index.js +1 -0
  40. package/dist/memory-router/index.js.map +1 -1
  41. package/dist/read-router/ReadRouter.d.ts +58 -0
  42. package/dist/read-router/ReadRouter.d.ts.map +1 -0
  43. package/dist/read-router/ReadRouter.js +91 -0
  44. package/dist/read-router/ReadRouter.js.map +1 -0
  45. package/dist/read-router/classifier.d.ts +54 -0
  46. package/dist/read-router/classifier.d.ts.map +1 -0
  47. package/dist/read-router/classifier.js +104 -0
  48. package/dist/read-router/classifier.js.map +1 -0
  49. package/dist/read-router/costs.d.ts +23 -0
  50. package/dist/read-router/costs.d.ts.map +1 -0
  51. package/dist/read-router/costs.js +51 -0
  52. package/dist/read-router/costs.js.map +1 -0
  53. package/dist/read-router/dispatcher.d.ts +33 -0
  54. package/dist/read-router/dispatcher.d.ts.map +1 -0
  55. package/dist/read-router/dispatcher.js +29 -0
  56. package/dist/read-router/dispatcher.js.map +1 -0
  57. package/dist/read-router/index.d.ts +23 -0
  58. package/dist/read-router/index.d.ts.map +1 -0
  59. package/dist/read-router/index.js +17 -0
  60. package/dist/read-router/index.js.map +1 -0
  61. package/dist/read-router/routing-tables.d.ts +85 -0
  62. package/dist/read-router/routing-tables.d.ts.map +1 -0
  63. package/dist/read-router/routing-tables.js +79 -0
  64. package/dist/read-router/routing-tables.js.map +1 -0
  65. package/dist/read-router/select-strategy.d.ts +42 -0
  66. package/dist/read-router/select-strategy.d.ts.map +1 -0
  67. package/dist/read-router/select-strategy.js +92 -0
  68. package/dist/read-router/select-strategy.js.map +1 -0
  69. package/package.json +16 -1
@@ -0,0 +1,202 @@
1
+ /**
2
+ * @file adaptive.ts
3
+ * @description Self-calibrating routing-table generator.
4
+ *
5
+ * The shipping {@link MINIMIZE_COST_TABLE} / {@link BALANCED_TABLE} /
6
+ * {@link MAXIMIZE_ACCURACY_TABLE} are calibrated from LongMemEval-S
7
+ * Phase B N=500 measurements. For workloads whose cost-accuracy profile
8
+ * diverges from that distribution, those tables are not optimal.
9
+ *
10
+ * AdaptiveMemoryRouter takes a workload-specific calibration dataset
11
+ * (a list of {category, backend, costUsd, correct} samples) and derives
12
+ * a routing table from it. Same MemoryRouter API; different table
13
+ * source.
14
+ *
15
+ * Calibration workflow:
16
+ * 1. Run a Phase A sweep on your workload (a few hundred queries
17
+ * across a small subset of expected categories, dispatched to all
18
+ * candidate backends).
19
+ * 2. Each sample contributes one (category, backend, costUsd, correct)
20
+ * data point.
21
+ * 3. AdaptiveMemoryRouter aggregates these into per-(category, backend)
22
+ * mean cost + mean accuracy.
23
+ * 4. Apply a preset selection rule:
24
+ * - 'minimize-cost': cheapest backend within 2pp of best accuracy;
25
+ * if none within tolerance, pick best accuracy.
26
+ * - 'maximize-accuracy': highest accuracy; ties broken by cost.
27
+ * - 'balanced': best $/correct (mean cost divided by mean
28
+ * accuracy).
29
+ * 5. Categories with insufficient samples fall back to the static
30
+ * preset table.
31
+ *
32
+ * The router is otherwise identical to {@link MemoryRouter} — same
33
+ * decide() / decideAndDispatch() / budget-aware dispatch.
34
+ *
35
+ * @module @framers/agentos/memory-router/adaptive
36
+ */
37
+ import { MemoryRouter } from './MemoryRouter.js';
38
+ import { PRESET_TABLES, } from './routing-tables.js';
39
+ // ============================================================================
40
+ // Aggregation
41
+ // ============================================================================
42
+ /**
43
+ * Roll up raw calibration samples into per-(category, backend) cells.
44
+ * Each cell carries n, meanCost, meanAccuracy.
45
+ */
46
+ export function aggregateCalibration(samples) {
47
+ const acc = {};
48
+ for (const s of samples) {
49
+ if (!acc[s.category])
50
+ acc[s.category] = {};
51
+ if (!acc[s.category][s.backend]) {
52
+ acc[s.category][s.backend] = { n: 0, sumCost: 0, sumCorrect: 0 };
53
+ }
54
+ const cell = acc[s.category][s.backend];
55
+ cell.n += 1;
56
+ cell.sumCost += s.costUsd;
57
+ cell.sumCorrect += s.correct;
58
+ }
59
+ const out = {};
60
+ for (const cat of Object.keys(acc)) {
61
+ out[cat] = {};
62
+ const inner = out[cat];
63
+ for (const backend of Object.keys(acc[cat])) {
64
+ const cell = acc[cat][backend];
65
+ inner[backend] = {
66
+ n: cell.n,
67
+ meanCost: cell.sumCost / cell.n,
68
+ meanAccuracy: cell.sumCorrect / cell.n,
69
+ };
70
+ }
71
+ }
72
+ return out;
73
+ }
74
+ // ============================================================================
75
+ // Per-category selection
76
+ // ============================================================================
77
+ /**
78
+ * Select a backend for one category from aggregated calibration data
79
+ * using the named preset rule. Falls back to the preset's static table
80
+ * when calibration is insufficient.
81
+ */
82
+ export function selectByPreset(args) {
83
+ const { category, agg, preset, minSamplesPerCell = 1, accuracyTolerance = 0.02, } = args;
84
+ const fallbackTable = PRESET_TABLES[preset];
85
+ const fallback = fallbackTable.defaultMapping[category];
86
+ const cells = agg[category];
87
+ if (!cells)
88
+ return fallback;
89
+ // Filter cells meeting min-sample threshold.
90
+ const eligible = Object.entries(cells)
91
+ .filter(([, cell]) => cell.n >= minSamplesPerCell);
92
+ if (eligible.length === 0)
93
+ return fallback;
94
+ if (preset === 'maximize-accuracy') {
95
+ return eligible.reduce((best, [backend, cell]) => {
96
+ const [bestBackend, bestCell] = best;
97
+ if (cell.meanAccuracy > bestCell.meanAccuracy)
98
+ return [backend, cell];
99
+ if (cell.meanAccuracy === bestCell.meanAccuracy) {
100
+ return cell.meanCost < bestCell.meanCost ? [backend, cell] : best;
101
+ }
102
+ return best;
103
+ }, eligible[0])[0];
104
+ }
105
+ if (preset === 'balanced') {
106
+ // best $/correct (skip zero-accuracy cells to avoid div-by-zero)
107
+ const valid = eligible.filter(([, cell]) => cell.meanAccuracy > 0);
108
+ if (valid.length === 0)
109
+ return fallback;
110
+ return valid.reduce((best, [backend, cell]) => {
111
+ const [bestBackend, bestCell] = best;
112
+ const cellCpc = cell.meanCost / cell.meanAccuracy;
113
+ const bestCpc = bestCell.meanCost / bestCell.meanAccuracy;
114
+ return cellCpc < bestCpc ? [backend, cell] : best;
115
+ }, valid[0])[0];
116
+ }
117
+ // minimize-cost: cheapest within accuracyTolerance of best accuracy.
118
+ const bestAccuracy = Math.max(...eligible.map(([, cell]) => cell.meanAccuracy));
119
+ const withinTolerance = eligible.filter(([, cell]) => bestAccuracy - cell.meanAccuracy <= accuracyTolerance);
120
+ if (withinTolerance.length === 0) {
121
+ // No candidates within tolerance is impossible (the best-accuracy
122
+ // backend itself qualifies), but guard anyway.
123
+ return fallback;
124
+ }
125
+ return withinTolerance.reduce((best, [backend, cell]) => {
126
+ const [bestBackend, bestCell] = best;
127
+ return cell.meanCost < bestCell.meanCost ? [backend, cell] : best;
128
+ }, withinTolerance[0])[0];
129
+ }
130
+ // ============================================================================
131
+ // Table construction
132
+ // ============================================================================
133
+ const ALL_CATEGORIES = [
134
+ 'single-session-user',
135
+ 'single-session-assistant',
136
+ 'single-session-preference',
137
+ 'knowledge-update',
138
+ 'multi-session',
139
+ 'temporal-reasoning',
140
+ ];
141
+ /**
142
+ * Build a complete frozen routing table from calibration samples + a
143
+ * preset rule. Categories without enough calibration fall back to the
144
+ * preset's static table.
145
+ */
146
+ export function buildAdaptiveRoutingTable(args) {
147
+ const { samples, preset, minSamplesPerCell, accuracyTolerance, fallbackTable, } = args;
148
+ const agg = aggregateCalibration(samples);
149
+ const fb = fallbackTable ?? PRESET_TABLES[preset];
150
+ const mapping = {};
151
+ for (const cat of ALL_CATEGORIES) {
152
+ mapping[cat] = selectByPreset({
153
+ category: cat,
154
+ agg,
155
+ preset,
156
+ minSamplesPerCell,
157
+ accuracyTolerance,
158
+ });
159
+ // selectByPreset falls back to the preset's STATIC default mapping,
160
+ // not the caller-supplied fallback table. Apply the explicit
161
+ // fallback only when the static fallback wasn't applied because of
162
+ // missing data — easiest is to override after the fact.
163
+ if (!agg[cat] && fb !== PRESET_TABLES[preset]) {
164
+ mapping[cat] = fb.defaultMapping[cat];
165
+ }
166
+ }
167
+ return Object.freeze({
168
+ preset: preset,
169
+ defaultMapping: Object.freeze(mapping),
170
+ });
171
+ }
172
+ // ============================================================================
173
+ // AdaptiveMemoryRouter class
174
+ // ============================================================================
175
+ /**
176
+ * Memory router whose routing table is derived from a calibration
177
+ * dataset rather than a static preset. Otherwise identical API to
178
+ * {@link MemoryRouter}.
179
+ */
180
+ export class AdaptiveMemoryRouter extends MemoryRouter {
181
+ constructor(options) {
182
+ const derivedTable = buildAdaptiveRoutingTable({
183
+ samples: options.calibrationSamples,
184
+ preset: options.preset,
185
+ minSamplesPerCell: options.minSamplesPerCell,
186
+ accuracyTolerance: options.accuracyTolerance,
187
+ });
188
+ super({
189
+ ...options,
190
+ preset: options.preset,
191
+ routingTable: derivedTable,
192
+ });
193
+ this.derivedTable = derivedTable;
194
+ }
195
+ /**
196
+ * Inspect the derived routing table for debugging / telemetry.
197
+ */
198
+ getRoutingTable() {
199
+ return this.derivedTable;
200
+ }
201
+ }
202
+ //# sourceMappingURL=adaptive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adaptive.js","sourceRoot":"","sources":["../../src/memory-router/adaptive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,YAAY,EAA4B,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EACL,aAAa,GAKd,MAAM,qBAAqB,CAAC;AA4F7B,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAqC;IAErC,MAAM,GAAG,GAAuF,EAAE,CAAC;IAEnG,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;YAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC3C,IAA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AAE,CAAC;YAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,MAAM,EAAE,MAA4B;QACpC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;KACvC,CAAiB,CAAC;AACrB,CAAC;AAED,+EAA+E;AAC/E,6BAA6B;AAC7B,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAGpD,YAAY,OAAoC;QAC9C,MAAM,YAAY,GAAG,yBAAyB,CAAC;YAC7C,OAAO,EAAE,OAAO,CAAC,kBAAkB;YACnC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;YAC5C,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;SAC7C,CAAC,CAAC;QAEH,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,MAAM,EAAE,OAAO,CAAC,MAA4B;YAC5C,YAAY,EAAE,YAAY;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF"}
@@ -121,4 +121,6 @@ export { selectBackend, MemoryRouterUnknownCategoryError, MemoryRouterBudgetExce
121
121
  export { CLASSIFIER_SYSTEM_PROMPT, CLASSIFIER_SYSTEM_PROMPT_FEWSHOT, SAFE_FALLBACK_CATEGORY, LLMMemoryClassifier, normalizeClassifierOutput, parseClassifierOutput, } from './classifier.js';
122
122
  export { FunctionMemoryDispatcher, UnsupportedMemoryBackendError, } from './dispatcher.js';
123
123
  export { MemoryRouter, MemoryRouterDispatcherMissingError, } from './MemoryRouter.js';
124
+ export type { CalibrationSample, CalibrationCell, AggregatedCalibration, AdaptivePresetRule, SelectByPresetArgs, BuildAdaptiveRoutingTableArgs, AdaptiveMemoryRouterOptions, } from './adaptive.js';
125
+ export { aggregateCalibration, selectByPreset, buildAdaptiveRoutingTable, AdaptiveMemoryRouter, } from './adaptive.js';
124
126
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory-router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6GG;AAMH,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,YAAY,EACZ,kCAAkC,GACnC,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory-router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6GG;AAMH,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,4BAA4B,GAC7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,YAAY,EACZ,kCAAkC,GACnC,MAAM,mBAAmB,CAAC;AAM3B,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,eAAe,CAAC"}
@@ -118,4 +118,5 @@ export { selectBackend, MemoryRouterUnknownCategoryError, MemoryRouterBudgetExce
118
118
  export { CLASSIFIER_SYSTEM_PROMPT, CLASSIFIER_SYSTEM_PROMPT_FEWSHOT, SAFE_FALLBACK_CATEGORY, LLMMemoryClassifier, normalizeClassifierOutput, parseClassifierOutput, } from './classifier.js';
119
119
  export { FunctionMemoryDispatcher, UnsupportedMemoryBackendError, } from './dispatcher.js';
120
120
  export { MemoryRouter, MemoryRouterDispatcherMissingError, } from './MemoryRouter.js';
121
+ export { aggregateCalibration, selectByPreset, buildAdaptiveRoutingTable, AdaptiveMemoryRouter, } from './adaptive.js';
121
122
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory-router/index.ts"],"names":[],"mappings":"AAAA;;;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AAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,wBAAwB,EACxB,gCAAgC,EAChC,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,YAAY,EACZ,kCAAkC,GACnC,MAAM,mBAAmB,CAAC;AAgB3B,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,eAAe,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @file ReadRouter.ts
3
+ * @description Top-level read-stage orchestrator composing the read-intent
4
+ * classifier with the pure {@link selectReadStrategy} into a single
5
+ * per-query routing call.
6
+ *
7
+ * @module @framers/agentos/read-router/ReadRouter
8
+ */
9
+ import type { IReadIntentClassifier, ReadIntentClassifierResult } from './classifier.js';
10
+ import { type ReadStrategyCostPoint } from './costs.js';
11
+ import { type ReadIntent, type ReadRouterPreset, type ReadRoutingTable, type ReadStrategyId } from './routing-tables.js';
12
+ import { type ReadBudgetMode, type ReadRoutingDecision } from './select-strategy.js';
13
+ import type { IReadDispatcher } from './dispatcher.js';
14
+ export interface ReadBudgetPolicy {
15
+ readonly perReadUsd?: number;
16
+ readonly mode?: ReadBudgetMode;
17
+ }
18
+ export interface ReadRouterOptions {
19
+ readonly classifier: IReadIntentClassifier;
20
+ readonly preset?: ReadRouterPreset;
21
+ readonly routingTable?: ReadRoutingTable;
22
+ readonly mapping?: Partial<Record<ReadIntent, ReadStrategyId>>;
23
+ readonly budget?: ReadBudgetPolicy;
24
+ readonly strategyCosts?: Readonly<Record<ReadStrategyId, ReadStrategyCostPoint>>;
25
+ readonly useFewShotPrompt?: boolean;
26
+ readonly dispatcher?: IReadDispatcher<unknown, unknown>;
27
+ }
28
+ export interface ReadRouterDecideOptions {
29
+ readonly manualIntent?: ReadIntent;
30
+ readonly groundTruthIntent?: ReadIntent | null;
31
+ readonly useFewShotPrompt?: boolean;
32
+ }
33
+ export interface ReadRouterDecision {
34
+ readonly classifier: ReadIntentClassifierResult;
35
+ readonly routing: ReadRoutingDecision;
36
+ }
37
+ export interface ReadRouterDispatchedResult<TOutcome> {
38
+ readonly decision: ReadRouterDecision;
39
+ readonly outcome: TOutcome;
40
+ readonly strategy: ReadStrategyId;
41
+ }
42
+ export declare class ReadRouterDispatcherMissingError extends Error {
43
+ constructor();
44
+ }
45
+ export declare class ReadRouter {
46
+ private readonly classifier;
47
+ private readonly preset;
48
+ private readonly routingTable;
49
+ private readonly budgetPerReadUsd;
50
+ private readonly budgetMode;
51
+ private readonly strategyCosts;
52
+ private readonly defaultUseFewShotPrompt;
53
+ private readonly dispatcher;
54
+ constructor(options: ReadRouterOptions);
55
+ decide(query: string, evidence: readonly string[], options?: ReadRouterDecideOptions): Promise<ReadRouterDecision>;
56
+ decideAndDispatch<TOutcome, TPayload = undefined>(query: string, evidence: readonly string[], dispatchPayload?: TPayload, options?: ReadRouterDecideOptions): Promise<ReadRouterDispatchedResult<TOutcome>>;
57
+ }
58
+ //# sourceMappingURL=ReadRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadRouter.d.ts","sourceRoot":"","sources":["../../src/read-router/ReadRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAsB,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,mBAAmB,E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;IAC3B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAED,qBAAa,gCAAiC,SAAQ,KAAK;;CAQ1D;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwB;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmB;IAChD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAE5B;IACF,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAU;IAClD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2C;gBAE1D,OAAO,EAAE,iBAAiB;IA4BhC,MAAM,CACV,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAiCxB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EACpD,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,eAAe,CAAC,EAAE,QAAQ,EAC1B,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC;CAmBjD"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @file ReadRouter.ts
3
+ * @description Top-level read-stage orchestrator composing the read-intent
4
+ * classifier with the pure {@link selectReadStrategy} into a single
5
+ * per-query routing call.
6
+ *
7
+ * @module @framers/agentos/read-router/ReadRouter
8
+ */
9
+ import { DEFAULT_READ_COSTS } from './costs.js';
10
+ import { PRESET_READ_TABLES, } from './routing-tables.js';
11
+ import { selectReadStrategy, } from './select-strategy.js';
12
+ export class ReadRouterDispatcherMissingError extends Error {
13
+ constructor() {
14
+ super('ReadRouter.decideAndDispatch requires a dispatcher. ' +
15
+ 'Either pass a dispatcher in options or call `decide` and dispatch yourself.');
16
+ this.name = 'ReadRouterDispatcherMissingError';
17
+ }
18
+ }
19
+ export class ReadRouter {
20
+ constructor(options) {
21
+ this.classifier = options.classifier;
22
+ this.preset = options.preset ?? 'precise-fact';
23
+ this.dispatcher = options.dispatcher ?? null;
24
+ const baseTable = options.routingTable ?? PRESET_READ_TABLES[this.preset];
25
+ if (options.mapping) {
26
+ const patched = {
27
+ ...baseTable.defaultMapping,
28
+ };
29
+ for (const key of Object.keys(options.mapping)) {
30
+ const ov = options.mapping[key];
31
+ if (ov)
32
+ patched[key] = ov;
33
+ }
34
+ this.routingTable = Object.freeze({
35
+ preset: baseTable.preset,
36
+ defaultMapping: Object.freeze(patched),
37
+ });
38
+ }
39
+ else {
40
+ this.routingTable = baseTable;
41
+ }
42
+ this.budgetPerReadUsd = options.budget?.perReadUsd ?? null;
43
+ this.budgetMode = options.budget?.mode ?? 'cheapest-fallback';
44
+ this.strategyCosts = options.strategyCosts ?? DEFAULT_READ_COSTS;
45
+ this.defaultUseFewShotPrompt = options.useFewShotPrompt ?? false;
46
+ }
47
+ async decide(query, evidence, options) {
48
+ let classifier;
49
+ if (options?.manualIntent) {
50
+ classifier = {
51
+ intent: options.manualIntent,
52
+ tokensIn: 0,
53
+ tokensOut: 0,
54
+ model: 'manual',
55
+ };
56
+ }
57
+ else {
58
+ const useFewShot = options?.useFewShotPrompt ?? this.defaultUseFewShotPrompt;
59
+ classifier = await this.classifier.classify(query, evidence, useFewShot ? { useFewShotPrompt: true } : undefined);
60
+ }
61
+ const routing = selectReadStrategy({
62
+ predictedIntent: classifier.intent,
63
+ groundTruthIntent: options?.groundTruthIntent ?? null,
64
+ config: {
65
+ table: this.routingTable,
66
+ budgetPerReadUsd: this.budgetPerReadUsd,
67
+ budgetMode: this.budgetMode,
68
+ strategyCosts: this.strategyCosts,
69
+ },
70
+ });
71
+ return { classifier, routing };
72
+ }
73
+ async decideAndDispatch(query, evidence, dispatchPayload, options) {
74
+ if (!this.dispatcher) {
75
+ throw new ReadRouterDispatcherMissingError();
76
+ }
77
+ const decision = await this.decide(query, evidence, options);
78
+ const dispatched = (await this.dispatcher.dispatch({
79
+ strategy: decision.routing.chosenStrategy,
80
+ query,
81
+ evidence,
82
+ payload: dispatchPayload,
83
+ }));
84
+ return {
85
+ decision,
86
+ outcome: dispatched.outcome,
87
+ strategy: dispatched.strategy,
88
+ };
89
+ }
90
+ }
91
+ //# sourceMappingURL=ReadRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadRouter.js","sourceRoot":"","sources":["../../src/read-router/ReadRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,kBAAkB,EAA8B,MAAM,YAAY,CAAC;AAC5E,OAAO,EACL,kBAAkB,GAKnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAyC9B,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACzD;QACE,KAAK,CACH,sDAAsD;YACpD,6EAA6E,CAChF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;IACjD,CAAC;CACF;AAED,MAAM,OAAO,UAAU;IAYrB,YAAY,OAA0B;QACpC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;QAE7C,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1E,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,OAAO,GAAuC;gBAClD,GAAG,SAAS,CAAC,cAAc;aAC5B,CAAC;YACF,KAAK,MAAM,GAAG,IAAI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CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CACpD,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,kBAAkB,CAAC;YACjC,eAAe,EAAE,UAAU,CAAC,MAAM;YAClC,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,IAAI,IAAI;YACrD,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI,CAAC,YAAY;gBACxB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;gBACvC,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;aAClC;SACF,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,KAAa,EACb,QAA2B,EAC3B,eAA0B,EAC1B,OAAiC;QAEjC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,gCAAgC,EAAE,CAAC;QAC/C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjD,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,cAAc;YACzC,KAAK;YACL,QAAQ;YACR,OAAO,EAAE,eAA0B;SACpC,CAAC,CAAiC,CAAC;QAEpC,OAAO;YACL,QAAQ;YACR,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file classifier.ts
3
+ * @description LLM-as-judge classifier that maps a query+evidence pair
4
+ * to one of the five {@link ReadIntent} values.
5
+ *
6
+ * @module @framers/agentos/read-router/classifier
7
+ */
8
+ import { type ReadIntent } from './routing-tables.js';
9
+ export interface ReadIntentClassifierLLMRequest {
10
+ readonly system: string;
11
+ readonly user: string;
12
+ readonly maxTokens: number;
13
+ readonly temperature: number;
14
+ }
15
+ export interface ReadIntentClassifierLLMResponse {
16
+ readonly text: string;
17
+ readonly tokensIn: number;
18
+ readonly tokensOut: number;
19
+ readonly model: string;
20
+ }
21
+ export interface IReadIntentClassifierLLM {
22
+ invoke(request: ReadIntentClassifierLLMRequest): Promise<ReadIntentClassifierLLMResponse>;
23
+ }
24
+ export interface ReadIntentClassifierClassifyOptions {
25
+ readonly useFewShotPrompt?: boolean;
26
+ }
27
+ export interface ReadIntentClassifierResult {
28
+ readonly intent: ReadIntent;
29
+ readonly tokensIn: number;
30
+ readonly tokensOut: number;
31
+ readonly model: string;
32
+ }
33
+ export interface IReadIntentClassifier {
34
+ classify(query: string, evidence: readonly string[], options?: ReadIntentClassifierClassifyOptions): Promise<ReadIntentClassifierResult>;
35
+ }
36
+ export declare const READ_INTENT_CLASSIFIER_SYSTEM_PROMPT = "You are classifying a user query (with retrieved evidence) into one of five read intents.\n\nReturn ONLY the intent token (no explanation, no quotes, no punctuation).\n\nIntents:\n- precise-fact: the user wants a specific named entity, number, date, or fact. Examples: \"What is X's email?\", \"When was the last release?\"\n- multi-source-synthesis: the answer requires combining information from multiple evidence chunks. Examples: \"Summarize all the topics we discussed\", \"Aggregate counts across sessions.\"\n- time-interval: the query asks about durations, orderings, or \"how long ago / before / after\" timing. Examples: \"How many days since X?\", \"In what order did Y, Z, W happen?\"\n- preference-recommendation: the user wants tips, suggestions, advice, or recommendations grounded in their own context. Examples: \"Any tips for X?\", \"Can you suggest Y?\"\n- abstention-candidate: the question may be unanswerable from the evidence. Adversarial or off-topic. Examples: \"Where did I move to last year?\" when no move is in evidence.";
37
+ export declare const READ_INTENT_CLASSIFIER_SYSTEM_PROMPT_FEWSHOT = "You are classifying a user query (with retrieved evidence) into one of five read intents.\n\nReturn ONLY the intent token (no explanation, no quotes, no punctuation).\n\nIntents:\n- precise-fact: a specific named entity, number, date, or fact.\n- multi-source-synthesis: combining information across multiple evidence chunks.\n- time-interval: durations, orderings, or \"how long ago\".\n- preference-recommendation: tips / suggestions / advice grounded in user context.\n- abstention-candidate: question may be unanswerable from evidence.\n\nExamples:\n\nQuestion: What was my final boss's name in the game I played last week?\nIntent: precise-fact\n\nQuestion: What topics did we discuss across our last five conversations?\nIntent: multi-source-synthesis\n\nQuestion: How many weeks have passed since I started the new job?\nIntent: time-interval\n\nQuestion: Any tips for improving my morning routine?\nIntent: preference-recommendation\n\nQuestion: Where did I move to four years ago?\nIntent: abstention-candidate";
38
+ export declare const SAFE_READ_INTENT_FALLBACK: ReadIntent;
39
+ export declare function normalizeReadIntentClassifierOutput(raw: string): string;
40
+ export declare function parseReadIntentClassifierOutput(raw: string): ReadIntent;
41
+ export interface LLMReadIntentClassifierOptions {
42
+ readonly llm: IReadIntentClassifierLLM;
43
+ readonly maxTokens?: number;
44
+ /** Max evidence-preview chars forwarded to the classifier. Default 600. */
45
+ readonly maxEvidenceChars?: number;
46
+ }
47
+ export declare class LLMReadIntentClassifier implements IReadIntentClassifier {
48
+ private readonly llm;
49
+ private readonly maxTokens;
50
+ private readonly maxEvidenceChars;
51
+ constructor(options: LLMReadIntentClassifierOptions);
52
+ classify(query: string, evidence: readonly string[], options?: ReadIntentClassifierClassifyOptions): Promise<ReadIntentClassifierResult>;
53
+ }
54
+ //# sourceMappingURL=classifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../src/read-router/classifier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMpE,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SA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,EAAE,MAAM,CAAC;IAC5B,2EAA2E;IAC3E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,qBAAa,uBAAwB,YAAW,qBAAqB;IACnE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA2B;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;gBAE9B,OAAO,EAAE,8BAA8B;IAM7C,QAAQ,CACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,OAAO,CAAC,EAAE,mCAAmC,GAC5C,OAAO,CAAC,0BAA0B,CAAC;CAuBvC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @file classifier.ts
3
+ * @description LLM-as-judge classifier that maps a query+evidence pair
4
+ * to one of the five {@link ReadIntent} values.
5
+ *
6
+ * @module @framers/agentos/read-router/classifier
7
+ */
8
+ import { READ_INTENTS } from './routing-tables.js';
9
+ // ============================================================================
10
+ // Prompts
11
+ // ============================================================================
12
+ export const READ_INTENT_CLASSIFIER_SYSTEM_PROMPT = `You are classifying a user query (with retrieved evidence) into one of five read intents.
13
+
14
+ Return ONLY the intent token (no explanation, no quotes, no punctuation).
15
+
16
+ Intents:
17
+ - precise-fact: the user wants a specific named entity, number, date, or fact. Examples: "What is X's email?", "When was the last release?"
18
+ - multi-source-synthesis: the answer requires combining information from multiple evidence chunks. Examples: "Summarize all the topics we discussed", "Aggregate counts across sessions."
19
+ - time-interval: the query asks about durations, orderings, or "how long ago / before / after" timing. Examples: "How many days since X?", "In what order did Y, Z, W happen?"
20
+ - preference-recommendation: the user wants tips, suggestions, advice, or recommendations grounded in their own context. Examples: "Any tips for X?", "Can you suggest Y?"
21
+ - abstention-candidate: the question may be unanswerable from the evidence. Adversarial or off-topic. Examples: "Where did I move to last year?" when no move is in evidence.`;
22
+ export const READ_INTENT_CLASSIFIER_SYSTEM_PROMPT_FEWSHOT = `You are classifying a user query (with retrieved evidence) into one of five read intents.
23
+
24
+ Return ONLY the intent token (no explanation, no quotes, no punctuation).
25
+
26
+ Intents:
27
+ - precise-fact: a specific named entity, number, date, or fact.
28
+ - multi-source-synthesis: combining information across multiple evidence chunks.
29
+ - time-interval: durations, orderings, or "how long ago".
30
+ - preference-recommendation: tips / suggestions / advice grounded in user context.
31
+ - abstention-candidate: question may be unanswerable from evidence.
32
+
33
+ Examples:
34
+
35
+ Question: What was my final boss's name in the game I played last week?
36
+ Intent: precise-fact
37
+
38
+ Question: What topics did we discuss across our last five conversations?
39
+ Intent: multi-source-synthesis
40
+
41
+ Question: How many weeks have passed since I started the new job?
42
+ Intent: time-interval
43
+
44
+ Question: Any tips for improving my morning routine?
45
+ Intent: preference-recommendation
46
+
47
+ Question: Where did I move to four years ago?
48
+ Intent: abstention-candidate`;
49
+ export const SAFE_READ_INTENT_FALLBACK = 'multi-source-synthesis';
50
+ export function normalizeReadIntentClassifierOutput(raw) {
51
+ const lines = raw.split('\n');
52
+ let firstLine = '';
53
+ for (const ln of lines) {
54
+ if (ln.trim().length > 0) {
55
+ firstLine = ln;
56
+ break;
57
+ }
58
+ }
59
+ let cleaned = firstLine.trim().toLowerCase();
60
+ cleaned = cleaned.replace(/^(intent|category|type|answer|label|class)\s*[:\-=]\s*/, '');
61
+ cleaned = cleaned.replace(/^["'`]+|["'`]+$/g, '');
62
+ cleaned = cleaned.replace(/[.,;!?]+$/g, '');
63
+ return cleaned.trim();
64
+ }
65
+ export function parseReadIntentClassifierOutput(raw) {
66
+ const cleaned = normalizeReadIntentClassifierOutput(raw);
67
+ for (const token of READ_INTENTS) {
68
+ if (cleaned === token ||
69
+ cleaned.startsWith(`${token} `) ||
70
+ cleaned.startsWith(`${token}\n`)) {
71
+ return token;
72
+ }
73
+ }
74
+ return SAFE_READ_INTENT_FALLBACK;
75
+ }
76
+ export class LLMReadIntentClassifier {
77
+ constructor(options) {
78
+ this.llm = options.llm;
79
+ this.maxTokens = options.maxTokens ?? 16;
80
+ this.maxEvidenceChars = options.maxEvidenceChars ?? 600;
81
+ }
82
+ async classify(query, evidence, options) {
83
+ const system = options?.useFewShotPrompt
84
+ ? READ_INTENT_CLASSIFIER_SYSTEM_PROMPT_FEWSHOT
85
+ : READ_INTENT_CLASSIFIER_SYSTEM_PROMPT;
86
+ const evidencePreview = evidence
87
+ .join('\n---\n')
88
+ .slice(0, this.maxEvidenceChars);
89
+ const user = `Question: ${query}\n\nEvidence (preview):\n${evidencePreview}\n\nIntent:`;
90
+ const response = await this.llm.invoke({
91
+ system,
92
+ user,
93
+ maxTokens: this.maxTokens,
94
+ temperature: 0,
95
+ });
96
+ return {
97
+ intent: parseReadIntentClassifierOutput(response.text),
98
+ tokensIn: response.tokensIn,
99
+ tokensOut: response.tokensOut,
100
+ model: response.model,
101
+ };
102
+ }
103
+ }
104
+ //# sourceMappingURL=classifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.js","sourceRoot":"","sources":["../../src/read-router/classifier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAmB,MAAM,qBAAqB,CAAC;AAiDpE,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,MAAM,CAAC,MAAM,oCAAoC,GAAG;;;;;;;;;8KAS0H,CAAC;AAE/K,MAAM,CAAC,MAAM,4CAA4C,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0B/B,CAAC;AAE9B,MAAM,CAAC,MAAM,yBAAyB,GAAe,wBAAwB,CAAC;AAE9E,MAAM,UAAU,mCAAmC,CAAC,GAAW;IAC7D,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC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;aAC7B,IAAI,CAAC,SAAS,CAAC;aACf,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,aAAa,KAAK,4BAA4B,eAAe,aAAa,CAAC;QAExF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YACrC,MAAM;YACN,IAAI;YACJ,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,WAAW,EAAE,CAAC;SACf,CAAC,CAAC;QAEH,OAAO;YACL,MAAM,EAAE,+BAA+B,CAAC,QAAQ,CAAC,IAAI,CAAC;YACtD,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,KAAK,EAAE,QAAQ,CAAC,KAAK;SACtB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file costs.ts
3
+ * @description Per-strategy cost-points for ReadRouter budget logic.
4
+ * Numbers are illustrative averages on gpt-4o reader; consumers should
5
+ * override with measurements from their own workload.
6
+ *
7
+ * @module @framers/agentos/read-router/costs
8
+ */
9
+ import type { ReadStrategyId } from './routing-tables.js';
10
+ export interface ReadStrategyCostPoint {
11
+ readonly strategy: ReadStrategyId;
12
+ readonly avgCostPerReadUsd: number;
13
+ readonly avgLatencyMs: number;
14
+ readonly callCount: number;
15
+ readonly description: string;
16
+ }
17
+ export declare const SINGLE_CALL_COST: ReadStrategyCostPoint;
18
+ export declare const TWO_CALL_EXTRACT_ANSWER_COST: ReadStrategyCostPoint;
19
+ export declare const COMMIT_VS_ABSTAIN_COST: ReadStrategyCostPoint;
20
+ export declare const VERBATIM_CITATION_COST: ReadStrategyCostPoint;
21
+ export declare const SCRATCHPAD_COST: ReadStrategyCostPoint;
22
+ export declare const DEFAULT_READ_COSTS: Readonly<Record<ReadStrategyId, ReadStrategyCostPoint>>;
23
+ //# sourceMappingURL=costs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"costs.d.ts","sourceRoot":"","sources":["../../src/read-router/costs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,gBAAgB,EAAE,qBAMJ,CAAC;AAE5B,eAAO,MAAM,4BAA4B,EAAE,qBAMhB,CAAC;AAE5B,eAAO,MAAM,sBAAsB,EAAE,qBAMV,CAAC;AAE5B,eAAO,MAAM,sBAAsB,EAAE,qBAMV,CAAC;AAE5B,eAAO,MAAM,eAAe,EAAE,qBAMH,CAAC;AAE5B,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CACvC,MAAM,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAO7C,CAAC"}