@mastra/memory 1.20.1-alpha.1 → 1.20.2-alpha.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 +42 -0
- package/dist/chunk-43FJOLKM.cjs +108 -0
- package/dist/chunk-43FJOLKM.cjs.map +1 -0
- package/dist/{chunk-3Q3LOVQP.cjs → chunk-D4J4XPGM.cjs} +2 -9
- package/dist/chunk-D4J4XPGM.cjs.map +1 -0
- package/dist/{chunk-VKRZ3O5X.js → chunk-LSJJAJAF.js} +3 -9
- package/dist/chunk-LSJJAJAF.js.map +1 -0
- package/dist/{chunk-P4BYW7GY.cjs → chunk-PTCSCRB6.cjs} +27 -27
- package/dist/{chunk-P4BYW7GY.cjs.map → chunk-PTCSCRB6.cjs.map} +1 -1
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-Q7SFCCGT.cjs +11 -0
- package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
- package/dist/{chunk-KMJQDCCZ.js → chunk-SXFOZU7K.js} +3 -3
- package/dist/{chunk-KMJQDCCZ.js.map → chunk-SXFOZU7K.js.map} +1 -1
- package/dist/chunk-WCGXQIEN.js +103 -0
- package/dist/chunk-WCGXQIEN.js.map +1 -0
- package/dist/constants-DVRTNEGY.js +3 -0
- package/dist/{constants-SPS7MR4D.js.map → constants-DVRTNEGY.js.map} +1 -1
- package/dist/{constants-D6W7OWCP.cjs → constants-JS5SS7GS.cjs} +8 -8
- package/dist/{constants-D6W7OWCP.cjs.map → constants-JS5SS7GS.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +43 -30
- package/dist/docs/references/docs-agents-agent-approval.md +1 -1
- package/dist/docs/references/docs-agents-background-tasks.md +2 -2
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-agents-supervisor-agents.md +2 -2
- package/dist/docs/references/docs-memory-memory-processors.md +6 -6
- package/dist/docs/references/docs-memory-multi-user-threads.md +2 -2
- package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
- package/dist/docs/references/docs-memory-storage.md +2 -1
- package/dist/docs/references/docs-memory-working-memory.md +28 -1
- package/dist/docs/references/reference-memory-memory-class.md +3 -3
- package/dist/docs/references/reference-memory-observational-memory.md +4 -4
- package/dist/docs/references/reference-processors-token-limiter-processor.md +3 -3
- package/dist/docs/references/reference-storage-dsql.md +1 -1
- package/dist/docs/references/reference-storage-libsql.md +6 -0
- package/dist/docs/references/reference-storage-mongodb.md +4 -1
- package/dist/docs/references/reference-storage-postgresql.md +4 -1
- package/dist/docs/references/reference-storage-redis.md +1 -1
- package/dist/docs/references/reference-storage-upstash.md +1 -1
- package/dist/docs/references/reference-vectors-libsql.md +1 -1
- package/dist/docs/references/reference-vectors-mongodb.md +1 -1
- package/dist/docs/references/reference-vectors-pg.md +1 -1
- package/dist/docs/references/reference-vectors-upstash.md +1 -1
- package/dist/index.cjs +222 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +184 -72
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-TJFOX3YN.js → observational-memory-G52HNRHE.js} +4 -4
- package/dist/{observational-memory-TJFOX3YN.js.map → observational-memory-G52HNRHE.js.map} +1 -1
- package/dist/{observational-memory-CDLGZL67.cjs → observational-memory-SZF7GKTS.cjs} +31 -31
- package/dist/{observational-memory-CDLGZL67.cjs.map → observational-memory-SZF7GKTS.cjs.map} +1 -1
- package/dist/processors/index.cjs +29 -29
- package/dist/processors/index.js +2 -2
- package/dist/processors/observational-memory/index.d.ts +1 -1
- package/dist/processors/observational-memory/index.d.ts.map +1 -1
- package/dist/processors/working-memory-state/index.d.ts +2 -0
- package/dist/processors/working-memory-state/index.d.ts.map +1 -0
- package/dist/processors/working-memory-state/processor.d.ts +53 -0
- package/dist/processors/working-memory-state/processor.d.ts.map +1 -0
- package/dist/tools/working-memory.d.ts +22 -0
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/dist/working-memory-state-J7ASTNXX.js +3 -0
- package/dist/working-memory-state-J7ASTNXX.js.map +1 -0
- package/dist/working-memory-state-Y2SCKCNU.cjs +24 -0
- package/dist/working-memory-state-Y2SCKCNU.cjs.map +1 -0
- package/package.json +9 -8
- package/dist/chunk-3Q3LOVQP.cjs.map +0 -1
- package/dist/chunk-VKRZ3O5X.js.map +0 -1
- package/dist/constants-SPS7MR4D.js +0 -3
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { structuredPatch } from 'diff';
|
|
3
|
+
|
|
4
|
+
// src/processors/working-memory-state/processor.ts
|
|
5
|
+
var WORKING_MEMORY_STATE_ID = "working-memory";
|
|
6
|
+
var WORKING_MEMORY_STATE_PROCESSOR_ID = "working-memory-state";
|
|
7
|
+
var WorkingMemoryStateProcessor = class {
|
|
8
|
+
constructor(memory, memoryConfig) {
|
|
9
|
+
this.memory = memory;
|
|
10
|
+
this.memoryConfig = memoryConfig;
|
|
11
|
+
}
|
|
12
|
+
memory;
|
|
13
|
+
memoryConfig;
|
|
14
|
+
id = WORKING_MEMORY_STATE_PROCESSOR_ID;
|
|
15
|
+
stateId = WORKING_MEMORY_STATE_ID;
|
|
16
|
+
async computeStateSignal(args) {
|
|
17
|
+
const template = await this.memory.getWorkingMemoryTemplate({ memoryConfig: this.memoryConfig });
|
|
18
|
+
if (!template) return;
|
|
19
|
+
const data = await this.memory.getWorkingMemory({
|
|
20
|
+
threadId: args.threadId,
|
|
21
|
+
resourceId: args.resourceId,
|
|
22
|
+
memoryConfig: this.memoryConfig
|
|
23
|
+
});
|
|
24
|
+
const contents = data?.trim();
|
|
25
|
+
if (!contents) return;
|
|
26
|
+
const cacheKey = stableWorkingMemoryCacheKey({ format: template.format, data: contents });
|
|
27
|
+
const shouldMakeSnapshot = !args.contextWindow.hasSnapshot;
|
|
28
|
+
if (args.tracking?.currentCacheKey === cacheKey && !shouldMakeSnapshot) return;
|
|
29
|
+
const mergedConfig = this.memory.getMergedThreadConfig(this.memoryConfig);
|
|
30
|
+
const scope = mergedConfig.workingMemory?.scope ?? "resource";
|
|
31
|
+
const deltaCandidate = template.format === "markdown" && !shouldMakeSnapshot ? buildMarkdownDelta({
|
|
32
|
+
lastSnapshot: args.lastSnapshot,
|
|
33
|
+
deltasSinceSnapshot: args.deltasSinceSnapshot,
|
|
34
|
+
nextContents: contents
|
|
35
|
+
}) : void 0;
|
|
36
|
+
if (deltaCandidate) {
|
|
37
|
+
return {
|
|
38
|
+
id: WORKING_MEMORY_STATE_ID,
|
|
39
|
+
mode: "delta",
|
|
40
|
+
cacheKey,
|
|
41
|
+
tagName: "working-memory",
|
|
42
|
+
contents: deltaCandidate.contents,
|
|
43
|
+
delta: deltaCandidate.contents,
|
|
44
|
+
// Stash the full post-edit text on the signal so the next turn can
|
|
45
|
+
// diff against the most recently emitted state instead of the older
|
|
46
|
+
// snapshot. Invisible to the model.
|
|
47
|
+
value: contents,
|
|
48
|
+
attributes: {
|
|
49
|
+
format: template.format,
|
|
50
|
+
scope,
|
|
51
|
+
patch: "unified-diff"
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
id: WORKING_MEMORY_STATE_ID,
|
|
57
|
+
mode: "snapshot",
|
|
58
|
+
cacheKey,
|
|
59
|
+
tagName: "working-memory",
|
|
60
|
+
contents,
|
|
61
|
+
// Mirror contents in value so the first delta after a snapshot has a
|
|
62
|
+
// typed prior-state to diff against without falling back to contents.
|
|
63
|
+
value: contents,
|
|
64
|
+
attributes: {
|
|
65
|
+
format: template.format,
|
|
66
|
+
scope
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function stableWorkingMemoryCacheKey(input) {
|
|
72
|
+
const hash = createHash("sha256");
|
|
73
|
+
hash.update(input.format);
|
|
74
|
+
hash.update("\0");
|
|
75
|
+
hash.update(input.data ?? "");
|
|
76
|
+
return `sha256:${hash.digest("hex")}`;
|
|
77
|
+
}
|
|
78
|
+
function buildMarkdownDelta(args) {
|
|
79
|
+
const { lastSnapshot, deltasSinceSnapshot, nextContents } = args;
|
|
80
|
+
const latestDelta = deltasSinceSnapshot.at(-1);
|
|
81
|
+
const prior = pickStringValue(readSignalValue(latestDelta)) ?? pickStringValue(readSignalValue(lastSnapshot)) ?? (typeof lastSnapshot?.contents === "string" ? lastSnapshot.contents : void 0);
|
|
82
|
+
if (!prior) return;
|
|
83
|
+
const patch = renderHunksOnly(prior, nextContents);
|
|
84
|
+
return { contents: patch };
|
|
85
|
+
}
|
|
86
|
+
function pickStringValue(value) {
|
|
87
|
+
return typeof value === "string" ? value : void 0;
|
|
88
|
+
}
|
|
89
|
+
function readSignalValue(signal) {
|
|
90
|
+
return signal?.metadata?.value;
|
|
91
|
+
}
|
|
92
|
+
function renderHunksOnly(prior, next) {
|
|
93
|
+
const { hunks } = structuredPatch("", "", prior, next, "", "", { context: 0 });
|
|
94
|
+
return hunks.map((hunk) => {
|
|
95
|
+
const header = `@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`;
|
|
96
|
+
const lines = hunk.lines.filter((line) => !line.startsWith("\"));
|
|
97
|
+
return [header, ...lines].join("\n");
|
|
98
|
+
}).join("\n");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemoryStateProcessor, stableWorkingMemoryCacheKey };
|
|
102
|
+
//# sourceMappingURL=chunk-WCGXQIEN.js.map
|
|
103
|
+
//# sourceMappingURL=chunk-WCGXQIEN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/processors/working-memory-state/processor.ts"],"names":[],"mappings":";;;;AA2CO,IAAM,uBAAA,GAA0B;AAChC,I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8BAA8B,CAAC,CAAA;AACxF,IAAA,OAAO,CAAC,MAAA,EAAQ,GAAG,KAAK,CAAA,CAAE,KAAK,IAAI,CAAA;AAAA,EACrC,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AACd","file":"chunk-WCGXQIEN.js","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"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVATION_RETRIEVAL_INSTRUCTIONS } from './chunk-LSJJAJAF.js';
|
|
2
|
+
//# sourceMappingURL=constants-DVRTNEGY.js.map
|
|
3
|
+
//# sourceMappingURL=constants-DVRTNEGY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-DVRTNEGY.js"}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkD4J4XPGM_cjs = require('./chunk-D4J4XPGM.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "OBSERVATIONAL_MEMORY_DEFAULTS", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkD4J4XPGM_cjs.OBSERVATIONAL_MEMORY_DEFAULTS; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "OBSERVATION_CONTEXT_INSTRUCTIONS", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_CONTEXT_INSTRUCTIONS; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "OBSERVATION_CONTEXT_PROMPT", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_CONTEXT_PROMPT; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "OBSERVATION_CONTINUATION_HINT", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_CONTINUATION_HINT; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "OBSERVATION_RETRIEVAL_INSTRUCTIONS", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_RETRIEVAL_INSTRUCTIONS; }
|
|
26
26
|
});
|
|
27
|
-
//# sourceMappingURL=constants-
|
|
28
|
-
//# sourceMappingURL=constants-
|
|
27
|
+
//# sourceMappingURL=constants-JS5SS7GS.cjs.map
|
|
28
|
+
//# sourceMappingURL=constants-JS5SS7GS.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-JS5SS7GS.cjs"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,136 +1,149 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.20.
|
|
2
|
+
"version": "1.20.2-alpha.0",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"ModelByInputTokens": {
|
|
6
6
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
7
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
8
8
|
"line": 787
|
|
9
9
|
},
|
|
10
10
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
11
11
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
12
|
+
"implementation": "dist/chunk-SXFOZU7K.js"
|
|
13
13
|
},
|
|
14
14
|
"ObservationalMemory": {
|
|
15
15
|
"types": "dist/processors/index.d.ts",
|
|
16
|
-
"implementation": "dist/chunk-
|
|
16
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
17
17
|
"line": 7175
|
|
18
18
|
},
|
|
19
19
|
"ObservationalMemoryProcessor": {
|
|
20
20
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
21
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
22
22
|
"line": 9747
|
|
23
23
|
},
|
|
24
24
|
"TokenCounter": {
|
|
25
25
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
26
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
27
27
|
"line": 6506
|
|
28
28
|
},
|
|
29
29
|
"buildObserverPrompt": {
|
|
30
30
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
31
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
32
32
|
"line": 3774
|
|
33
33
|
},
|
|
34
34
|
"buildObserverSystemPrompt": {
|
|
35
35
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
36
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
37
37
|
"line": 3045
|
|
38
38
|
},
|
|
39
39
|
"combineObservationGroupRanges": {
|
|
40
40
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
41
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
42
42
|
"line": 879
|
|
43
43
|
},
|
|
44
44
|
"deriveObservationGroupProvenance": {
|
|
45
45
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
46
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
47
47
|
"line": 913
|
|
48
48
|
},
|
|
49
49
|
"extractCurrentTask": {
|
|
50
50
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
51
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
52
52
|
"line": 3888
|
|
53
53
|
},
|
|
54
54
|
"formatMessagesForObserver": {
|
|
55
55
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
56
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
57
57
|
"line": 3500
|
|
58
58
|
},
|
|
59
59
|
"getObservationsAsOf": {
|
|
60
60
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
61
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
62
62
|
"line": 9960
|
|
63
63
|
},
|
|
64
64
|
"hasCurrentTaskSection": {
|
|
65
65
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
66
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
67
67
|
"line": 3876
|
|
68
68
|
},
|
|
69
69
|
"injectAnchorIds": {
|
|
70
70
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
71
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
72
72
|
"line": 2593
|
|
73
73
|
},
|
|
74
74
|
"optimizeObservationsForContext": {
|
|
75
75
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
76
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
77
77
|
"line": 3899
|
|
78
78
|
},
|
|
79
79
|
"parseAnchorId": {
|
|
80
80
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
81
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
82
82
|
"line": 2566
|
|
83
83
|
},
|
|
84
84
|
"parseObservationGroups": {
|
|
85
85
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
86
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
87
87
|
"line": 848
|
|
88
88
|
},
|
|
89
89
|
"parseObserverOutput": {
|
|
90
90
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
91
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
92
92
|
"line": 3784
|
|
93
93
|
},
|
|
94
94
|
"reconcileObservationGroupsFromReflection": {
|
|
95
95
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
96
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
97
97
|
"line": 937
|
|
98
98
|
},
|
|
99
99
|
"renderObservationGroupsForReflection": {
|
|
100
100
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
101
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
102
102
|
"line": 893
|
|
103
103
|
},
|
|
104
104
|
"stripEphemeralAnchorIds": {
|
|
105
105
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
106
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
107
107
|
"line": 2623
|
|
108
108
|
},
|
|
109
109
|
"stripObservationGroups": {
|
|
110
110
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
111
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
112
112
|
"line": 870
|
|
113
113
|
},
|
|
114
114
|
"wrapInObservationGroup": {
|
|
115
115
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
116
|
+
"implementation": "dist/chunk-SXFOZU7K.js",
|
|
117
117
|
"line": 841
|
|
118
118
|
},
|
|
119
119
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
120
120
|
"types": "dist/processors/index.d.ts",
|
|
121
|
-
"implementation": "dist/chunk-
|
|
121
|
+
"implementation": "dist/chunk-LSJJAJAF.js"
|
|
122
122
|
},
|
|
123
123
|
"OBSERVATION_CONTEXT_INSTRUCTIONS": {
|
|
124
124
|
"types": "dist/processors/index.d.ts",
|
|
125
|
-
"implementation": "dist/chunk-
|
|
125
|
+
"implementation": "dist/chunk-LSJJAJAF.js"
|
|
126
126
|
},
|
|
127
127
|
"OBSERVATION_CONTEXT_PROMPT": {
|
|
128
128
|
"types": "dist/processors/index.d.ts",
|
|
129
|
-
"implementation": "dist/chunk-
|
|
129
|
+
"implementation": "dist/chunk-LSJJAJAF.js"
|
|
130
130
|
},
|
|
131
131
|
"OBSERVATION_CONTINUATION_HINT": {
|
|
132
132
|
"types": "dist/processors/index.d.ts",
|
|
133
|
-
"implementation": "dist/chunk-
|
|
133
|
+
"implementation": "dist/chunk-LSJJAJAF.js"
|
|
134
|
+
},
|
|
135
|
+
"WORKING_MEMORY_STATE_ID": {
|
|
136
|
+
"types": "dist/index.d.ts",
|
|
137
|
+
"implementation": "dist/chunk-WCGXQIEN.js"
|
|
138
|
+
},
|
|
139
|
+
"WORKING_MEMORY_STATE_PROCESSOR_ID": {
|
|
140
|
+
"types": "dist/index.d.ts",
|
|
141
|
+
"implementation": "dist/chunk-WCGXQIEN.js"
|
|
142
|
+
},
|
|
143
|
+
"WorkingMemoryStateProcessor": {
|
|
144
|
+
"types": "dist/index.d.ts",
|
|
145
|
+
"implementation": "dist/chunk-WCGXQIEN.js",
|
|
146
|
+
"line": 7
|
|
134
147
|
},
|
|
135
148
|
"MessageHistory": {
|
|
136
149
|
"types": "dist/index.d.ts",
|
|
@@ -149,8 +162,8 @@
|
|
|
149
162
|
"processors": {
|
|
150
163
|
"index": "dist/processors/index.js",
|
|
151
164
|
"chunks": [
|
|
152
|
-
"chunk-
|
|
153
|
-
"chunk-
|
|
165
|
+
"chunk-SXFOZU7K.js",
|
|
166
|
+
"chunk-LSJJAJAF.js"
|
|
154
167
|
]
|
|
155
168
|
}
|
|
156
169
|
}
|
|
@@ -412,7 +412,7 @@ const supervisorAgent = new Agent({
|
|
|
412
412
|
name: 'Supervisor Agent',
|
|
413
413
|
instructions: `You coordinate data retrieval tasks.
|
|
414
414
|
Delegate to data-agent for user lookups.`,
|
|
415
|
-
model: 'openai/gpt-5.
|
|
415
|
+
model: 'openai/gpt-5.5',
|
|
416
416
|
agents: { dataAgent },
|
|
417
417
|
memory: new Memory(),
|
|
418
418
|
})
|
|
@@ -80,7 +80,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
80
80
|
export const researcher = new Agent({
|
|
81
81
|
id: 'researcher',
|
|
82
82
|
instructions: 'You research topics and answer questions.',
|
|
83
|
-
model: 'openai/gpt-5.
|
|
83
|
+
model: 'openai/gpt-5.5',
|
|
84
84
|
tools: { researchTool, summarizeTool },
|
|
85
85
|
backgroundTasks: {
|
|
86
86
|
tools: {
|
|
@@ -175,7 +175,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
175
175
|
const supervisor = new Agent({
|
|
176
176
|
id: 'supervisor',
|
|
177
177
|
instructions: 'Coordinate research and writing using the available agents.',
|
|
178
|
-
model: 'openai/gpt-5.
|
|
178
|
+
model: 'openai/gpt-5.5',
|
|
179
179
|
agents: { researchAgent, writingAgent },
|
|
180
180
|
backgroundTasks: {
|
|
181
181
|
tools: {
|
|
@@ -27,7 +27,7 @@ export const routingAgent = new Agent({
|
|
|
27
27
|
name: 'Routing Agent',
|
|
28
28
|
instructions: `
|
|
29
29
|
You are a network of writers and researchers. The user will ask you to research a topic. Always respond with a complete report—no bullet points. Write in full paragraphs, like a blog post. Do not answer with incomplete or uncertain information.`,
|
|
30
|
-
model: 'openai/gpt-5.
|
|
30
|
+
model: 'openai/gpt-5.5',
|
|
31
31
|
agents: {
|
|
32
32
|
researchAgent,
|
|
33
33
|
writingAgent,
|
|
@@ -41,7 +41,7 @@ const supervisor = new Agent({
|
|
|
41
41
|
id: 'supervisor',
|
|
42
42
|
instructions: `You coordinate research and writing using specialized agents.
|
|
43
43
|
Delegate to research-agent for facts, then writing-agent for content.`,
|
|
44
|
-
model: 'openai/gpt-5.
|
|
44
|
+
model: 'openai/gpt-5.5',
|
|
45
45
|
agents: { researchAgent, writingAgent },
|
|
46
46
|
memory: new Memory({
|
|
47
47
|
storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
|
|
@@ -326,7 +326,7 @@ Enable the [backgroundTasks manager](https://mastra.ai/reference/configuration)
|
|
|
326
326
|
const supervisor = new Agent({
|
|
327
327
|
id: 'supervisor',
|
|
328
328
|
instructions: 'Coordinate research and writing using the available agents.',
|
|
329
|
-
model: 'openai/gpt-5.
|
|
329
|
+
model: 'openai/gpt-5.5',
|
|
330
330
|
agents: { researchAgent, writingAgent },
|
|
331
331
|
backgroundTasks: {
|
|
332
332
|
tools: {
|
|
@@ -45,7 +45,7 @@ const agent = new Agent({
|
|
|
45
45
|
id: 'test-agent',
|
|
46
46
|
name: 'Test Agent',
|
|
47
47
|
instructions: 'You are a helpful assistant',
|
|
48
|
-
model: 'openai/gpt-5.
|
|
48
|
+
model: 'openai/gpt-5.5',
|
|
49
49
|
memory: new Memory({
|
|
50
50
|
storage: new LibSQLStore({
|
|
51
51
|
id: 'memory-store',
|
|
@@ -95,7 +95,7 @@ import { openai } from '@ai-sdk/openai'
|
|
|
95
95
|
const agent = new Agent({
|
|
96
96
|
name: 'semantic-agent',
|
|
97
97
|
instructions: 'You are a helpful assistant with semantic memory',
|
|
98
|
-
model: 'openai/gpt-5.
|
|
98
|
+
model: 'openai/gpt-5.5',
|
|
99
99
|
memory: new Memory({
|
|
100
100
|
storage: new LibSQLStore({
|
|
101
101
|
id: 'memory-store',
|
|
@@ -148,7 +148,7 @@ import { openai } from '@ai-sdk/openai'
|
|
|
148
148
|
const agent = new Agent({
|
|
149
149
|
name: 'working-memory-agent',
|
|
150
150
|
instructions: 'You are an assistant with working memory',
|
|
151
|
-
model: 'openai/gpt-5.
|
|
151
|
+
model: 'openai/gpt-5.5',
|
|
152
152
|
memory: new Memory({
|
|
153
153
|
storage: new LibSQLStore({
|
|
154
154
|
id: 'memory-store',
|
|
@@ -180,7 +180,7 @@ const customMessageHistory = new MessageHistory({
|
|
|
180
180
|
const agent = new Agent({
|
|
181
181
|
name: 'custom-memory-agent',
|
|
182
182
|
instructions: 'You are a helpful assistant',
|
|
183
|
-
model: 'openai/gpt-5.
|
|
183
|
+
model: 'openai/gpt-5.5',
|
|
184
184
|
memory: new Memory({
|
|
185
185
|
storage: new LibSQLStore({ id: 'memory-store', url: 'file:memory.db' }),
|
|
186
186
|
lastMessages: 10, // This would normally add MessageHistory(10)
|
|
@@ -250,7 +250,7 @@ const contentBlocker = {
|
|
|
250
250
|
const agent = new Agent({
|
|
251
251
|
name: 'safe-agent',
|
|
252
252
|
instructions: 'You are a helpful assistant',
|
|
253
|
-
model: 'openai/gpt-5.
|
|
253
|
+
model: 'openai/gpt-5.5',
|
|
254
254
|
memory: new Memory({ lastMessages: 10 }),
|
|
255
255
|
// Your guardrail runs BEFORE memory saves
|
|
256
256
|
outputProcessors: [contentBlocker],
|
|
@@ -289,7 +289,7 @@ const inputValidator = {
|
|
|
289
289
|
const agent = new Agent({
|
|
290
290
|
name: 'validated-agent',
|
|
291
291
|
instructions: 'You are a helpful assistant',
|
|
292
|
-
model: 'openai/gpt-5.
|
|
292
|
+
model: 'openai/gpt-5.5',
|
|
293
293
|
memory: new Memory({ lastMessages: 10 }),
|
|
294
294
|
// Your guardrail runs AFTER memory loads history
|
|
295
295
|
inputProcessors: [inputValidator],
|
|
@@ -65,7 +65,7 @@ const memory = new Memory({
|
|
|
65
65
|
export const collabAgent = new Agent({
|
|
66
66
|
id: 'collab',
|
|
67
67
|
name: 'CollabAgent',
|
|
68
|
-
model: '
|
|
68
|
+
model: 'openai/gpt-5-mini',
|
|
69
69
|
memory,
|
|
70
70
|
instructions: `
|
|
71
71
|
You are a collaborative document assistant. Multiple users talk to you in the SAME thread.
|
|
@@ -135,7 +135,7 @@ const memory = new Memory({
|
|
|
135
135
|
|
|
136
136
|
The model reads identity from the `<turn>` tag on the current message and from prior tagged messages brought back through `lastMessages`.
|
|
137
137
|
|
|
138
|
-
### With
|
|
138
|
+
### With Observational Memory (recommended)
|
|
139
139
|
|
|
140
140
|
[Observational Memory](https://mastra.ai/docs/memory/observational-memory) (OM) extracts per-user facts into a background log without burning the agent's tool budget. The default Observer model reads `<turn>` tags natively and produces named attribution like `Alice stated her favorite color is teal.` and `Bob asked for QA sign-off before publish.`
|
|
141
141
|
|
|
@@ -30,7 +30,7 @@ const agent = new Agent({
|
|
|
30
30
|
id: 'support-agent',
|
|
31
31
|
name: 'SupportAgent',
|
|
32
32
|
instructions: 'You are a helpful support agent.',
|
|
33
|
-
model: 'openai/gpt-5.
|
|
33
|
+
model: 'openai/gpt-5.5',
|
|
34
34
|
memory: new Memory({
|
|
35
35
|
storage: new LibSQLStore({
|
|
36
36
|
id: 'agent-storage',
|
|
@@ -41,6 +41,7 @@ Each provider page includes installation instructions, configuration parameters,
|
|
|
41
41
|
- [DynamoDB](https://mastra.ai/reference/storage/dynamodb)
|
|
42
42
|
- [LanceDB](https://mastra.ai/reference/storage/lance)
|
|
43
43
|
- [Microsoft SQL Server](https://mastra.ai/reference/storage/mssql)
|
|
44
|
+
- [Google Cloud Spanner](https://mastra.ai/reference/storage/spanner)
|
|
44
45
|
|
|
45
46
|
> **Tip:** libSQL is the easiest way to get started because it doesn’t require running a separate database server.
|
|
46
47
|
|
|
@@ -179,7 +180,7 @@ export const agent = new Agent({
|
|
|
179
180
|
memory: new Memory({
|
|
180
181
|
options: {
|
|
181
182
|
generateTitle: {
|
|
182
|
-
model: '
|
|
183
|
+
model: 'openai/gpt-5-mini',
|
|
183
184
|
instructions: 'Generate a 1 word title',
|
|
184
185
|
},
|
|
185
186
|
},
|
|
@@ -26,7 +26,7 @@ const agent = new Agent({
|
|
|
26
26
|
id: 'personal-assistant',
|
|
27
27
|
name: 'PersonalAssistant',
|
|
28
28
|
instructions: 'You are a helpful personal assistant.',
|
|
29
|
-
model: 'openai/gpt-5.
|
|
29
|
+
model: 'openai/gpt-5.5',
|
|
30
30
|
memory: new Memory({
|
|
31
31
|
options: {
|
|
32
32
|
workingMemory: {
|
|
@@ -393,6 +393,33 @@ const response = await agent.generate('What do you know about me?', {
|
|
|
393
393
|
})
|
|
394
394
|
```
|
|
395
395
|
|
|
396
|
+
## Opt in to state signals (experimental)
|
|
397
|
+
|
|
398
|
+
By default, working memory reaches the model as part of the system message. You can opt into delivering it as a [state signal](https://mastra.ai/docs/agents/signals) instead by setting `useStateSignals: true`:
|
|
399
|
+
|
|
400
|
+
```typescript
|
|
401
|
+
const memory = new Memory({
|
|
402
|
+
storage: new LibSQLStore({ url: 'file:./mastra.db' }),
|
|
403
|
+
options: {
|
|
404
|
+
workingMemory: {
|
|
405
|
+
enabled: true,
|
|
406
|
+
template: '# User\n- name:\n- location:',
|
|
407
|
+
useStateSignals: true, // experimental: deliver as state signal
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
})
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
What changes:
|
|
414
|
+
|
|
415
|
+
- **Storage is identical.** The same resource/thread `workingMemory` field is read and written.
|
|
416
|
+
- **The tool is the same shape, exposed under a new name.** Writes still flow through the same underlying tool; on this path it is registered as `setWorkingMemory` (instead of `updateWorkingMemory`). The rename keeps legacy strip filters from removing tool-call parts so they persist as a normal audit trail and the next model step picks the new value up automatically.
|
|
417
|
+
- **Delivery only.** Instead of folding into the system prompt, `Memory` auto-attaches a `WorkingMemoryStateProcessor` that emits the current working memory as a `state` signal with `stateId: 'working-memory'`.
|
|
418
|
+
|
|
419
|
+
You inherit the standard state-signal benefits: thread-scoped tracking metadata, `cacheKey` dedup so identical snapshots are only emitted once, and `contextWindow.hasSnapshot` re-injection when an older snapshot rolls out of the window.
|
|
420
|
+
|
|
421
|
+
The default (`useStateSignals: false`) keeps the existing system-message behavior unchanged. `useStateSignals` is not supported with template working memory `version: 'vnext'`.
|
|
422
|
+
|
|
396
423
|
## Examples
|
|
397
424
|
|
|
398
425
|
- [Working memory with template](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-template)
|
|
@@ -11,7 +11,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
11
11
|
export const agent = new Agent({
|
|
12
12
|
name: 'test-agent',
|
|
13
13
|
instructions: 'You are an agent with memory.',
|
|
14
|
-
model: 'openai/gpt-5.
|
|
14
|
+
model: 'openai/gpt-5.5',
|
|
15
15
|
memory: new Memory({
|
|
16
16
|
options: {
|
|
17
17
|
workingMemory: {
|
|
@@ -60,7 +60,7 @@ import { LibSQLStore, LibSQLVector } from '@mastra/libsql'
|
|
|
60
60
|
export const agent = new Agent({
|
|
61
61
|
name: 'test-agent',
|
|
62
62
|
instructions: 'You are an agent with memory.',
|
|
63
|
-
model: 'openai/gpt-5.
|
|
63
|
+
model: 'openai/gpt-5.5',
|
|
64
64
|
memory: new Memory({
|
|
65
65
|
storage: new LibSQLStore({
|
|
66
66
|
id: 'test-agent-storage',
|
|
@@ -97,7 +97,7 @@ import { PgStore, PgVector } from '@mastra/pg'
|
|
|
97
97
|
export const agent = new Agent({
|
|
98
98
|
name: 'pg-agent',
|
|
99
99
|
instructions: 'You are an agent with optimized PostgreSQL memory.',
|
|
100
|
-
model: 'openai/gpt-5.
|
|
100
|
+
model: 'openai/gpt-5.5',
|
|
101
101
|
memory: new Memory({
|
|
102
102
|
storage: new PgStore({
|
|
103
103
|
id: 'pg-agent-storage',
|
|
@@ -181,7 +181,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
181
181
|
export const agent = new Agent({
|
|
182
182
|
name: 'my-agent',
|
|
183
183
|
instructions: 'You are a helpful assistant.',
|
|
184
|
-
model: 'openai/gpt-5.
|
|
184
|
+
model: 'openai/gpt-5.5',
|
|
185
185
|
memory: new Memory({
|
|
186
186
|
options: {
|
|
187
187
|
observationalMemory: {
|
|
@@ -201,7 +201,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
201
201
|
export const agent = new Agent({
|
|
202
202
|
name: 'my-agent',
|
|
203
203
|
instructions: 'You are a helpful assistant.',
|
|
204
|
-
model: 'openai/gpt-5.
|
|
204
|
+
model: 'openai/gpt-5.5',
|
|
205
205
|
memory: new Memory({
|
|
206
206
|
options: {
|
|
207
207
|
observationalMemory: {
|
|
@@ -228,7 +228,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
228
228
|
export const agent = new Agent({
|
|
229
229
|
name: 'health-assistant',
|
|
230
230
|
instructions: 'You are a health and wellness assistant.',
|
|
231
|
-
model: 'openai/gpt-5.
|
|
231
|
+
model: 'openai/gpt-5.5',
|
|
232
232
|
memory: new Memory({
|
|
233
233
|
options: {
|
|
234
234
|
observationalMemory: {
|
|
@@ -677,7 +677,7 @@ const selector = new ModelByInputTokens({
|
|
|
677
677
|
upTo: {
|
|
678
678
|
10_000: 'google/gemini-2.5-flash', // Fast for small inputs
|
|
679
679
|
40_000: 'openai/gpt-5-mini', // Stronger for medium inputs
|
|
680
|
-
1_000_000: 'openai/gpt-5.
|
|
680
|
+
1_000_000: 'openai/gpt-5.5', // Most capable for large inputs
|
|
681
681
|
},
|
|
682
682
|
})
|
|
683
683
|
```
|