@mastra/memory 1.23.1 → 1.24.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/CHANGELOG.md +50 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +3 -205
- package/dist/docs/references/docs-memory-message-history.md +19 -1
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-vectors-mongodb.md +185 -4
- package/dist/index.cjs +30 -72
- package/dist/index.d.ts +2 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/processors/index.cjs +32 -129
- package/dist/processors/index.js +2 -4
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/src-Ci_GvBVm.js +28106 -0
- package/dist/src-Ci_GvBVm.js.map +1 -0
- package/dist/src-VD6qMn-H.cjs +28360 -0
- package/dist/src-VD6qMn-H.cjs.map +1 -0
- package/package.json +11 -10
- package/dist/chunk-43FJOLKM.cjs +0 -108
- package/dist/chunk-43FJOLKM.cjs.map +0 -1
- package/dist/chunk-D4J4XPGM.cjs +0 -111
- package/dist/chunk-D4J4XPGM.cjs.map +0 -1
- package/dist/chunk-EGRHWZRV.js +0 -3
- package/dist/chunk-EGRHWZRV.js.map +0 -1
- package/dist/chunk-LSJJAJAF.js +0 -105
- package/dist/chunk-LSJJAJAF.js.map +0 -1
- package/dist/chunk-NKIQRCOM.cjs +0 -4
- package/dist/chunk-NKIQRCOM.cjs.map +0 -1
- package/dist/chunk-TSABI3S4.cjs +0 -31496
- package/dist/chunk-TSABI3S4.cjs.map +0 -1
- package/dist/chunk-WCGXQIEN.js +0 -103
- package/dist/chunk-WCGXQIEN.js.map +0 -1
- package/dist/chunk-XOCZP6LJ.js +0 -31429
- package/dist/chunk-XOCZP6LJ.js.map +0 -1
- package/dist/constants-RMCTOZE3.js +0 -3
- package/dist/constants-RMCTOZE3.js.map +0 -1
- package/dist/constants-ZEKSZ4UM.cjs +0 -28
- package/dist/constants-ZEKSZ4UM.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/observational-memory-HQ4AP566.js +0 -4
- package/dist/observational-memory-HQ4AP566.js.map +0 -1
- package/dist/observational-memory-NZSUTGPH.cjs +0 -129
- package/dist/observational-memory-NZSUTGPH.cjs.map +0 -1
- package/dist/processors/index.cjs.map +0 -1
- package/dist/processors/index.js.map +0 -1
- package/dist/working-memory-state-LDPWYVCG.cjs +0 -24
- package/dist/working-memory-state-LDPWYVCG.cjs.map +0 -1
- package/dist/working-memory-state-OMSMSYAW.js +0 -3
- package/dist/working-memory-state-OMSMSYAW.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"@vitest/coverage-v8": "4.1.10",
|
|
57
57
|
"@vitest/ui": "4.1.10",
|
|
58
58
|
"eslint": "^10.7.0",
|
|
59
|
-
"
|
|
59
|
+
"tsdown": "0.22.9",
|
|
60
60
|
"tsx": "^4.23.1",
|
|
61
61
|
"typescript": "^6.0.3",
|
|
62
62
|
"typescript-eslint": "^8.57.0",
|
|
63
63
|
"vitest": "4.1.10",
|
|
64
|
-
"@internal/ai-sdk-v5": "0.0.
|
|
65
|
-
"@internal/
|
|
66
|
-
"@internal/
|
|
67
|
-
"@internal/
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
64
|
+
"@internal/ai-sdk-v5": "0.0.65",
|
|
65
|
+
"@internal/lint": "0.0.118",
|
|
66
|
+
"@internal/types-builder": "0.0.93",
|
|
67
|
+
"@internal/ai-v6": "0.0.65",
|
|
68
|
+
"@internal/ai-sdk-v4": "0.0.65",
|
|
69
|
+
"@mastra/core": "1.54.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@mastra/core": ">=1.4.1-0 <2.0.0-0"
|
|
@@ -85,12 +85,13 @@
|
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"check": "tsc --noEmit",
|
|
88
|
-
"build:lib": "
|
|
88
|
+
"build:lib": "tsdown --silent --config tsdown.config.ts",
|
|
89
89
|
"build:watch": "pnpm build:lib --watch",
|
|
90
90
|
"test:integration": "cd integration-tests && pnpm run test",
|
|
91
91
|
"test:unit": "pnpm vitest run ./src/*",
|
|
92
92
|
"test": "pnpm test:integration && pnpm test:unit",
|
|
93
|
-
"lint": "eslint .",
|
|
93
|
+
"lint": "oxlint . && eslint .",
|
|
94
|
+
"lint:fix": "oxlint --fix . && eslint --fix .",
|
|
94
95
|
"analyze:om-repro": "node ./scripts/analyze-om-repro.mjs",
|
|
95
96
|
"sanitize:om-repro": "node ./scripts/sanitize-om-repro.mjs"
|
|
96
97
|
}
|
package/dist/chunk-43FJOLKM.cjs
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
var diff = require('diff');
|
|
5
|
-
|
|
6
|
-
// src/processors/working-memory-state/processor.ts
|
|
7
|
-
var WORKING_MEMORY_STATE_ID = "working-memory";
|
|
8
|
-
var WORKING_MEMORY_STATE_PROCESSOR_ID = "working-memory-state";
|
|
9
|
-
var WorkingMemoryStateProcessor = class {
|
|
10
|
-
constructor(memory, memoryConfig) {
|
|
11
|
-
this.memory = memory;
|
|
12
|
-
this.memoryConfig = memoryConfig;
|
|
13
|
-
}
|
|
14
|
-
memory;
|
|
15
|
-
memoryConfig;
|
|
16
|
-
id = WORKING_MEMORY_STATE_PROCESSOR_ID;
|
|
17
|
-
stateId = WORKING_MEMORY_STATE_ID;
|
|
18
|
-
async computeStateSignal(args) {
|
|
19
|
-
const template = await this.memory.getWorkingMemoryTemplate({ memoryConfig: this.memoryConfig });
|
|
20
|
-
if (!template) return;
|
|
21
|
-
const data = await this.memory.getWorkingMemory({
|
|
22
|
-
threadId: args.threadId,
|
|
23
|
-
resourceId: args.resourceId,
|
|
24
|
-
memoryConfig: this.memoryConfig
|
|
25
|
-
});
|
|
26
|
-
const contents = data?.trim();
|
|
27
|
-
if (!contents) return;
|
|
28
|
-
const cacheKey = stableWorkingMemoryCacheKey({ format: template.format, data: contents });
|
|
29
|
-
const shouldMakeSnapshot = !args.contextWindow.hasSnapshot;
|
|
30
|
-
if (args.tracking?.currentCacheKey === cacheKey && !shouldMakeSnapshot) return;
|
|
31
|
-
const mergedConfig = this.memory.getMergedThreadConfig(this.memoryConfig);
|
|
32
|
-
const scope = mergedConfig.workingMemory?.scope ?? "resource";
|
|
33
|
-
const deltaCandidate = template.format === "markdown" && !shouldMakeSnapshot ? buildMarkdownDelta({
|
|
34
|
-
lastSnapshot: args.lastSnapshot,
|
|
35
|
-
deltasSinceSnapshot: args.deltasSinceSnapshot,
|
|
36
|
-
nextContents: contents
|
|
37
|
-
}) : void 0;
|
|
38
|
-
if (deltaCandidate) {
|
|
39
|
-
return {
|
|
40
|
-
id: WORKING_MEMORY_STATE_ID,
|
|
41
|
-
mode: "delta",
|
|
42
|
-
cacheKey,
|
|
43
|
-
tagName: "working-memory",
|
|
44
|
-
contents: deltaCandidate.contents,
|
|
45
|
-
delta: deltaCandidate.contents,
|
|
46
|
-
// Stash the full post-edit text on the signal so the next turn can
|
|
47
|
-
// diff against the most recently emitted state instead of the older
|
|
48
|
-
// snapshot. Invisible to the model.
|
|
49
|
-
value: contents,
|
|
50
|
-
attributes: {
|
|
51
|
-
format: template.format,
|
|
52
|
-
scope,
|
|
53
|
-
patch: "unified-diff"
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
id: WORKING_MEMORY_STATE_ID,
|
|
59
|
-
mode: "snapshot",
|
|
60
|
-
cacheKey,
|
|
61
|
-
tagName: "working-memory",
|
|
62
|
-
contents,
|
|
63
|
-
// Mirror contents in value so the first delta after a snapshot has a
|
|
64
|
-
// typed prior-state to diff against without falling back to contents.
|
|
65
|
-
value: contents,
|
|
66
|
-
attributes: {
|
|
67
|
-
format: template.format,
|
|
68
|
-
scope
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
function stableWorkingMemoryCacheKey(input) {
|
|
74
|
-
const hash = crypto.createHash("sha256");
|
|
75
|
-
hash.update(input.format);
|
|
76
|
-
hash.update("\0");
|
|
77
|
-
hash.update(input.data ?? "");
|
|
78
|
-
return `sha256:${hash.digest("hex")}`;
|
|
79
|
-
}
|
|
80
|
-
function buildMarkdownDelta(args) {
|
|
81
|
-
const { lastSnapshot, deltasSinceSnapshot, nextContents } = args;
|
|
82
|
-
const latestDelta = deltasSinceSnapshot.at(-1);
|
|
83
|
-
const prior = pickStringValue(readSignalValue(latestDelta)) ?? pickStringValue(readSignalValue(lastSnapshot)) ?? (typeof lastSnapshot?.contents === "string" ? lastSnapshot.contents : void 0);
|
|
84
|
-
if (!prior) return;
|
|
85
|
-
const patch = renderHunksOnly(prior, nextContents);
|
|
86
|
-
return { contents: patch };
|
|
87
|
-
}
|
|
88
|
-
function pickStringValue(value) {
|
|
89
|
-
return typeof value === "string" ? value : void 0;
|
|
90
|
-
}
|
|
91
|
-
function readSignalValue(signal) {
|
|
92
|
-
return signal?.metadata?.value;
|
|
93
|
-
}
|
|
94
|
-
function renderHunksOnly(prior, next) {
|
|
95
|
-
const { hunks } = diff.structuredPatch("", "", prior, next, "", "", { context: 0 });
|
|
96
|
-
return hunks.map((hunk) => {
|
|
97
|
-
const header = `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`;
|
|
98
|
-
const lines = hunk.lines.filter((line) => !line.startsWith("\"));
|
|
99
|
-
return [header, ...lines].join("\n");
|
|
100
|
-
}).join("\n");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
exports.WORKING_MEMORY_STATE_ID = WORKING_MEMORY_STATE_ID;
|
|
104
|
-
exports.WORKING_MEMORY_STATE_PROCESSOR_ID = WORKING_MEMORY_STATE_PROCESSOR_ID;
|
|
105
|
-
exports.WorkingMemoryStateProcessor = WorkingMemoryStateProcessor;
|
|
106
|
-
exports.stableWorkingMemoryCacheKey = stableWorkingMemoryCacheKey;
|
|
107
|
-
//# sourceMappingURL=chunk-43FJOLKM.cjs.map
|
|
108
|
-
//# sourceMappingURL=chunk-43FJOLKM.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/processors/working-memory-state/processor.ts"],"names":["createHash","structuredPatch"],"mappings":"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","file":"chunk-43FJOLKM.cjs","sourcesContent":["/**\n * WorkingMemoryStateProcessor\n *\n * Experimental: delivers working memory to the model as a state signal instead\n * of folding it into the system message. Storage and the `setWorkingMemory`\n * tool are unchanged — this processor only changes the delivery path.\n *\n * Pattern matches `BrowserContextProcessor` in `@mastra/core/browser`:\n * - `stateId` namespaces the state lane on the thread.\n * - `cacheKey` is derived from the rendered payload so dedup is automatic.\n * - `contextWindow.hasSnapshot` re-injection ensures the model still sees the\n * current snapshot after older messages drop out of the window.\n *\n * Delta emission (markdown mode only): when a prior snapshot exists in the\n * context window, the processor emits a unified-diff delta against that\n * snapshot's contents. Schema mode and the snapshot fallback always emit a\n * full snapshot.\n *\n * @example\n * ```ts\n * new Memory({\n * options: {\n * workingMemory: {\n * enabled: true,\n * template: '...',\n * useStateSignals: true, // auto-attaches this processor\n * },\n * },\n * });\n * ```\n */\n\nimport { createHash } from 'node:crypto';\n\nimport type { MastraMemory, MemoryConfigInternal, WorkingMemoryTemplate } from '@mastra/core/memory';\nimport type {\n ComputeStateSignalArgs,\n ComputeStateSignalResult,\n Processor,\n ProcessorActiveStateSignal,\n} from '@mastra/core/processors';\nimport { structuredPatch } from 'diff';\n\nexport const WORKING_MEMORY_STATE_ID = 'working-memory';\nexport const WORKING_MEMORY_STATE_PROCESSOR_ID = 'working-memory-state';\n\nexport class WorkingMemoryStateProcessor implements Processor<typeof WORKING_MEMORY_STATE_PROCESSOR_ID> {\n readonly id = WORKING_MEMORY_STATE_PROCESSOR_ID;\n readonly stateId = WORKING_MEMORY_STATE_ID;\n\n constructor(\n private readonly memory: MastraMemory,\n private readonly memoryConfig?: MemoryConfigInternal,\n ) {}\n\n async computeStateSignal(args: ComputeStateSignalArgs): Promise<ComputeStateSignalResult> {\n const template = await this.memory.getWorkingMemoryTemplate({ memoryConfig: this.memoryConfig });\n if (!template) return;\n\n const data = await this.memory.getWorkingMemory({\n threadId: args.threadId,\n resourceId: args.resourceId,\n memoryConfig: this.memoryConfig,\n });\n\n // Nothing stored yet — no state to broadcast. The setWorkingMemory tool\n // description tells the model the expected shape; the signal carries state.\n const contents = data?.trim();\n if (!contents) return;\n\n const cacheKey = stableWorkingMemoryCacheKey({ format: template.format, data: contents });\n const shouldMakeSnapshot = !args.contextWindow.hasSnapshot;\n if (args.tracking?.currentCacheKey === cacheKey && !shouldMakeSnapshot) return;\n\n const mergedConfig = this.memory.getMergedThreadConfig(this.memoryConfig);\n const scope = mergedConfig.workingMemory?.scope ?? 'resource';\n\n const deltaCandidate =\n template.format === 'markdown' && !shouldMakeSnapshot\n ? buildMarkdownDelta({\n lastSnapshot: args.lastSnapshot,\n deltasSinceSnapshot: args.deltasSinceSnapshot,\n nextContents: contents,\n })\n : undefined;\n\n if (deltaCandidate) {\n return {\n id: WORKING_MEMORY_STATE_ID,\n mode: 'delta',\n cacheKey,\n tagName: 'working-memory',\n contents: deltaCandidate.contents,\n delta: deltaCandidate.contents,\n // Stash the full post-edit text on the signal so the next turn can\n // diff against the most recently emitted state instead of the older\n // snapshot. Invisible to the model.\n value: contents,\n attributes: {\n format: template.format,\n scope,\n patch: 'unified-diff',\n },\n };\n }\n\n return {\n id: WORKING_MEMORY_STATE_ID,\n mode: 'snapshot',\n cacheKey,\n tagName: 'working-memory',\n contents,\n // Mirror contents in value so the first delta after a snapshot has a\n // typed prior-state to diff against without falling back to contents.\n value: contents,\n attributes: {\n format: template.format,\n scope,\n },\n };\n }\n}\n\n/**\n * Stable cache key for the rendered working memory payload. Returns a SHA-256\n * digest so dedup metadata stays compact regardless of payload size (working\n * memory blobs can grow arbitrarily long).\n */\nexport function stableWorkingMemoryCacheKey(input: {\n format: WorkingMemoryTemplate['format'];\n data: string | null;\n}): string {\n const hash = createHash('sha256');\n hash.update(input.format);\n hash.update('\\0');\n hash.update(input.data ?? '');\n return `sha256:${hash.digest('hex')}`;\n}\n\n/**\n * Build a unified-diff delta against the most recently emitted state. Prefers\n * the latest delta's `value` (the post-edit full text) when available, falling\n * back to the snapshot's `value` and finally the snapshot's `contents`. This\n * keeps deltas incremental (B→C) instead of cumulative against a stale\n * snapshot (A→C), which matters when many small edits land between snapshots.\n *\n * Returns undefined when:\n * - there's no prior state to diff against\n * - the prior state isn't a plain string (multimodal signal)\n *\n * In either case the caller falls back to emitting a full snapshot.\n */\nfunction buildMarkdownDelta(args: {\n lastSnapshot?: ProcessorActiveStateSignal;\n deltasSinceSnapshot: ProcessorActiveStateSignal[];\n nextContents: string;\n}): { contents: string } | undefined {\n const { lastSnapshot, deltasSinceSnapshot, nextContents } = args;\n\n // `value` is stored on the persisted signal's metadata (see applyStateSignal\n // in @mastra/core/agent/state-signals). Read from there to recover the\n // post-edit full text from the most recently emitted state.\n const latestDelta = deltasSinceSnapshot.at(-1);\n const prior =\n pickStringValue(readSignalValue(latestDelta)) ??\n pickStringValue(readSignalValue(lastSnapshot)) ??\n (typeof lastSnapshot?.contents === 'string' ? lastSnapshot.contents : undefined);\n ('');\n if (!prior) return;\n\n const patch = renderHunksOnly(prior, nextContents);\n\n return { contents: patch };\n}\n\nfunction pickStringValue(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readSignalValue(signal: ProcessorActiveStateSignal | undefined): unknown {\n return (signal?.metadata as { value?: unknown } | undefined)?.value;\n}\n\n/**\n * Render a unified-diff-style patch body containing only `@@` hunks and their\n * lines — dropping the filename preamble (`Index:` / `===` / `---` / `+++`)\n * that `createPatch` emits and the `\` trailer.\n * The preamble exists for tooling like `patch -p1` to know which file to\n * apply to; we only ever diff a single working-memory blob. The newline\n * trailer is semantically meaningless to the model and adds noise to the\n * state signal.\n */\nfunction renderHunksOnly(prior: string, next: string): string {\n const { hunks } = structuredPatch('', '', prior, next, '', '', { context: 0 });\n return hunks\n .map(hunk => {\n const header = `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`;\n const lines = hunk.lines.filter(line => !line.startsWith('\\\'));\n return [header, ...lines].join('\\n');\n })\n .join('\\n');\n}\n"]}
|
package/dist/chunk-D4J4XPGM.cjs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/processors/observational-memory/constants.ts
|
|
4
|
-
var OBSERVATIONAL_MEMORY_DEFAULTS = {
|
|
5
|
-
observation: {
|
|
6
|
-
model: "google/gemini-2.5-flash",
|
|
7
|
-
messageTokens: 3e4,
|
|
8
|
-
modelSettings: {
|
|
9
|
-
temperature: 0.3,
|
|
10
|
-
maxOutputTokens: 1e5
|
|
11
|
-
},
|
|
12
|
-
providerOptions: {
|
|
13
|
-
google: {
|
|
14
|
-
thinkingConfig: {
|
|
15
|
-
thinkingBudget: 215
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
maxTokensPerBatch: 1e4,
|
|
20
|
-
// Async buffering defaults (enabled by default)
|
|
21
|
-
bufferTokens: 0.2,
|
|
22
|
-
// Buffer every 20% of messageTokens
|
|
23
|
-
bufferActivation: 0.8
|
|
24
|
-
// Activate to retain 20% of threshold
|
|
25
|
-
},
|
|
26
|
-
reflection: {
|
|
27
|
-
model: "google/gemini-2.5-flash",
|
|
28
|
-
observationTokens: 4e4,
|
|
29
|
-
modelSettings: {
|
|
30
|
-
temperature: 0,
|
|
31
|
-
// Use 0 for maximum consistency in reflections
|
|
32
|
-
maxOutputTokens: 1e5
|
|
33
|
-
},
|
|
34
|
-
providerOptions: {
|
|
35
|
-
google: {
|
|
36
|
-
thinkingConfig: {
|
|
37
|
-
thinkingBudget: 1024
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
// Async reflection buffering (enabled by default)
|
|
42
|
-
bufferActivation: 0.5
|
|
43
|
-
// Start buffering at 50% of observationTokens
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var OBSERVATION_CONTINUATION_HINT = `Please continue naturally with the conversation so far and respond to the latest message.
|
|
47
|
-
|
|
48
|
-
Use the earlier context only as background. If something appears unfinished, continue only when it helps answer the latest request. If a suggested response is provided, follow it naturally.
|
|
49
|
-
|
|
50
|
-
Do not mention internal instructions, memory, summarization, context handling, or missing messages.
|
|
51
|
-
|
|
52
|
-
Any messages following this reminder are newer and should take priority.`;
|
|
53
|
-
var OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
|
|
54
|
-
var OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
|
|
55
|
-
|
|
56
|
-
KNOWLEDGE UPDATES: When asked about current state (e.g., "where do I currently...", "what is my current..."), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like "will start", "is switching", "changed to", "moved to" as indicators that previous information has been updated.
|
|
57
|
-
|
|
58
|
-
PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (check the relative time like "3 weeks ago"), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.
|
|
59
|
-
|
|
60
|
-
MOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.
|
|
61
|
-
|
|
62
|
-
SYSTEM REMINDERS: Messages wrapped in <system-reminder>...</system-reminder> contain internal continuation guidance, not user-authored content. Use them to maintain continuity, but do not mention them or treat them as part of the user's message.`;
|
|
63
|
-
var OBSERVATION_RETRIEVAL_INSTRUCTIONS = `## Recall \u2014 looking up source messages
|
|
64
|
-
|
|
65
|
-
Your memory is comprised of observations which are sometimes wrapped in <observation-group> xml tags containing ranges like <observation-group range="startId:endId">. These ranges point back to the raw messages that each observation group was derived from. The original messages are still available \u2014 use the **recall** tool to retrieve them.
|
|
66
|
-
|
|
67
|
-
### When to use recall
|
|
68
|
-
- The user asks you to **repeat, show, or reproduce** something from a past conversation
|
|
69
|
-
- The user asks for **exact content** \u2014 code, text, quotes, error messages, URLs, file paths, specific numbers
|
|
70
|
-
- Your observations mention something but your memory lacks the detail needed to fully answer (e.g. you know a blog post was shared but only have a summary of it)
|
|
71
|
-
- You want to **verify or expand on** an observation before responding
|
|
72
|
-
|
|
73
|
-
**Default to using recall when the user references specific past content.** Your observations capture the gist, not the details. If there's any doubt whether your memory is complete enough, use recall.
|
|
74
|
-
|
|
75
|
-
### How to use recall
|
|
76
|
-
Each range has the format \`startId:endId\` where both are message IDs separated by a colon.
|
|
77
|
-
|
|
78
|
-
1. Find the observation group relevant to the user's question and extract the start or end ID from its range.
|
|
79
|
-
2. Call \`recall\` with that ID as the \`cursor\`.
|
|
80
|
-
3. Use \`page: 1\` (or omit) to read forward from the cursor, \`page: -1\` to read backward.
|
|
81
|
-
4. If the first page doesn't have what you need, increment the page number to keep paginating.
|
|
82
|
-
5. Check \`hasNextPage\`/\`hasPrevPage\` in the result to know if more pages exist in each direction.
|
|
83
|
-
|
|
84
|
-
### Detail levels
|
|
85
|
-
By default recall returns **low** detail: truncated text and tool names only. Each message shows its ID and each part has a positional index like \`[p0]\`, \`[p1]\`, etc.
|
|
86
|
-
|
|
87
|
-
- Use \`detail: "high"\` to get full message content including tool arguments and results. This will only return the high detail version of a single message part at a time.
|
|
88
|
-
- Use \`partIndex\` with a cursor to fetch a single part at full detail \u2014 for example, to read one specific tool result or code block without loading every part.
|
|
89
|
-
|
|
90
|
-
If the result says \`truncated: true\`, the output was cut to fit the token budget. You can paginate or use \`partIndex\` to target specific content.
|
|
91
|
-
|
|
92
|
-
### Following up on truncated parts
|
|
93
|
-
Low-detail results may include truncation hints like:
|
|
94
|
-
\`[truncated \u2014 call recall cursor="..." partIndex=N detail="high" for full content]\`
|
|
95
|
-
|
|
96
|
-
**When you see these hints and need the full content, make the exact call described in the hint.** This is the normal workflow: first recall at low detail to scan, then drill into specific parts at high detail. Do not stop at the low-detail result if the user asked for exact content.
|
|
97
|
-
|
|
98
|
-
### When recall is NOT needed
|
|
99
|
-
- The user is asking for a high-level summary and your observations already cover it
|
|
100
|
-
- The question is about general preferences or facts that don't require source text
|
|
101
|
-
- There is no relevant range in your observations for the topic
|
|
102
|
-
|
|
103
|
-
Observation groups with range IDs and your recall tool allows you to think back and remember details you're fuzzy on.`;
|
|
104
|
-
|
|
105
|
-
exports.OBSERVATIONAL_MEMORY_DEFAULTS = OBSERVATIONAL_MEMORY_DEFAULTS;
|
|
106
|
-
exports.OBSERVATION_CONTEXT_INSTRUCTIONS = OBSERVATION_CONTEXT_INSTRUCTIONS;
|
|
107
|
-
exports.OBSERVATION_CONTEXT_PROMPT = OBSERVATION_CONTEXT_PROMPT;
|
|
108
|
-
exports.OBSERVATION_CONTINUATION_HINT = OBSERVATION_CONTINUATION_HINT;
|
|
109
|
-
exports.OBSERVATION_RETRIEVAL_INSTRUCTIONS = OBSERVATION_RETRIEVAL_INSTRUCTIONS;
|
|
110
|
-
//# sourceMappingURL=chunk-D4J4XPGM.cjs.map
|
|
111
|
-
//# sourceMappingURL=chunk-D4J4XPGM.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/processors/observational-memory/constants.ts"],"names":[],"mappings":";;;AAGO,IAAM,6BAAA,GAAgC;AAAA,EAC3C,WAAA,EAAa;AAAA,IACX,KAAA,EAAO,yBAAA;AAAA,IACP,aAAA,EAAe,GAAA;AAAA,IACf,aAAA,EAAe;AAAA,MACb,WAAA,EAAa,GAAA;AAAA,MACb,eAAA,EAAiB;AAAA,KACnB;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,MAAA,EAAQ;AAAA,QACN,cAAA,EAAgB;AAAA,UACd,cAAA,EAAgB;AAAA;AAClB;AACF,KACF;AAAA,IACA,iBAAA,EAAmB,GAAA;AAAA;AAAA,IAEnB,YAAA,EAAc,GAAA;AAAA;AAAA,IACd,gBAAA,EAAkB;AAAA;AAAA,GACpB;AAAA,EACA,UAAA,EAAY;AAAA,IACV,KAAA,EAAO,yBAAA;AAAA,IACP,iBAAA,EAAmB,GAAA;AAAA,IACnB,aAAA,EAAe;AAAA,MACb,WAAA,EAAa,CAAA;AAAA;AAAA,MACb,eAAA,EAAiB;AAAA,KACnB;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,MAAA,EAAQ;AAAA,QACN,cAAA,EAAgB;AAAA,UACd,cAAA,EAAgB;AAAA;AAClB;AACF,KACF;AAAA;AAAA,IAEA,gBAAA,EAAkB;AAAA;AAAA;AAEtB;AAOO,IAAM,6BAAA,GAAgC,CAAA;;AAAA;;AAAA;;AAAA,wEAAA;AAatC,IAAM,0BAAA,GAA6B,CAAA,2FAAA;AAMnC,IAAM,gCAAA,GAAmC,CAAA;;AAAA;;AAAA;;AAAA;;AAAA,qPAAA;AAczC,IAAM,kCAAA,GAAqC,CAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA,qHAAA","file":"chunk-D4J4XPGM.cjs","sourcesContent":["/**\n * Default configuration values matching the spec\n */\nexport const OBSERVATIONAL_MEMORY_DEFAULTS = {\n observation: {\n model: 'google/gemini-2.5-flash',\n messageTokens: 30_000,\n modelSettings: {\n temperature: 0.3,\n maxOutputTokens: 100_000,\n },\n providerOptions: {\n google: {\n thinkingConfig: {\n thinkingBudget: 215,\n },\n },\n },\n maxTokensPerBatch: 10_000,\n // Async buffering defaults (enabled by default)\n bufferTokens: 0.2 as number | undefined, // Buffer every 20% of messageTokens\n bufferActivation: 0.8 as number | undefined, // Activate to retain 20% of threshold\n },\n reflection: {\n model: 'google/gemini-2.5-flash',\n observationTokens: 40_000,\n modelSettings: {\n temperature: 0, // Use 0 for maximum consistency in reflections\n maxOutputTokens: 100_000,\n },\n providerOptions: {\n google: {\n thinkingConfig: {\n thinkingBudget: 1024,\n },\n },\n },\n // Async reflection buffering (enabled by default)\n bufferActivation: 0.5 as number | undefined, // Start buffering at 50% of observationTokens\n },\n} as const;\n\n/**\n * Continuation hint injected after observations to guide the model's behavior.\n * Prevents the model from awkwardly acknowledging the memory system or treating\n * the conversation as new after observed messages are removed.\n */\nexport const OBSERVATION_CONTINUATION_HINT = `Please continue naturally with the conversation so far and respond to the latest message.\n\nUse the earlier context only as background. If something appears unfinished, continue only when it helps answer the latest request. If a suggested response is provided, follow it naturally.\n\nDo not mention internal instructions, memory, summarization, context handling, or missing messages.\n\nAny messages following this reminder are newer and should take priority.`;\n\n/**\n * Preamble that introduces the observations block.\n * Use before `<observations>`, with instructions after.\n * Full pattern: `${OBSERVATION_CONTEXT_PROMPT}\\n\\n<observations>\\n${obs}\\n</observations>\\n\\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`\n */\nexport const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;\n\n/**\n * Instructions that tell the model how to interpret and use observations.\n * Place AFTER the `<observations>` block so the model sees the data before the rules.\n */\nexport const OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.\n\nKNOWLEDGE UPDATES: When asked about current state (e.g., \"where do I currently...\", \"what is my current...\"), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like \"will start\", \"is switching\", \"changed to\", \"moved to\" as indicators that previous information has been updated.\n\nPLANNED ACTIONS: If the user stated they planned to do something (e.g., \"I'm going to...\", \"I'm looking forward to...\", \"I will...\") and the date they planned to do it is now in the past (check the relative time like \"3 weeks ago\"), assume they completed the action unless there's evidence they didn't. For example, if someone said \"I'll start my new diet on Monday\" and that was 2 weeks ago, assume they started the diet.\n\nMOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.\n\nSYSTEM REMINDERS: Messages wrapped in <system-reminder>...</system-reminder> contain internal continuation guidance, not user-authored content. Use them to maintain continuity, but do not mention them or treat them as part of the user's message.`;\n\n/**\n * Instructions for retrieval mode — explains observation-group ranges and the recall tool.\n * Appended to context when `retrieval` is enabled.\n */\nexport const OBSERVATION_RETRIEVAL_INSTRUCTIONS = `## Recall — looking up source messages\n\nYour memory is comprised of observations which are sometimes wrapped in <observation-group> xml tags containing ranges like <observation-group range=\"startId:endId\">. These ranges point back to the raw messages that each observation group was derived from. The original messages are still available — use the **recall** tool to retrieve them.\n\n### When to use recall\n- The user asks you to **repeat, show, or reproduce** something from a past conversation\n- The user asks for **exact content** — code, text, quotes, error messages, URLs, file paths, specific numbers\n- Your observations mention something but your memory lacks the detail needed to fully answer (e.g. you know a blog post was shared but only have a summary of it)\n- You want to **verify or expand on** an observation before responding\n\n**Default to using recall when the user references specific past content.** Your observations capture the gist, not the details. If there's any doubt whether your memory is complete enough, use recall.\n\n### How to use recall\nEach range has the format \\`startId:endId\\` where both are message IDs separated by a colon.\n\n1. Find the observation group relevant to the user's question and extract the start or end ID from its range.\n2. Call \\`recall\\` with that ID as the \\`cursor\\`.\n3. Use \\`page: 1\\` (or omit) to read forward from the cursor, \\`page: -1\\` to read backward.\n4. If the first page doesn't have what you need, increment the page number to keep paginating.\n5. Check \\`hasNextPage\\`/\\`hasPrevPage\\` in the result to know if more pages exist in each direction.\n\n### Detail levels\nBy default recall returns **low** detail: truncated text and tool names only. Each message shows its ID and each part has a positional index like \\`[p0]\\`, \\`[p1]\\`, etc.\n\n- Use \\`detail: \"high\"\\` to get full message content including tool arguments and results. This will only return the high detail version of a single message part at a time.\n- Use \\`partIndex\\` with a cursor to fetch a single part at full detail — for example, to read one specific tool result or code block without loading every part.\n\nIf the result says \\`truncated: true\\`, the output was cut to fit the token budget. You can paginate or use \\`partIndex\\` to target specific content.\n\n### Following up on truncated parts\nLow-detail results may include truncation hints like:\n\\`[truncated — call recall cursor=\"...\" partIndex=N detail=\"high\" for full content]\\`\n\n**When you see these hints and need the full content, make the exact call described in the hint.** This is the normal workflow: first recall at low detail to scan, then drill into specific parts at high detail. Do not stop at the low-detail result if the user asked for exact content.\n\n### When recall is NOT needed\n- The user is asking for a high-level summary and your observations already cover it\n- The question is about general preferences or facts that don't require source text\n- There is no relevant range in your observations for the topic\n\nObservation groups with range IDs and your recall tool allows you to think back and remember details you're fuzzy on.`;\n"]}
|
package/dist/chunk-EGRHWZRV.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-EGRHWZRV.js"}
|
package/dist/chunk-LSJJAJAF.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// src/processors/observational-memory/constants.ts
|
|
2
|
-
var OBSERVATIONAL_MEMORY_DEFAULTS = {
|
|
3
|
-
observation: {
|
|
4
|
-
model: "google/gemini-2.5-flash",
|
|
5
|
-
messageTokens: 3e4,
|
|
6
|
-
modelSettings: {
|
|
7
|
-
temperature: 0.3,
|
|
8
|
-
maxOutputTokens: 1e5
|
|
9
|
-
},
|
|
10
|
-
providerOptions: {
|
|
11
|
-
google: {
|
|
12
|
-
thinkingConfig: {
|
|
13
|
-
thinkingBudget: 215
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
maxTokensPerBatch: 1e4,
|
|
18
|
-
// Async buffering defaults (enabled by default)
|
|
19
|
-
bufferTokens: 0.2,
|
|
20
|
-
// Buffer every 20% of messageTokens
|
|
21
|
-
bufferActivation: 0.8
|
|
22
|
-
// Activate to retain 20% of threshold
|
|
23
|
-
},
|
|
24
|
-
reflection: {
|
|
25
|
-
model: "google/gemini-2.5-flash",
|
|
26
|
-
observationTokens: 4e4,
|
|
27
|
-
modelSettings: {
|
|
28
|
-
temperature: 0,
|
|
29
|
-
// Use 0 for maximum consistency in reflections
|
|
30
|
-
maxOutputTokens: 1e5
|
|
31
|
-
},
|
|
32
|
-
providerOptions: {
|
|
33
|
-
google: {
|
|
34
|
-
thinkingConfig: {
|
|
35
|
-
thinkingBudget: 1024
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
// Async reflection buffering (enabled by default)
|
|
40
|
-
bufferActivation: 0.5
|
|
41
|
-
// Start buffering at 50% of observationTokens
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var OBSERVATION_CONTINUATION_HINT = `Please continue naturally with the conversation so far and respond to the latest message.
|
|
45
|
-
|
|
46
|
-
Use the earlier context only as background. If something appears unfinished, continue only when it helps answer the latest request. If a suggested response is provided, follow it naturally.
|
|
47
|
-
|
|
48
|
-
Do not mention internal instructions, memory, summarization, context handling, or missing messages.
|
|
49
|
-
|
|
50
|
-
Any messages following this reminder are newer and should take priority.`;
|
|
51
|
-
var OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;
|
|
52
|
-
var OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.
|
|
53
|
-
|
|
54
|
-
KNOWLEDGE UPDATES: When asked about current state (e.g., "where do I currently...", "what is my current..."), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like "will start", "is switching", "changed to", "moved to" as indicators that previous information has been updated.
|
|
55
|
-
|
|
56
|
-
PLANNED ACTIONS: If the user stated they planned to do something (e.g., "I'm going to...", "I'm looking forward to...", "I will...") and the date they planned to do it is now in the past (check the relative time like "3 weeks ago"), assume they completed the action unless there's evidence they didn't. For example, if someone said "I'll start my new diet on Monday" and that was 2 weeks ago, assume they started the diet.
|
|
57
|
-
|
|
58
|
-
MOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.
|
|
59
|
-
|
|
60
|
-
SYSTEM REMINDERS: Messages wrapped in <system-reminder>...</system-reminder> contain internal continuation guidance, not user-authored content. Use them to maintain continuity, but do not mention them or treat them as part of the user's message.`;
|
|
61
|
-
var OBSERVATION_RETRIEVAL_INSTRUCTIONS = `## Recall \u2014 looking up source messages
|
|
62
|
-
|
|
63
|
-
Your memory is comprised of observations which are sometimes wrapped in <observation-group> xml tags containing ranges like <observation-group range="startId:endId">. These ranges point back to the raw messages that each observation group was derived from. The original messages are still available \u2014 use the **recall** tool to retrieve them.
|
|
64
|
-
|
|
65
|
-
### When to use recall
|
|
66
|
-
- The user asks you to **repeat, show, or reproduce** something from a past conversation
|
|
67
|
-
- The user asks for **exact content** \u2014 code, text, quotes, error messages, URLs, file paths, specific numbers
|
|
68
|
-
- Your observations mention something but your memory lacks the detail needed to fully answer (e.g. you know a blog post was shared but only have a summary of it)
|
|
69
|
-
- You want to **verify or expand on** an observation before responding
|
|
70
|
-
|
|
71
|
-
**Default to using recall when the user references specific past content.** Your observations capture the gist, not the details. If there's any doubt whether your memory is complete enough, use recall.
|
|
72
|
-
|
|
73
|
-
### How to use recall
|
|
74
|
-
Each range has the format \`startId:endId\` where both are message IDs separated by a colon.
|
|
75
|
-
|
|
76
|
-
1. Find the observation group relevant to the user's question and extract the start or end ID from its range.
|
|
77
|
-
2. Call \`recall\` with that ID as the \`cursor\`.
|
|
78
|
-
3. Use \`page: 1\` (or omit) to read forward from the cursor, \`page: -1\` to read backward.
|
|
79
|
-
4. If the first page doesn't have what you need, increment the page number to keep paginating.
|
|
80
|
-
5. Check \`hasNextPage\`/\`hasPrevPage\` in the result to know if more pages exist in each direction.
|
|
81
|
-
|
|
82
|
-
### Detail levels
|
|
83
|
-
By default recall returns **low** detail: truncated text and tool names only. Each message shows its ID and each part has a positional index like \`[p0]\`, \`[p1]\`, etc.
|
|
84
|
-
|
|
85
|
-
- Use \`detail: "high"\` to get full message content including tool arguments and results. This will only return the high detail version of a single message part at a time.
|
|
86
|
-
- Use \`partIndex\` with a cursor to fetch a single part at full detail \u2014 for example, to read one specific tool result or code block without loading every part.
|
|
87
|
-
|
|
88
|
-
If the result says \`truncated: true\`, the output was cut to fit the token budget. You can paginate or use \`partIndex\` to target specific content.
|
|
89
|
-
|
|
90
|
-
### Following up on truncated parts
|
|
91
|
-
Low-detail results may include truncation hints like:
|
|
92
|
-
\`[truncated \u2014 call recall cursor="..." partIndex=N detail="high" for full content]\`
|
|
93
|
-
|
|
94
|
-
**When you see these hints and need the full content, make the exact call described in the hint.** This is the normal workflow: first recall at low detail to scan, then drill into specific parts at high detail. Do not stop at the low-detail result if the user asked for exact content.
|
|
95
|
-
|
|
96
|
-
### When recall is NOT needed
|
|
97
|
-
- The user is asking for a high-level summary and your observations already cover it
|
|
98
|
-
- The question is about general preferences or facts that don't require source text
|
|
99
|
-
- There is no relevant range in your observations for the topic
|
|
100
|
-
|
|
101
|
-
Observation groups with range IDs and your recall tool allows you to think back and remember details you're fuzzy on.`;
|
|
102
|
-
|
|
103
|
-
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVATION_RETRIEVAL_INSTRUCTIONS };
|
|
104
|
-
//# sourceMappingURL=chunk-LSJJAJAF.js.map
|
|
105
|
-
//# sourceMappingURL=chunk-LSJJAJAF.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/processors/observational-memory/constants.ts"],"names":[],"mappings":";AAGO,IAAM,6BAAA,GAAgC;AAAA,EAC3C,WAAA,EAAa;AAAA,IACX,KAAA,EAAO,yBAAA;AAAA,IACP,aAAA,EAAe,GAAA;AAAA,IACf,aAAA,EAAe;AAAA,MACb,WAAA,EAAa,GAAA;AAAA,MACb,eAAA,EAAiB;AAAA,KACnB;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,MAAA,EAAQ;AAAA,QACN,cAAA,EAAgB;AAAA,UACd,cAAA,EAAgB;AAAA;AAClB;AACF,KACF;AAAA,IACA,iBAAA,EAAmB,GAAA;AAAA;AAAA,IAEnB,YAAA,EAAc,GAAA;AAAA;AAAA,IACd,gBAAA,EAAkB;AAAA;AAAA,GACpB;AAAA,EACA,UAAA,EAAY;AAAA,IACV,KAAA,EAAO,yBAAA;AAAA,IACP,iBAAA,EAAmB,GAAA;AAAA,IACnB,aAAA,EAAe;AAAA,MACb,WAAA,EAAa,CAAA;AAAA;AAAA,MACb,eAAA,EAAiB;AAAA,KACnB;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,MAAA,EAAQ;AAAA,QACN,cAAA,EAAgB;AAAA,UACd,cAAA,EAAgB;AAAA;AAClB;AACF,KACF;AAAA;AAAA,IAEA,gBAAA,EAAkB;AAAA;AAAA;AAEtB;AAOO,IAAM,6BAAA,GAAgC,CAAA;;AAAA;;AAAA;;AAAA,wEAAA;AAatC,IAAM,0BAAA,GAA6B,CAAA,2FAAA;AAMnC,IAAM,gCAAA,GAAmC,CAAA;;AAAA;;AAAA;;AAAA;;AAAA,qPAAA;AAczC,IAAM,kCAAA,GAAqC,CAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA,qHAAA","file":"chunk-LSJJAJAF.js","sourcesContent":["/**\n * Default configuration values matching the spec\n */\nexport const OBSERVATIONAL_MEMORY_DEFAULTS = {\n observation: {\n model: 'google/gemini-2.5-flash',\n messageTokens: 30_000,\n modelSettings: {\n temperature: 0.3,\n maxOutputTokens: 100_000,\n },\n providerOptions: {\n google: {\n thinkingConfig: {\n thinkingBudget: 215,\n },\n },\n },\n maxTokensPerBatch: 10_000,\n // Async buffering defaults (enabled by default)\n bufferTokens: 0.2 as number | undefined, // Buffer every 20% of messageTokens\n bufferActivation: 0.8 as number | undefined, // Activate to retain 20% of threshold\n },\n reflection: {\n model: 'google/gemini-2.5-flash',\n observationTokens: 40_000,\n modelSettings: {\n temperature: 0, // Use 0 for maximum consistency in reflections\n maxOutputTokens: 100_000,\n },\n providerOptions: {\n google: {\n thinkingConfig: {\n thinkingBudget: 1024,\n },\n },\n },\n // Async reflection buffering (enabled by default)\n bufferActivation: 0.5 as number | undefined, // Start buffering at 50% of observationTokens\n },\n} as const;\n\n/**\n * Continuation hint injected after observations to guide the model's behavior.\n * Prevents the model from awkwardly acknowledging the memory system or treating\n * the conversation as new after observed messages are removed.\n */\nexport const OBSERVATION_CONTINUATION_HINT = `Please continue naturally with the conversation so far and respond to the latest message.\n\nUse the earlier context only as background. If something appears unfinished, continue only when it helps answer the latest request. If a suggested response is provided, follow it naturally.\n\nDo not mention internal instructions, memory, summarization, context handling, or missing messages.\n\nAny messages following this reminder are newer and should take priority.`;\n\n/**\n * Preamble that introduces the observations block.\n * Use before `<observations>`, with instructions after.\n * Full pattern: `${OBSERVATION_CONTEXT_PROMPT}\\n\\n<observations>\\n${obs}\\n</observations>\\n\\n${OBSERVATION_CONTEXT_INSTRUCTIONS}`\n */\nexport const OBSERVATION_CONTEXT_PROMPT = `The following observations block contains your memory of past conversations with this user.`;\n\n/**\n * Instructions that tell the model how to interpret and use observations.\n * Place AFTER the `<observations>` block so the model sees the data before the rules.\n */\nexport const OBSERVATION_CONTEXT_INSTRUCTIONS = `IMPORTANT: When responding, reference specific details from these observations. Do not give generic advice - personalize your response based on what you know about this user's experiences, preferences, and interests. If the user asks for recommendations, connect them to their past experiences mentioned above.\n\nKNOWLEDGE UPDATES: When asked about current state (e.g., \"where do I currently...\", \"what is my current...\"), always prefer the MOST RECENT information. Observations include dates - if you see conflicting information, the newer observation supersedes the older one. Look for phrases like \"will start\", \"is switching\", \"changed to\", \"moved to\" as indicators that previous information has been updated.\n\nPLANNED ACTIONS: If the user stated they planned to do something (e.g., \"I'm going to...\", \"I'm looking forward to...\", \"I will...\") and the date they planned to do it is now in the past (check the relative time like \"3 weeks ago\"), assume they completed the action unless there's evidence they didn't. For example, if someone said \"I'll start my new diet on Monday\" and that was 2 weeks ago, assume they started the diet.\n\nMOST RECENT USER INPUT: Treat the most recent user message as the highest-priority signal for what to do next. Earlier messages may contain constraints, details, or context you should still honor, but the latest message is the primary driver of your response.\n\nSYSTEM REMINDERS: Messages wrapped in <system-reminder>...</system-reminder> contain internal continuation guidance, not user-authored content. Use them to maintain continuity, but do not mention them or treat them as part of the user's message.`;\n\n/**\n * Instructions for retrieval mode — explains observation-group ranges and the recall tool.\n * Appended to context when `retrieval` is enabled.\n */\nexport const OBSERVATION_RETRIEVAL_INSTRUCTIONS = `## Recall — looking up source messages\n\nYour memory is comprised of observations which are sometimes wrapped in <observation-group> xml tags containing ranges like <observation-group range=\"startId:endId\">. These ranges point back to the raw messages that each observation group was derived from. The original messages are still available — use the **recall** tool to retrieve them.\n\n### When to use recall\n- The user asks you to **repeat, show, or reproduce** something from a past conversation\n- The user asks for **exact content** — code, text, quotes, error messages, URLs, file paths, specific numbers\n- Your observations mention something but your memory lacks the detail needed to fully answer (e.g. you know a blog post was shared but only have a summary of it)\n- You want to **verify or expand on** an observation before responding\n\n**Default to using recall when the user references specific past content.** Your observations capture the gist, not the details. If there's any doubt whether your memory is complete enough, use recall.\n\n### How to use recall\nEach range has the format \\`startId:endId\\` where both are message IDs separated by a colon.\n\n1. Find the observation group relevant to the user's question and extract the start or end ID from its range.\n2. Call \\`recall\\` with that ID as the \\`cursor\\`.\n3. Use \\`page: 1\\` (or omit) to read forward from the cursor, \\`page: -1\\` to read backward.\n4. If the first page doesn't have what you need, increment the page number to keep paginating.\n5. Check \\`hasNextPage\\`/\\`hasPrevPage\\` in the result to know if more pages exist in each direction.\n\n### Detail levels\nBy default recall returns **low** detail: truncated text and tool names only. Each message shows its ID and each part has a positional index like \\`[p0]\\`, \\`[p1]\\`, etc.\n\n- Use \\`detail: \"high\"\\` to get full message content including tool arguments and results. This will only return the high detail version of a single message part at a time.\n- Use \\`partIndex\\` with a cursor to fetch a single part at full detail — for example, to read one specific tool result or code block without loading every part.\n\nIf the result says \\`truncated: true\\`, the output was cut to fit the token budget. You can paginate or use \\`partIndex\\` to target specific content.\n\n### Following up on truncated parts\nLow-detail results may include truncation hints like:\n\\`[truncated — call recall cursor=\"...\" partIndex=N detail=\"high\" for full content]\\`\n\n**When you see these hints and need the full content, make the exact call described in the hint.** This is the normal workflow: first recall at low detail to scan, then drill into specific parts at high detail. Do not stop at the low-detail result if the user asked for exact content.\n\n### When recall is NOT needed\n- The user is asking for a high-level summary and your observations already cover it\n- The question is about general preferences or facts that don't require source text\n- There is no relevant range in your observations for the topic\n\nObservation groups with range IDs and your recall tool allows you to think back and remember details you're fuzzy on.`;\n"]}
|
package/dist/chunk-NKIQRCOM.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-NKIQRCOM.cjs"}
|