agentfootprint 9.4.0 → 9.5.0
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/AGENTS.md +2 -1
- package/dist/esm/memory/define.d.ts +2 -1
- package/dist/esm/memory/define.js +45 -8
- package/dist/esm/memory/define.js.map +1 -1
- package/dist/esm/memory/define.types.d.ts +30 -4
- package/dist/esm/memory/define.types.js +6 -0
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/index.d.ts +1 -0
- package/dist/esm/memory/index.js +3 -0
- package/dist/esm/memory/index.js.map +1 -1
- package/dist/esm/memory/pipeline/default.d.ts +16 -0
- package/dist/esm/memory/pipeline/default.js +8 -1
- package/dist/esm/memory/pipeline/default.js.map +1 -1
- package/dist/esm/memory/stages/filterByDecay.d.ts +67 -0
- package/dist/esm/memory/stages/filterByDecay.js +44 -0
- package/dist/esm/memory/stages/filterByDecay.js.map +1 -0
- package/dist/esm/memory/stages/index.d.ts +2 -0
- package/dist/esm/memory/stages/index.js +1 -0
- package/dist/esm/memory/stages/index.js.map +1 -1
- package/dist/esm/memory/strategies.d.ts +107 -0
- package/dist/esm/memory/strategies.js +232 -0
- package/dist/esm/memory/strategies.js.map +1 -0
- package/dist/memory/define.js +45 -8
- package/dist/memory/define.js.map +1 -1
- package/dist/memory/define.types.js +6 -0
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/index.js +6 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/pipeline/default.js +8 -1
- package/dist/memory/pipeline/default.js.map +1 -1
- package/dist/memory/stages/filterByDecay.js +48 -0
- package/dist/memory/stages/filterByDecay.js.map +1 -0
- package/dist/memory/stages/index.js +4 -1
- package/dist/memory/stages/index.js.map +1 -1
- package/dist/memory/strategies.js +238 -0
- package/dist/memory/strategies.js.map +1 -0
- package/dist/types/memory/define.d.ts +2 -1
- package/dist/types/memory/define.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +30 -4
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/index.d.ts +1 -0
- package/dist/types/memory/index.d.ts.map +1 -1
- package/dist/types/memory/pipeline/default.d.ts +16 -0
- package/dist/types/memory/pipeline/default.d.ts.map +1 -1
- package/dist/types/memory/stages/filterByDecay.d.ts +68 -0
- package/dist/types/memory/stages/filterByDecay.d.ts.map +1 -0
- package/dist/types/memory/stages/index.d.ts +2 -0
- package/dist/types/memory/stages/index.d.ts.map +1 -1
- package/dist/types/memory/strategies.d.ts +108 -0
- package/dist/types/memory/strategies.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Named memory strategies — what each one does, which TYPES accept it, and
|
|
4
|
+
* what the host must supply before it can run.
|
|
5
|
+
*
|
|
6
|
+
* `MEMORY_STRATEGIES` is a const of seven bare strings. A string is enough to
|
|
7
|
+
* WRITE `strategy: { kind: … }` and not nearly enough to OFFER the choice: a
|
|
8
|
+
* host rendering a strategy picker off that const offers seven options, and
|
|
9
|
+
* learns which of them this deployment can actually run by calling
|
|
10
|
+
* `defineMemory` and reading the exception. That is a selector that discovers
|
|
11
|
+
* its own capabilities by failing.
|
|
12
|
+
*
|
|
13
|
+
* So each strategy declares itself, and `listMemoryStrategies()` enumerates
|
|
14
|
+
* the declarations. The shape mirrors the influence exemplar in this same
|
|
15
|
+
* package (`listInfluenceStrategies()` → `{ name, description, requirements,
|
|
16
|
+
* scorer }`), with two deliberate differences:
|
|
17
|
+
*
|
|
18
|
+
* • the id is `kind`, not `name` — it is the value the caller writes into
|
|
19
|
+
* `strategy.kind`, so a picker's option value IS the id;
|
|
20
|
+
* • there is no `scorer`, because a memory strategy is not a function the
|
|
21
|
+
* host calls; what it needs instead is `types` — the memory TYPES that
|
|
22
|
+
* accept it, which is the other half of "can I offer this?" (`decay` on a
|
|
23
|
+
* SEMANTIC store is refused however good the host's credentials are).
|
|
24
|
+
*
|
|
25
|
+
* `requirements` is what a host must SUPPLY (an embedder, an LLM, a store
|
|
26
|
+
* that can search). Empty means the strategy runs anywhere, at $0.
|
|
27
|
+
*
|
|
28
|
+
* Pattern: declared capability descriptors + a guard that enforces them.
|
|
29
|
+
* Role: memory/ layer-1, beside the const it describes.
|
|
30
|
+
* Emits: N/A — build-time only.
|
|
31
|
+
*
|
|
32
|
+
* @see ./define.types.ts for `MEMORY_STRATEGIES` and the strategy union
|
|
33
|
+
* @see ../lib/influence-core/strategies.ts for the exemplar this follows
|
|
34
|
+
*/
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.assertStrategyRequirements = exports.memoryStrategyInfo = exports.listMemoryStrategies = void 0;
|
|
37
|
+
const define_types_js_1 = require("./define.types.js");
|
|
38
|
+
const capability_js_1 = require("./store/capability.js");
|
|
39
|
+
const WINDOW = Object.freeze({
|
|
40
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.WINDOW,
|
|
41
|
+
description: 'Keeps the last `size` entries — messages on an Episodic store, facts or beats on the ' +
|
|
42
|
+
'others. A pure rule: no LLM, no embeddings, nothing to configure but the number. The ' +
|
|
43
|
+
'right default for short-to-medium chats.',
|
|
44
|
+
requirements: Object.freeze([]),
|
|
45
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.EPISODIC, define_types_js_1.MEMORY_TYPES.SEMANTIC, define_types_js_1.MEMORY_TYPES.NARRATIVE]),
|
|
46
|
+
});
|
|
47
|
+
const BUDGET = Object.freeze({
|
|
48
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.BUDGET,
|
|
49
|
+
description: 'Injects as many recent entries as fit a token budget, and injects none at all when the ' +
|
|
50
|
+
'budget is below the floor. Free — the count is estimated, not modelled by a tokenizer ' +
|
|
51
|
+
'call. The decision (pick / skip-empty / skip-no-budget) is recorded as branch evidence.',
|
|
52
|
+
requirements: Object.freeze([]),
|
|
53
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.EPISODIC]),
|
|
54
|
+
});
|
|
55
|
+
const SUMMARIZE = Object.freeze({
|
|
56
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.SUMMARIZE,
|
|
57
|
+
description: 'Names a cheap LLM to compress older turns while the most recent `recent` turns stay ' +
|
|
58
|
+
'raw. HONEST CAVEAT (9.5.0): the compression stage exists but is not composed into the ' +
|
|
59
|
+
'pipeline `defineMemory` builds, so what runs today is the last `recent` entries, ' +
|
|
60
|
+
'verbatim — the `llm` is required and not yet called. Until it is wired, ' +
|
|
61
|
+
'`.compaction({ summarizer, model })` on the Agent is the summarizer that does run.',
|
|
62
|
+
requirements: Object.freeze(['llm']),
|
|
63
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.EPISODIC]),
|
|
64
|
+
});
|
|
65
|
+
const TOP_K = Object.freeze({
|
|
66
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.TOP_K,
|
|
67
|
+
description: 'Embeds the query and returns the closest stored entries above a threshold — strictly: ' +
|
|
68
|
+
'when nothing clears the threshold, nothing is injected. The embedder is exempt for a ' +
|
|
69
|
+
"store that declares `ranksBy: 'server-text'`, which takes the question as words and " +
|
|
70
|
+
'ranks it on its own side.',
|
|
71
|
+
requirements: Object.freeze(['embedder', 'vector-store']),
|
|
72
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.SEMANTIC, define_types_js_1.MEMORY_TYPES.CAUSAL]),
|
|
73
|
+
});
|
|
74
|
+
const EXTRACT = Object.freeze({
|
|
75
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.EXTRACT,
|
|
76
|
+
description: 'Distills each turn into structured facts or narrative beats on the WRITE side. ' +
|
|
77
|
+
"`extractor: 'pattern'` is regex heuristics — free, no dependency, which is why this " +
|
|
78
|
+
"strategy requires nothing. `extractor: 'llm'` additionally needs an `llm`, and is " +
|
|
79
|
+
'refused without one.',
|
|
80
|
+
requirements: Object.freeze([]),
|
|
81
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.SEMANTIC, define_types_js_1.MEMORY_TYPES.NARRATIVE]),
|
|
82
|
+
});
|
|
83
|
+
const DECAY = Object.freeze({
|
|
84
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.DECAY,
|
|
85
|
+
description: 'Lets old memory fade: each loaded entry is scored by age against a half-life and ' +
|
|
86
|
+
'dropped below `minScore`, so a long-running agent stops rehearsing last month. Free — ' +
|
|
87
|
+
'arithmetic on a timestamp, no LLM and no embeddings.',
|
|
88
|
+
requirements: Object.freeze([]),
|
|
89
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.EPISODIC]),
|
|
90
|
+
});
|
|
91
|
+
const HYBRID = Object.freeze({
|
|
92
|
+
kind: define_types_js_1.MEMORY_STRATEGIES.HYBRID,
|
|
93
|
+
description: 'Composes several strategies on one store. It requires nothing of its own — each ' +
|
|
94
|
+
'sub-strategy carries its own requirements, and every one of them is checked at build ' +
|
|
95
|
+
'so a hybrid cannot smuggle in a strategy this deployment cannot run.',
|
|
96
|
+
requirements: Object.freeze([]),
|
|
97
|
+
types: Object.freeze([define_types_js_1.MEMORY_TYPES.EPISODIC, define_types_js_1.MEMORY_TYPES.SEMANTIC, define_types_js_1.MEMORY_TYPES.NARRATIVE]),
|
|
98
|
+
});
|
|
99
|
+
const BUILT_IN = Object.freeze([
|
|
100
|
+
WINDOW,
|
|
101
|
+
BUDGET,
|
|
102
|
+
SUMMARIZE,
|
|
103
|
+
TOP_K,
|
|
104
|
+
EXTRACT,
|
|
105
|
+
DECAY,
|
|
106
|
+
HYBRID,
|
|
107
|
+
]);
|
|
108
|
+
/**
|
|
109
|
+
* Every memory strategy, described — cheapest first, in the order the docs
|
|
110
|
+
* teach them. Frozen: a host renders its picker straight off this.
|
|
111
|
+
*
|
|
112
|
+
* @example Offer only what this deployment can actually run
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { listMemoryStrategies } from 'agentfootprint/memory';
|
|
115
|
+
*
|
|
116
|
+
* const available = new Set(embedder ? ['embedder', 'vector-store'] : []);
|
|
117
|
+
* const offerable = listMemoryStrategies().filter(
|
|
118
|
+
* (s) => s.types.includes('episodic') && s.requirements.every((r) => available.has(r)),
|
|
119
|
+
* );
|
|
120
|
+
* // → window, budget, decay, hybrid — the four that cost nothing to run.
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
function listMemoryStrategies() {
|
|
124
|
+
return BUILT_IN;
|
|
125
|
+
}
|
|
126
|
+
exports.listMemoryStrategies = listMemoryStrategies;
|
|
127
|
+
/**
|
|
128
|
+
* One strategy's description by `kind`, or `undefined` for a string that is
|
|
129
|
+
* not a strategy at all.
|
|
130
|
+
*/
|
|
131
|
+
function memoryStrategyInfo(kind) {
|
|
132
|
+
return BUILT_IN.find((s) => s.kind === kind);
|
|
133
|
+
}
|
|
134
|
+
exports.memoryStrategyInfo = memoryStrategyInfo;
|
|
135
|
+
// ─── The guard that makes the declaration true ──────────────────────
|
|
136
|
+
/**
|
|
137
|
+
* Refuse a config whose strategy declares a requirement the caller did not
|
|
138
|
+
* supply — by name, at BUILD, with the fix in the message.
|
|
139
|
+
*
|
|
140
|
+
* WHY it runs LAST, after the pipeline dispatch rather than before it: the
|
|
141
|
+
* dispatch's own refusals know more than this one does. `defineMemory`'s
|
|
142
|
+
* TOP_K arm knows about the `ranksBy: 'server-text'` exemption AND about the
|
|
143
|
+
* write half it takes away; the CAUSAL arm knows that exemption does not
|
|
144
|
+
* apply to it; the EXTRACT arm knows the `llm` matters only for
|
|
145
|
+
* `extractor: 'llm'`. Speaking first would replace those messages with a
|
|
146
|
+
* blunter one. This is the BACKSTOP: it says something only when nothing
|
|
147
|
+
* better already did, and its job is that no declared requirement can go
|
|
148
|
+
* unchecked — the failure it exists to prevent is a missing dependency
|
|
149
|
+
* surfacing as a `TypeError` from five frames inside a stage, halfway
|
|
150
|
+
* through a paid run.
|
|
151
|
+
*
|
|
152
|
+
* @param options the config as written by the caller.
|
|
153
|
+
* @param site the call to name in the message, e.g. `defineMemory[chat]`.
|
|
154
|
+
*/
|
|
155
|
+
function assertStrategyRequirements(options, site) {
|
|
156
|
+
checkStrategy(options.strategy, options.type, options.store, site, undefined);
|
|
157
|
+
}
|
|
158
|
+
exports.assertStrategyRequirements = assertStrategyRequirements;
|
|
159
|
+
function checkStrategy(strategy, type, store, site, insideHybrid) {
|
|
160
|
+
const info = memoryStrategyInfo(strategy.kind);
|
|
161
|
+
// An unknown kind, or a kind this TYPE does not accept, is not this guard's
|
|
162
|
+
// business — the dispatch refuses both, and names the alternative.
|
|
163
|
+
if (!info || !info.types.includes(type))
|
|
164
|
+
return;
|
|
165
|
+
for (const requirement of info.requirements) {
|
|
166
|
+
if (isSatisfied(requirement, strategy, type, store, site))
|
|
167
|
+
continue;
|
|
168
|
+
throw new Error(missingRequirement(requirement, info, site, insideHybrid === true));
|
|
169
|
+
}
|
|
170
|
+
if (strategy.kind === define_types_js_1.MEMORY_STRATEGIES.HYBRID) {
|
|
171
|
+
// A hybrid is only as runnable as its parts, and the pipelines it builds
|
|
172
|
+
// do not all read every part — so the parts are checked HERE, where the
|
|
173
|
+
// caller's words still exist, rather than trusted to whatever the
|
|
174
|
+
// composed pipeline happens to consume.
|
|
175
|
+
for (const sub of strategy.strategies)
|
|
176
|
+
checkStrategy(sub, type, store, site, true);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function isSatisfied(requirement, strategy, type, store, site) {
|
|
180
|
+
// Read through a structural shape: the union's arms declare each other's
|
|
181
|
+
// fields as `never`, so the union itself cannot be asked these questions.
|
|
182
|
+
const s = strategy;
|
|
183
|
+
switch (requirement) {
|
|
184
|
+
case 'embedder':
|
|
185
|
+
// The one exemption, and it is a fact about the STORE: a backend that
|
|
186
|
+
// ranks TEXT on its own side has nothing here to embed. It does not
|
|
187
|
+
// extend to CAUSAL, which matches a stored query VECTOR — there is
|
|
188
|
+
// always a vector to produce there.
|
|
189
|
+
if (type !== define_types_js_1.MEMORY_TYPES.CAUSAL && (0, capability_js_1.resolveRankingMode)(store, site) === 'server-text') {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
return s.embedder !== undefined;
|
|
193
|
+
case 'vector-store':
|
|
194
|
+
return typeof store.search === 'function';
|
|
195
|
+
case 'llm':
|
|
196
|
+
return s.llm !== undefined;
|
|
197
|
+
default:
|
|
198
|
+
// A requirement this library does not know how to check is not a
|
|
199
|
+
// requirement it may fail the caller over.
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function missingRequirement(requirement, info, site, insideHybrid) {
|
|
204
|
+
const where = insideHybrid
|
|
205
|
+
? `the \`${info.kind}\` strategy inside \`hybrid\``
|
|
206
|
+
: `the \`${info.kind}\` strategy`;
|
|
207
|
+
const declared = ` Every strategy declares what it needs — \`listMemoryStrategies()\` reports ` +
|
|
208
|
+
`\`requirements: [${info.requirements.map((r) => `'${r}'`).join(', ')}]\` for this one, so a ` +
|
|
209
|
+
`host can check before it offers the choice.\n`;
|
|
210
|
+
switch (requirement) {
|
|
211
|
+
case 'embedder':
|
|
212
|
+
return (`${site}: ${where} needs an \`embedder\` and none was passed — somebody has to turn ` +
|
|
213
|
+
`the query into a vector before a store can rank it.\n` +
|
|
214
|
+
declared +
|
|
215
|
+
` Fix: pass \`embedder\` on the strategy (\`mockEmbedder()\` for dev/tests), or omit ` +
|
|
216
|
+
`it only for a store that declares \`ranksBy: 'server-text'\` and embeds on its own side.`);
|
|
217
|
+
case 'vector-store':
|
|
218
|
+
return (`${site}: ${where} needs a store that can \`search()\`, and the store you passed does ` +
|
|
219
|
+
`not implement one — nothing would ever rank the entries written to it.\n` +
|
|
220
|
+
declared +
|
|
221
|
+
` Fix: pass a vector-capable store — \`InMemoryStore\` (dev/tests), ` +
|
|
222
|
+
`\`sqliteVectorStore\` (durable, one file), \`pgVectorStore\`, \`s3VectorsStore\`, or any ` +
|
|
223
|
+
`adapter that ranks the vectors you give it.\n` +
|
|
224
|
+
` Or: keep this store and pick a strategy that ranks nothing — \`window\` (last N) ` +
|
|
225
|
+
`or \`budget\` (fit-to-tokens).`);
|
|
226
|
+
case 'llm':
|
|
227
|
+
return (`${site}: ${where} names an \`llm\` and none was passed.\n` +
|
|
228
|
+
declared +
|
|
229
|
+
` Fix: pass \`llm\` on the strategy — a cheap model is the point of it.\n` +
|
|
230
|
+
` Or: use \`{ kind: 'window', size: <recent> }\`, which needs nothing, and which is ` +
|
|
231
|
+
`what this strategy's read path does today (its compression stage is not yet wired).`);
|
|
232
|
+
default:
|
|
233
|
+
return (`${site}: ${where} declares \`${requirement}\` and it was not supplied.\n` +
|
|
234
|
+
declared +
|
|
235
|
+
` Fix: supply it, or pick a strategy whose \`requirements\` are empty.`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=strategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.js","sourceRoot":"","sources":["../../src/memory/strategies.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;;AAEH,uDAO2B;AAC3B,yDAA2D;AAyC3D,MAAM,MAAM,GAAuB,MAAM,CAAC,MAAM,CAAC;IAC/C,IAAI,EAAE,mCAAiB,CAAC,MAAM;IAC9B,WAAW,EACT,uFAAuF;QACvF,uFAAuF;QACvF,0CAA0C;IAC5C,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAW,CAAC;IACxC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,8BAAY,CAAC,QAAQ,EAAE,8BAAY,CAAC,QAAQ,EAAE,8BAAY,CAAC,SAAS,CAAC,CAAC;CAC7F,CAAC,CAAC;AAEH,MAAM,MAAM,GAAuB,MAAM,CAAC,MAAM,CAAC;IAC/C,IAAI,EAAE,mCAAiB,CAAC,MAAM;IAC9B,WAAW,EACT,yFAAyF;QACzF,wFAAwF;QACxF,yFAAyF;IAC3F,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAW,CAAC;IACxC,KAAK,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,eAAe,WAAW,+BAA+B;gBAC1E,QAAQ;gBACR,yEAAyE,CAC1E,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -42,7 +42,8 @@ import type { MemoryDefinition, ReadonlyMemoryFlowChart } from './define.types.j
|
|
|
42
42
|
* | --------- | ------------- | ------------------------ |
|
|
43
43
|
* | EPISODIC | WINDOW | defaultPipeline |
|
|
44
44
|
* | EPISODIC | BUDGET | defaultPipeline |
|
|
45
|
-
* | EPISODIC | SUMMARIZE | defaultPipeline
|
|
45
|
+
* | EPISODIC | SUMMARIZE | defaultPipeline (the compression stage is NOT composed in yet — see `listMemoryStrategies()`) |
|
|
46
|
+
* | EPISODIC | DECAY | defaultPipeline + filterByDecay stage |
|
|
46
47
|
* | SEMANTIC | TOP_K | semanticPipeline |
|
|
47
48
|
* | SEMANTIC | EXTRACT | factPipeline |
|
|
48
49
|
* | SEMANTIC | WINDOW | factPipeline (recency-load) |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAeH,OAAO,EAIL,KAAK,mBAAmB,EAazB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAInF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,gBAAgB,CAqC3E;AA8XD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,OAAO,CAErF"}
|
|
@@ -68,6 +68,12 @@ export type MemoryType = (typeof MEMORY_TYPES)[keyof typeof MEMORY_TYPES];
|
|
|
68
68
|
* `CAUSAL` type accepts ONLY `TOP_K` — its snapshots are matched semantically
|
|
69
69
|
* against the new query, never by recency, so `buildCausalPipeline` throws on
|
|
70
70
|
* any other strategy kind. Mix and match the non-Causal types.
|
|
71
|
+
*
|
|
72
|
+
* These are BARE STRINGS, which is enough to write one and not enough to
|
|
73
|
+
* OFFER one. `listMemoryStrategies()` (./strategies.ts) is the same seven
|
|
74
|
+
* described — what each does, which TYPES accept it, and what the host must
|
|
75
|
+
* supply (`requirements`) — so a picker can grey out what this deployment
|
|
76
|
+
* cannot run instead of finding out from an exception.
|
|
71
77
|
*/
|
|
72
78
|
export declare const MEMORY_STRATEGIES: {
|
|
73
79
|
readonly WINDOW: "window";
|
|
@@ -236,14 +242,34 @@ export interface ExtractStrategy {
|
|
|
236
242
|
readonly maxPerTurn?: number;
|
|
237
243
|
}
|
|
238
244
|
/**
|
|
239
|
-
* Decay —
|
|
240
|
-
*
|
|
245
|
+
* Decay — let old memory fade. Each loaded entry is scored by AGE against
|
|
246
|
+
* `halfLifeMs` (`2^(-age / halfLife)`) and dropped below `minScore`, so a
|
|
247
|
+
* long-running agent stops rehearsing last month. Free: arithmetic on a
|
|
248
|
+
* timestamp, no LLM and no embedder. EPISODIC only.
|
|
249
|
+
*
|
|
250
|
+
* Wired in 9.5.0. Before that, this type existed, `MEMORY_STRATEGIES.DECAY`
|
|
251
|
+
* existed, and `defineMemory` threw "not yet wired" on it.
|
|
252
|
+
*
|
|
253
|
+
* AGE, not use. The underlying model (`computeDecayFactor`) also has an
|
|
254
|
+
* access term, and the read path passes a neutral `1` for it: `accessCount`
|
|
255
|
+
* is bumped by `store.get()`, and no shipped read path calls `get()` — they
|
|
256
|
+
* `list()` or `search()`. A knob for it here would be wired to a counter
|
|
257
|
+
* that never moves, so there isn't one. Nothing stored is mutated either:
|
|
258
|
+
* an entry that decays out of one turn is still in the store, and the next
|
|
259
|
+
* turn scores it again.
|
|
241
260
|
*/
|
|
242
261
|
export interface DecayStrategy {
|
|
243
262
|
readonly kind: typeof MEMORY_STRATEGIES.DECAY;
|
|
244
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* How long before an untouched entry is worth half as much, in
|
|
265
|
+
* milliseconds. A day is `86_400_000`. Must be finite and non-negative —
|
|
266
|
+
* a negative half-life would score OLDER entries higher, so it is refused.
|
|
267
|
+
*/
|
|
245
268
|
readonly halfLifeMs: number;
|
|
246
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* Drop entries scoring below this. Default 0.1 — roughly "older than
|
|
271
|
+
* three-and-a-bit half-lives". `0` keeps everything.
|
|
272
|
+
*/
|
|
247
273
|
readonly minScore?: number;
|
|
248
274
|
}
|
|
249
275
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.types.d.ts","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AACX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE1E
|
|
1
|
+
{"version":3,"file":"define.types.d.ts","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,kBAAkB,CAE/E;AAID;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,oBAA8B,CAAC;AAEvE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,6BAA6B,sBAAgC,CAAC;AAE3E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -18,4 +18,5 @@ export * from './wire/index.js';
|
|
|
18
18
|
export * from './retrieval/index.js';
|
|
19
19
|
export { MEMORY_TYPES, MEMORY_STRATEGIES, MEMORY_TIMING, SNAPSHOT_PROJECTIONS, MEMORY_INJECTION_KEY_PREFIX, RETRIEVAL_EVIDENCE_KEY_PREFIX, isMemoryType, isMemoryStrategyKind, isMemoryTiming, isSnapshotProjection, memoryInjectionKey, isMemoryInjectionKey, retrievalEvidenceKey, isRetrievalEvidenceKey, type MemoryType, type MemoryStrategyKind, type MemoryTiming, type SnapshotProjection, type Strategy, type MemoryWindowStrategy, type BudgetStrategy, type SummarizeStrategy, type TopKStrategy, type TopKShorthandStrategy, type TopKRetrievalStrategy, type MemoryFlavor, type ExtractStrategy, type DecayStrategy, type HybridStrategy, type MemoryDefinition, type DefineMemoryOptions, type DefineEpisodicOptions, type DefineSemanticOptions, type DefineNarrativeOptions, type DefineCausalOptions, type MemoryRedactionPolicy, } from './define.types.js';
|
|
20
20
|
export { defineMemory } from './define.js';
|
|
21
|
+
export { listMemoryStrategies, memoryStrategyInfo, type MemoryStrategyInfo, type MemoryStrategyRequirement, } from './strategies.js';
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AAGrC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AAGrC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FilterByDecayConfig } from '../stages/filterByDecay.js';
|
|
1
2
|
import type { MemoryStore } from '../store/index.js';
|
|
2
3
|
import type { MemoryPipeline } from './types.js';
|
|
3
4
|
export interface DefaultPipelineConfig {
|
|
@@ -34,6 +35,21 @@ export interface DefaultPipelineConfig {
|
|
|
34
35
|
* retention windows.
|
|
35
36
|
*/
|
|
36
37
|
readonly writeTtlMs?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Let old entries fade (9.5.0). When present, a `FilterByDecay` stage is
|
|
40
|
+
* composed between the load and the picker: every loaded entry is scored
|
|
41
|
+
* by AGE against `halfLifeMs` and dropped below `minScore`, so a
|
|
42
|
+
* long-running conversation stops rehearsing last month.
|
|
43
|
+
*
|
|
44
|
+
* Absent — the historical behaviour — means no decay stage is compiled at
|
|
45
|
+
* all, not a decay stage that keeps everything. What is not in the chart
|
|
46
|
+
* cannot cost anything or appear in the narrative.
|
|
47
|
+
*
|
|
48
|
+
* `defineMemory({ strategy: { kind: MEMORY_STRATEGIES.DECAY, halfLifeMs } })`
|
|
49
|
+
* is the door most consumers use; this is the same thing, spelled at the
|
|
50
|
+
* pipeline level so it composes with `loadCount` / the budget knobs.
|
|
51
|
+
*/
|
|
52
|
+
readonly decay?: FilterByDecayConfig;
|
|
37
53
|
/**
|
|
38
54
|
* Override for the formatter's header text. Omit to use the default
|
|
39
55
|
* "Relevant context from prior conversations..." phrasing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../src/memory/pipeline/default.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../src/memory/pipeline/default.ts"],"names":[],"mappings":"AAoDA,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAKrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,qBAAqB;IACpC,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEhC,kFAAkF;IAClF,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;IAExD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAE7C;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B,gEAAgE;IAChE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,cAAc,CA2D7E"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* filterByDecay — read-side stage that lets old memory fade.
|
|
3
|
+
*
|
|
4
|
+
* Reads from scope: `loaded`
|
|
5
|
+
* Writes to scope: `loaded` (the survivors, order preserved)
|
|
6
|
+
*
|
|
7
|
+
* Where it sits:
|
|
8
|
+
*
|
|
9
|
+
* loadRecent → filterByDecay → pickByBudget → formatDefault
|
|
10
|
+
*
|
|
11
|
+
* BEFORE the picker on purpose. The picker spends a token budget on what it
|
|
12
|
+
* is given; deciding what has faded is not a budget question, and a stale
|
|
13
|
+
* entry that fits should still not be injected. Dropping first also means
|
|
14
|
+
* the budget is spent on entries that are still worth something.
|
|
15
|
+
*
|
|
16
|
+
* ## The score
|
|
17
|
+
*
|
|
18
|
+
* `computeDecayFactor` (memory/entry/decay.ts) is the model, unchanged:
|
|
19
|
+
*
|
|
20
|
+
* factor = 2^(-age / halfLife) · min(accessBoost^accessCount, 10)
|
|
21
|
+
*
|
|
22
|
+
* This stage passes `accessBoost: 1`, which makes the access term exactly
|
|
23
|
+
* `1` and the score purely age-based — and that is a truthful default rather
|
|
24
|
+
* than a timid one. `accessCount` is incremented by `store.get()`, and no
|
|
25
|
+
* shipped read path calls `get()`: they all `list()` or `search()`. So an
|
|
26
|
+
* access-weighted knob here would be a dial wired to a counter that never
|
|
27
|
+
* moves. When a read path starts bumping it, the term is already in the
|
|
28
|
+
* model and the knob can arrive with something real behind it.
|
|
29
|
+
*
|
|
30
|
+
* ## What is never dropped
|
|
31
|
+
*
|
|
32
|
+
* An entry whose `lastAccessedAt` is missing or not a finite number is KEPT.
|
|
33
|
+
* A store that does not date its entries has not told us they are old, and
|
|
34
|
+
* "I cannot date this" must not read as "this is ancient" — the arithmetic
|
|
35
|
+
* would produce `NaN`, and `NaN >= minScore` is false, which would silently
|
|
36
|
+
* drop every entry from such a store.
|
|
37
|
+
*/
|
|
38
|
+
import type { TypedScope } from 'footprintjs';
|
|
39
|
+
import type { MemoryState } from './types.js';
|
|
40
|
+
export interface FilterByDecayConfig {
|
|
41
|
+
/**
|
|
42
|
+
* How long, in milliseconds, before an untouched entry is worth half as
|
|
43
|
+
* much. `0` means "anything not written this instant is gone".
|
|
44
|
+
*/
|
|
45
|
+
readonly halfLifeMs: number;
|
|
46
|
+
/**
|
|
47
|
+
* Drop entries scoring below this. Default `0.1` — roughly "older than
|
|
48
|
+
* three-and-a-bit half-lives". `0` keeps everything, which is a coherent
|
|
49
|
+
* request (score, don't drop) and is honoured as written.
|
|
50
|
+
*/
|
|
51
|
+
readonly minScore?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Clock seam. Defaults to `Date.now`; tests pass a fixed clock so a decay
|
|
54
|
+
* assertion is arithmetic rather than a race.
|
|
55
|
+
*/
|
|
56
|
+
readonly now?: () => number;
|
|
57
|
+
}
|
|
58
|
+
/** See {@link FilterByDecayConfig.minScore}. */
|
|
59
|
+
export declare const DEFAULT_DECAY_MIN_SCORE = 0.1;
|
|
60
|
+
/**
|
|
61
|
+
* Build a stage that drops faded entries from `scope.loaded`.
|
|
62
|
+
*
|
|
63
|
+
* Pure arithmetic over what is already in scope: no store call, no LLM, no
|
|
64
|
+
* embedding, and no mutation of anything stored — an entry that decays out
|
|
65
|
+
* of one turn is still in the store, and a later turn scores it again.
|
|
66
|
+
*/
|
|
67
|
+
export declare function filterByDecay(config: FilterByDecayConfig): (scope: TypedScope<MemoryState>) => Promise<void>;
|
|
68
|
+
//# sourceMappingURL=filterByDecay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterByDecay.d.ts","sourceRoot":"","sources":["../../../../src/memory/stages/filterByDecay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAED,gDAAgD;AAChD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAQ3C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,WAQlC,WAAW,WAAW,CAAC,KAAG,QAAQ,IAAI,CAAC,CAoB7D"}
|
|
@@ -11,4 +11,6 @@ export { approximateTokenCounter, countMessageTokens } from './tokenize.js';
|
|
|
11
11
|
export type { TokenCounter } from './tokenize.js';
|
|
12
12
|
export { summarize } from './summarize.js';
|
|
13
13
|
export type { SummarizeConfig } from './summarize.js';
|
|
14
|
+
export { filterByDecay, DEFAULT_DECAY_MIN_SCORE } from './filterByDecay.js';
|
|
15
|
+
export type { FilterByDecayConfig } from './filterByDecay.js';
|
|
14
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/stages/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/stages/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named memory strategies — what each one does, which TYPES accept it, and
|
|
3
|
+
* what the host must supply before it can run.
|
|
4
|
+
*
|
|
5
|
+
* `MEMORY_STRATEGIES` is a const of seven bare strings. A string is enough to
|
|
6
|
+
* WRITE `strategy: { kind: … }` and not nearly enough to OFFER the choice: a
|
|
7
|
+
* host rendering a strategy picker off that const offers seven options, and
|
|
8
|
+
* learns which of them this deployment can actually run by calling
|
|
9
|
+
* `defineMemory` and reading the exception. That is a selector that discovers
|
|
10
|
+
* its own capabilities by failing.
|
|
11
|
+
*
|
|
12
|
+
* So each strategy declares itself, and `listMemoryStrategies()` enumerates
|
|
13
|
+
* the declarations. The shape mirrors the influence exemplar in this same
|
|
14
|
+
* package (`listInfluenceStrategies()` → `{ name, description, requirements,
|
|
15
|
+
* scorer }`), with two deliberate differences:
|
|
16
|
+
*
|
|
17
|
+
* • the id is `kind`, not `name` — it is the value the caller writes into
|
|
18
|
+
* `strategy.kind`, so a picker's option value IS the id;
|
|
19
|
+
* • there is no `scorer`, because a memory strategy is not a function the
|
|
20
|
+
* host calls; what it needs instead is `types` — the memory TYPES that
|
|
21
|
+
* accept it, which is the other half of "can I offer this?" (`decay` on a
|
|
22
|
+
* SEMANTIC store is refused however good the host's credentials are).
|
|
23
|
+
*
|
|
24
|
+
* `requirements` is what a host must SUPPLY (an embedder, an LLM, a store
|
|
25
|
+
* that can search). Empty means the strategy runs anywhere, at $0.
|
|
26
|
+
*
|
|
27
|
+
* Pattern: declared capability descriptors + a guard that enforces them.
|
|
28
|
+
* Role: memory/ layer-1, beside the const it describes.
|
|
29
|
+
* Emits: N/A — build-time only.
|
|
30
|
+
*
|
|
31
|
+
* @see ./define.types.ts for `MEMORY_STRATEGIES` and the strategy union
|
|
32
|
+
* @see ../lib/influence-core/strategies.ts for the exemplar this follows
|
|
33
|
+
*/
|
|
34
|
+
import { type DefineMemoryOptions, type MemoryStrategyKind, type MemoryType } from './define.types.js';
|
|
35
|
+
/**
|
|
36
|
+
* What a strategy needs the host to supply before it can run. A picker greys
|
|
37
|
+
* out (or refuses to offer) strategies whose requirements it cannot meet.
|
|
38
|
+
*
|
|
39
|
+
* Three well-known values ship; the type stays open so a consumer's own
|
|
40
|
+
* strategy descriptor can name something else:
|
|
41
|
+
*
|
|
42
|
+
* - `'embedder'` — an `Embedder` that turns text into a vector.
|
|
43
|
+
* - `'vector-store'` — a store that implements `search()`. Not the same
|
|
44
|
+
* requirement as an embedder: the embedder makes the
|
|
45
|
+
* query vector, the store is what ranks against it,
|
|
46
|
+
* and a deployment can easily have one without the
|
|
47
|
+
* other (`RedisStore` is a full memory store with no
|
|
48
|
+
* `search()` at all).
|
|
49
|
+
* - `'llm'` — a chat provider the strategy calls on the host's
|
|
50
|
+
* behalf.
|
|
51
|
+
*/
|
|
52
|
+
export type MemoryStrategyRequirement = 'embedder' | 'vector-store' | 'llm' | (string & Record<never, never>);
|
|
53
|
+
/**
|
|
54
|
+
* A memory strategy, described: enough for a host to render it in a picker
|
|
55
|
+
* and know, before it offers the option, whether this deployment can run it.
|
|
56
|
+
*/
|
|
57
|
+
export interface MemoryStrategyInfo {
|
|
58
|
+
/** The value written as `strategy.kind` — a member of `MEMORY_STRATEGIES`. */
|
|
59
|
+
readonly kind: MemoryStrategyKind;
|
|
60
|
+
/** One-or-two-sentence plain description, current-truth caveats included. */
|
|
61
|
+
readonly description: string;
|
|
62
|
+
/** What the host must supply. Empty = runs anywhere, no dependency, $0. */
|
|
63
|
+
readonly requirements: readonly MemoryStrategyRequirement[];
|
|
64
|
+
/** The memory TYPES that accept this strategy. Any other pair is refused. */
|
|
65
|
+
readonly types: readonly MemoryType[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Every memory strategy, described — cheapest first, in the order the docs
|
|
69
|
+
* teach them. Frozen: a host renders its picker straight off this.
|
|
70
|
+
*
|
|
71
|
+
* @example Offer only what this deployment can actually run
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { listMemoryStrategies } from 'agentfootprint/memory';
|
|
74
|
+
*
|
|
75
|
+
* const available = new Set(embedder ? ['embedder', 'vector-store'] : []);
|
|
76
|
+
* const offerable = listMemoryStrategies().filter(
|
|
77
|
+
* (s) => s.types.includes('episodic') && s.requirements.every((r) => available.has(r)),
|
|
78
|
+
* );
|
|
79
|
+
* // → window, budget, decay, hybrid — the four that cost nothing to run.
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function listMemoryStrategies(): readonly MemoryStrategyInfo[];
|
|
83
|
+
/**
|
|
84
|
+
* One strategy's description by `kind`, or `undefined` for a string that is
|
|
85
|
+
* not a strategy at all.
|
|
86
|
+
*/
|
|
87
|
+
export declare function memoryStrategyInfo(kind: string): MemoryStrategyInfo | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Refuse a config whose strategy declares a requirement the caller did not
|
|
90
|
+
* supply — by name, at BUILD, with the fix in the message.
|
|
91
|
+
*
|
|
92
|
+
* WHY it runs LAST, after the pipeline dispatch rather than before it: the
|
|
93
|
+
* dispatch's own refusals know more than this one does. `defineMemory`'s
|
|
94
|
+
* TOP_K arm knows about the `ranksBy: 'server-text'` exemption AND about the
|
|
95
|
+
* write half it takes away; the CAUSAL arm knows that exemption does not
|
|
96
|
+
* apply to it; the EXTRACT arm knows the `llm` matters only for
|
|
97
|
+
* `extractor: 'llm'`. Speaking first would replace those messages with a
|
|
98
|
+
* blunter one. This is the BACKSTOP: it says something only when nothing
|
|
99
|
+
* better already did, and its job is that no declared requirement can go
|
|
100
|
+
* unchecked — the failure it exists to prevent is a missing dependency
|
|
101
|
+
* surfacing as a `TypeError` from five frames inside a stage, halfway
|
|
102
|
+
* through a paid run.
|
|
103
|
+
*
|
|
104
|
+
* @param options the config as written by the caller.
|
|
105
|
+
* @param site the call to name in the message, e.g. `defineMemory[chat]`.
|
|
106
|
+
*/
|
|
107
|
+
export declare function assertStrategyRequirements(options: DefineMemoryOptions, site: string): void;
|
|
108
|
+
//# sourceMappingURL=strategies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../../src/memory/strategies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EAEhB,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,yBAAyB,GACjC,UAAU,GACV,cAAc,GACd,KAAK,GACL,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,YAAY,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC5D,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CACvC;AAsFD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,IAAI,SAAS,kBAAkB,EAAE,CAEpE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAE/E;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE3F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentfootprint",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"description": "The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|