@mastra/memory 1.28.0 → 1.28.1-alpha.1
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 +20 -0
- package/LICENSE.md +6 -4
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-human-in-the-loop.md +2 -0
- package/dist/docs/references/docs-agents-networks.md +2 -0
- package/dist/docs/references/docs-evals-evals-with-memory.md +2 -0
- package/dist/docs/references/docs-guides-context-engineering.md +2 -0
- package/dist/docs/references/docs-harness-background-tasks.md +2 -0
- package/dist/docs/references/docs-harness-goals.md +2 -0
- package/dist/docs/references/docs-memory-memory-processors.md +2 -0
- package/dist/docs/references/docs-memory-message-history.md +2 -0
- package/dist/docs/references/docs-memory-multi-user-threads.md +2 -0
- package/dist/docs/references/docs-memory-observational-memory.md +2 -0
- package/dist/docs/references/docs-memory-overview.md +2 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +2 -0
- package/dist/docs/references/docs-memory-working-memory.md +2 -0
- package/dist/docs/references/docs-storage.md +2 -0
- package/dist/docs/references/docs-subagents.md +2 -0
- package/dist/docs/references/integrations-channels-github.md +2 -0
- package/dist/docs/references/integrations-databases-aurora-dsql.md +2 -0
- package/dist/docs/references/integrations-databases-dynamodb.md +2 -0
- package/dist/docs/references/integrations-databases-elasticsearch.md +2 -0
- package/dist/docs/references/integrations-databases-libsql.md +2 -0
- package/dist/docs/references/integrations-databases-mongodb.md +2 -0
- package/dist/docs/references/integrations-databases-oracledb.md +2 -0
- package/dist/docs/references/integrations-databases-postgresql.md +2 -0
- package/dist/docs/references/integrations-databases-redis.md +2 -0
- package/dist/docs/references/integrations-databases-upstash.md +2 -0
- package/dist/docs/references/integrations-databases-valkey.md +2 -0
- package/dist/docs/references/reference-core-getMemory.md +2 -0
- package/dist/docs/references/reference-core-listMemory.md +2 -0
- package/dist/docs/references/reference-file-based-agents-memory.md +2 -0
- package/dist/docs/references/reference-memory-clone-utilities.md +2 -0
- package/dist/docs/references/reference-memory-cloneThread.md +2 -0
- package/dist/docs/references/reference-memory-createThread.md +2 -0
- package/dist/docs/references/reference-memory-getThreadById.md +2 -0
- package/dist/docs/references/reference-memory-listThreads.md +2 -0
- package/dist/docs/references/reference-memory-memory-class.md +2 -0
- package/dist/docs/references/reference-memory-observational-memory.md +2 -0
- package/dist/docs/references/reference-memory-settled.md +2 -0
- package/dist/docs/references/reference-memory-summarizeConversation.md +2 -0
- package/dist/docs/references/reference-memory-summarizeThread.md +2 -0
- package/dist/docs/references/reference-migrations-agentnetwork.md +2 -0
- package/dist/docs/references/reference-migrations-upgrade-to-v1-memory.md +2 -0
- package/dist/docs/references/reference-processors-token-limiter-processor.md +2 -0
- package/dist/docs/references/reference-vectors-libsql.md +2 -0
- package/dist/docs/references/reference-vectors-mongodb.md +2 -0
- package/dist/docs/references/reference-vectors-oracledb.md +2 -0
- package/dist/docs/references/reference-vectors-pg.md +2 -0
- package/dist/docs/references/reference-vectors-upstash.md +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/subconscious/capture.d.ts.map +1 -1
- package/dist/processors/observational-memory/subconscious/curate.d.ts.map +1 -1
- package/dist/processors/observational-memory/subconscious/index.d.ts.map +1 -1
- package/dist/processors/observational-memory/subconscious/knowledge-write-tools.d.ts.map +1 -1
- package/dist/processors/observational-memory/subconscious/learn.d.ts.map +1 -1
- package/dist/processors/observational-memory/subconscious/semantic-index.d.ts.map +1 -1
- package/dist/{src-BATJenuZ.js → src-BNtoxIHL.js} +75 -15
- package/dist/src-BNtoxIHL.js.map +1 -0
- package/dist/{src-C7Ozl6Pf.cjs → src-Br56ncef.cjs} +74 -14
- package/dist/src-Br56ncef.cjs.map +1 -0
- package/package.json +7 -7
- package/dist/src-BATJenuZ.js.map +0 -1
- package/dist/src-C7Ozl6Pf.cjs.map +0 -1
|
@@ -227,7 +227,7 @@ let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
|
227
227
|
return (size = defaultSize) => {
|
|
228
228
|
let id = "";
|
|
229
229
|
let i = size | 0;
|
|
230
|
-
while (i--) id += alphabet[Math.random() * alphabet.length | 0];
|
|
230
|
+
while (i-- > 0) id += alphabet[Math.random() * alphabet.length | 0];
|
|
231
231
|
return id;
|
|
232
232
|
};
|
|
233
233
|
};
|
|
@@ -3734,7 +3734,7 @@ function trimStartOfStream() {
|
|
|
3734
3734
|
};
|
|
3735
3735
|
}
|
|
3736
3736
|
//#endregion
|
|
3737
|
-
//#region ../_vendored/ai_v5/dist/dist-
|
|
3737
|
+
//#region ../_vendored/ai_v5/dist/dist-Dqv4QeJJ.js
|
|
3738
3738
|
var marker$1$4 = "vercel.ai.error";
|
|
3739
3739
|
var symbol$1$3 = Symbol.for(marker$1$4);
|
|
3740
3740
|
var _a$1$3;
|
|
@@ -8623,7 +8623,7 @@ var object$1 = ({ schema: inputSchema }) => {
|
|
|
8623
8623
|
};
|
|
8624
8624
|
};
|
|
8625
8625
|
//#endregion
|
|
8626
|
-
//#region ../_vendored/ai_v6/dist/dist-
|
|
8626
|
+
//#region ../_vendored/ai_v6/dist/dist-Cx98_f-i.js
|
|
8627
8627
|
var marker$1 = "vercel.ai.error";
|
|
8628
8628
|
var symbol$1$1 = Symbol.for(marker$1);
|
|
8629
8629
|
var _a$1$1;
|
|
@@ -10776,7 +10776,7 @@ function withoutTrailingSlash(url) {
|
|
|
10776
10776
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
10777
10777
|
}
|
|
10778
10778
|
//#endregion
|
|
10779
|
-
//#region ../_vendored/ai_v6/dist/dist-
|
|
10779
|
+
//#region ../_vendored/ai_v6/dist/dist-pa8X6y1Z.js
|
|
10780
10780
|
function getContext() {
|
|
10781
10781
|
return { headers: {} };
|
|
10782
10782
|
}
|
|
@@ -15294,6 +15294,7 @@ Return nodes with short stable names, a freeform kind, and knowledge records nes
|
|
|
15294
15294
|
Use common kinds such as person, task, event, project, organization, or document when they fit.
|
|
15295
15295
|
Set node scope to the narrowest level where that identity and content should be shared. Omit it to use the configured default scope.
|
|
15296
15296
|
Knowledge records must be grounded in the conversation, concise, and written as prose. Do not infer unstated information.
|
|
15297
|
+
When the conversation states a canonical identifier or URL for an entity, preserve it verbatim in the record text.
|
|
15297
15298
|
Wrap every named node mentioned in record text in [[wikilinks]].
|
|
15298
15299
|
Set a record scope only when the conversation establishes where it applies. Use org for organization-wide records, resource for records shared across this resource's conversations, and thread for conversation-private records.
|
|
15299
15300
|
Omit scope when uncertain; omitted record scopes stay private to the current thread.
|
|
@@ -16165,7 +16166,7 @@ function createKnowledgeWriteTools(memory, options) {
|
|
|
16165
16166
|
}),
|
|
16166
16167
|
knowledge_update_node: (0, _mastra_core_tools.createTool)({
|
|
16167
16168
|
id: "knowledge_update_node",
|
|
16168
|
-
description: "Update a visible node name or kind using optimistic concurrency.",
|
|
16169
|
+
description: "Update a visible node name or kind using optimistic concurrency. Provide at least one of name or kind.",
|
|
16169
16170
|
inputSchema: {
|
|
16170
16171
|
type: "object",
|
|
16171
16172
|
properties: {
|
|
@@ -16187,11 +16188,11 @@ function createKnowledgeWriteTools(memory, options) {
|
|
|
16187
16188
|
}
|
|
16188
16189
|
},
|
|
16189
16190
|
required: ["node", "expectedVersion"],
|
|
16190
|
-
anyOf: [{ required: ["name"] }, { required: ["kind"] }],
|
|
16191
16191
|
additionalProperties: false
|
|
16192
16192
|
},
|
|
16193
16193
|
execute: async (input) => {
|
|
16194
16194
|
const value = input;
|
|
16195
|
+
if (value.name === void 0 && value.kind === void 0) throw new Error("knowledge_update_node requires at least one of: name, kind.");
|
|
16195
16196
|
const store = await getStore(memory);
|
|
16196
16197
|
const node = await store.getNode(value.node);
|
|
16197
16198
|
if (!node || node.mergedInto) throw new Error(`Knowledge node not found: ${value.node}`);
|
|
@@ -16269,6 +16270,48 @@ function createKnowledgeWriteTools(memory, options) {
|
|
|
16269
16270
|
});
|
|
16270
16271
|
}
|
|
16271
16272
|
}),
|
|
16273
|
+
knowledge_write_node_description: (0, _mastra_core_tools.createTool)({
|
|
16274
|
+
id: "knowledge_write_node_description",
|
|
16275
|
+
description: `Write the bounded synopsis (max ${_mastra_core_storage.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH} UTF-16 code units) on an existing visible node using optimistic concurrency. Pass an empty string to clear it. Does not create nodes.`,
|
|
16276
|
+
inputSchema: {
|
|
16277
|
+
type: "object",
|
|
16278
|
+
properties: {
|
|
16279
|
+
node: {
|
|
16280
|
+
type: "string",
|
|
16281
|
+
minLength: 1
|
|
16282
|
+
},
|
|
16283
|
+
expectedVersion: {
|
|
16284
|
+
type: "integer",
|
|
16285
|
+
minimum: 1
|
|
16286
|
+
},
|
|
16287
|
+
description: {
|
|
16288
|
+
type: "string",
|
|
16289
|
+
minLength: 0,
|
|
16290
|
+
maxLength: _mastra_core_storage.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH,
|
|
16291
|
+
description: `One or two plain-text sentences describing the node, targeting 40-75 tokens. Hard limit ${_mastra_core_storage.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH} UTF-16 code units, enforced by storage on every write; the length check on execution is authoritative. Long-form detail belongs in node content, not here. An empty string clears the description.`
|
|
16292
|
+
}
|
|
16293
|
+
},
|
|
16294
|
+
required: [
|
|
16295
|
+
"node",
|
|
16296
|
+
"expectedVersion",
|
|
16297
|
+
"description"
|
|
16298
|
+
],
|
|
16299
|
+
additionalProperties: false
|
|
16300
|
+
},
|
|
16301
|
+
execute: async (input) => {
|
|
16302
|
+
const value = input;
|
|
16303
|
+
if (value.description.length > _mastra_core_storage.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH) throw new Error(`Node descriptions are limited to ${_mastra_core_storage.MAX_KNOWLEDGE_NODE_DESCRIPTION_LENGTH} UTF-16 code units. Shorten the description and retry.`);
|
|
16304
|
+
const store = await getStore(memory);
|
|
16305
|
+
const node = await store.getNode(value.node);
|
|
16306
|
+
if (!node || node.mergedInto) throw new Error(`Knowledge node not found: ${value.node}`);
|
|
16307
|
+
requireVisible(node.scope, options, "Knowledge node");
|
|
16308
|
+
return store.updateNode({
|
|
16309
|
+
id: node.id,
|
|
16310
|
+
version: value.expectedVersion,
|
|
16311
|
+
description: value.description
|
|
16312
|
+
});
|
|
16313
|
+
}
|
|
16314
|
+
}),
|
|
16272
16315
|
knowledge_write_node_content: (0, _mastra_core_tools.createTool)({
|
|
16273
16316
|
id: "knowledge_write_node_content",
|
|
16274
16317
|
description: "Create or replace long-form content on a scoped knowledge node. Existing nodes require expectedVersion.",
|
|
@@ -16477,7 +16520,7 @@ var KnowledgeSemanticIndexCoordinator = class {
|
|
|
16477
16520
|
const node = await this.#knowledge.getNode(entry.documentId.slice(15));
|
|
16478
16521
|
if (!node || node.mergedInto) return null;
|
|
16479
16522
|
return {
|
|
16480
|
-
text: `${node.name}\n${node.content ?? ""}`,
|
|
16523
|
+
text: node.description ? `${node.name}\n${node.description}\n${node.content ?? ""}` : `${node.name}\n${node.content ?? ""}`,
|
|
16481
16524
|
name: node.name,
|
|
16482
16525
|
scope: node.scope,
|
|
16483
16526
|
recordId: node.id,
|
|
@@ -16547,7 +16590,14 @@ var subconscious_exports = /* @__PURE__ */ __exportAll({
|
|
|
16547
16590
|
});
|
|
16548
16591
|
const BUILT_IN_OBSERVATION = /* @__PURE__ */ new Set(["capture", "remind"]);
|
|
16549
16592
|
const BUILT_IN_REFLECTION = /* @__PURE__ */ new Set(["curate", "learn"]);
|
|
16550
|
-
const DEFAULT_MAX_STEPS =
|
|
16593
|
+
const DEFAULT_MAX_STEPS = 50;
|
|
16594
|
+
/**
|
|
16595
|
+
* Curation walks a worklist that can reach hundreds of records, and its completion marker is
|
|
16596
|
+
* fail-closed: a curator that runs out of steps advances no cursor at all. It gets a much larger
|
|
16597
|
+
* default budget than the other agents, which each handle a single bounded prompt.
|
|
16598
|
+
*/
|
|
16599
|
+
const DEFAULT_MAX_STEPS_BY_AGENT = { curate: 200 };
|
|
16600
|
+
const MAX_MAX_STEPS = 500;
|
|
16551
16601
|
const DEFAULT_RECENT_UPDATES = 10;
|
|
16552
16602
|
const MAX_RECENT_UPDATES = 100;
|
|
16553
16603
|
function entryName(entry) {
|
|
@@ -16564,7 +16614,7 @@ function assertUniqueNames(entries, phase) {
|
|
|
16564
16614
|
}
|
|
16565
16615
|
function boundedSteps(entry, fallback) {
|
|
16566
16616
|
const steps = entry?.maxSteps ?? fallback;
|
|
16567
|
-
if (!Number.isInteger(steps) || steps < 1 || steps >
|
|
16617
|
+
if (!Number.isInteger(steps) || steps < 1 || steps > MAX_MAX_STEPS) throw new Error(`Subconscious maxSteps must be an integer between 1 and ${MAX_MAX_STEPS}.`);
|
|
16568
16618
|
return steps;
|
|
16569
16619
|
}
|
|
16570
16620
|
function resolveExtractor(entry) {
|
|
@@ -16579,12 +16629,13 @@ function resolveExtractor(entry) {
|
|
|
16579
16629
|
function resolveAgent(entry, builtIns, globalModel, globalMaxSteps) {
|
|
16580
16630
|
const config = typeof entry === "string" ? void 0 : entry;
|
|
16581
16631
|
const name = entryName(entry);
|
|
16632
|
+
const fallbackMaxSteps = globalMaxSteps ?? DEFAULT_MAX_STEPS_BY_AGENT[name] ?? DEFAULT_MAX_STEPS;
|
|
16582
16633
|
return {
|
|
16583
16634
|
name,
|
|
16584
16635
|
instructions: config?.instructions,
|
|
16585
16636
|
model: config?.model ?? globalModel,
|
|
16586
16637
|
agent: config?.agent,
|
|
16587
|
-
maxSteps: boundedSteps(config,
|
|
16638
|
+
maxSteps: boundedSteps(config, fallbackMaxSteps),
|
|
16588
16639
|
builtIn: builtIns.has(name)
|
|
16589
16640
|
};
|
|
16590
16641
|
}
|
|
@@ -16601,7 +16652,7 @@ var Subconscious = class {
|
|
|
16601
16652
|
const reflection = config.reflection ?? ["curate", "learn"];
|
|
16602
16653
|
assertUniqueNames(observation, "observation");
|
|
16603
16654
|
assertUniqueNames(reflection, "reflection");
|
|
16604
|
-
const maxSteps = boundedSteps(config, DEFAULT_MAX_STEPS);
|
|
16655
|
+
const maxSteps = config.maxSteps === void 0 ? void 0 : boundedSteps(config, DEFAULT_MAX_STEPS);
|
|
16605
16656
|
for (const entry of observation) this.#validateObservationEntry(entry);
|
|
16606
16657
|
for (const entry of reflection) this.#validateReflectionEntry(entry);
|
|
16607
16658
|
const recentUpdates = config.activity === false ? false : config.activity?.recentUpdates ?? DEFAULT_RECENT_UPDATES;
|
|
@@ -16695,6 +16746,8 @@ const DEFAULT_INSTRUCTIONS$1 = `Maintain durable scoped knowledge from the commi
|
|
|
16695
16746
|
|
|
16696
16747
|
Use the read tools to inspect existing nodes, knowledge records, mentions, backlinks, and long-form node content. Use the write tools to merge true duplicates, repair names and links, soft-delete superseded knowledge records, rescope knowledge records only when justified and permitted by their ceilings, and synthesize useful node content. Never restore deleted knowledge records. Never invent provenance, capture timestamps, scopes, ceilings, IDs, or versions; those are enforced by code. Resolve optimistic-concurrency conflicts by reading the latest record and retrying the intended mutation. Keep the reserved capture-guidance node concise and update it only with durable guidance that will improve future capture.
|
|
16697
16748
|
|
|
16749
|
+
For each significant entity node touched by a KnowledgeRecord in the current worklist, including people, projects, pull requests, issues, repositories, documents, and organizations, maintain a short entity description; do not walk nodes outside the worklist for this. Use the supplied record and read the named node once; do not search or browse unless its identity is ambiguous. Describe what the entity is, its current state, and links to its real-world object, then write it with knowledge_write_node_description, which always requires expectedVersion from the node you just read; after a version conflict, re-read the node and regenerate the description from its current state before retrying. If the node does not exist yet, create it first with knowledge_write_node_content, then re-read it for its fresh version before writing the description. Write one or two plain-text sentences, roughly 40 to 75 tokens; storage rejects any description over its hard length cap, so keep them tight and put long-form detail in node content instead. Include links only from the entity's own records or observations that explicitly associate the link with that entity; never invent a URL, identifier, file path, or provenance. Leave long-form node content alone unless you are synthesizing it deliberately; never shrink content into a synopsis. For entity-description maintenance only, skip low-signal nodes with only a trivial record, any system-kind node, and the reserved capture-guidance node.
|
|
16750
|
+
|
|
16698
16751
|
Process the worklist in ID order. Every time you finish processing a KnowledgeRecord, include <curation-complete through="RECORD_ID" /> in your next text response with that record's ID. The latest marker is your acknowledged cursor, so progress survives if you run out of steps mid-batch. Your final response must end with the marker for the last KnowledgeRecord you fully processed. If you cannot finish the batch, acknowledge only the last KnowledgeRecord you did finish. Do not emit a completion marker when no KnowledgeRecord was fully processed.`;
|
|
16699
16752
|
const PINNED_INSTRUCTIONS = `Maintain the pin set with knowledge_pin, knowledge_edit_pin, and knowledge_unpin. Pinned entries are delivered to the main agent on every turn, so they cost tokens permanently and must stay short. Pin only knowledge that should apply without being asked for, such as standing instructions, durable preferences, and hard constraints. Pin only knowledge that is BOTH costly to rediscover AND not the kind of thing a future agent would think to search for; anything a reminder can surface on demand does not belong in the pin set. Unpin an entry as soon as it stops being unconditionally true.`;
|
|
16700
16753
|
function resolveScope$1(context) {
|
|
@@ -16706,6 +16759,11 @@ function resolveScope$1(context) {
|
|
|
16706
16759
|
`thread:${context.parentThreadId}`
|
|
16707
16760
|
]);
|
|
16708
16761
|
}
|
|
16762
|
+
/**
|
|
16763
|
+
* Upper bound on records pulled into a single reflection prompt. `hasMore` tells the agent the
|
|
16764
|
+
* worklist was truncated; the cursor it advances lets the next cycle pick up the remainder.
|
|
16765
|
+
*/
|
|
16766
|
+
const MAX_WORKLIST_RECORDS$1 = 1e3;
|
|
16709
16767
|
async function readWorklist$1(store, sourceThreadId, scope, after) {
|
|
16710
16768
|
const records = [];
|
|
16711
16769
|
let cursor = after;
|
|
@@ -16719,7 +16777,7 @@ async function readWorklist$1(store, sourceThreadId, scope, after) {
|
|
|
16719
16777
|
});
|
|
16720
16778
|
records.push(...page.records);
|
|
16721
16779
|
cursor = page.nextCursor;
|
|
16722
|
-
} while (cursor && records.length <
|
|
16780
|
+
} while (cursor && records.length < MAX_WORKLIST_RECORDS$1);
|
|
16723
16781
|
return {
|
|
16724
16782
|
records,
|
|
16725
16783
|
hasMore: Boolean(cursor)
|
|
@@ -16841,6 +16899,8 @@ function resolveScope(context) {
|
|
|
16841
16899
|
`thread:${context.parentThreadId}`
|
|
16842
16900
|
]);
|
|
16843
16901
|
}
|
|
16902
|
+
/** Upper bound on records pulled into a single reflection prompt; `hasMore` signals truncation. */
|
|
16903
|
+
const MAX_WORKLIST_RECORDS = 1e3;
|
|
16844
16904
|
async function readWorklist(store, sourceThreadId, scope, after) {
|
|
16845
16905
|
const records = [];
|
|
16846
16906
|
let cursor = after;
|
|
@@ -16853,7 +16913,7 @@ async function readWorklist(store, sourceThreadId, scope, after) {
|
|
|
16853
16913
|
});
|
|
16854
16914
|
records.push(...page.records);
|
|
16855
16915
|
cursor = page.nextCursor;
|
|
16856
|
-
} while (cursor && records.length <
|
|
16916
|
+
} while (cursor && records.length < MAX_WORKLIST_RECORDS);
|
|
16857
16917
|
return {
|
|
16858
16918
|
records,
|
|
16859
16919
|
hasMore: Boolean(cursor)
|
|
@@ -31809,4 +31869,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
|
|
|
31809
31869
|
}
|
|
31810
31870
|
});
|
|
31811
31871
|
|
|
31812
|
-
//# sourceMappingURL=src-
|
|
31872
|
+
//# sourceMappingURL=src-Br56ncef.cjs.map
|