@mastra/memory 1.20.3 → 1.20.6-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.
Files changed (30) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/{chunk-4TZ5SRFX.cjs → chunk-2ZNDDQ6X.cjs} +31 -12
  3. package/dist/chunk-2ZNDDQ6X.cjs.map +1 -0
  4. package/dist/{chunk-YJJXL5KY.js → chunk-3I6H2ABM.js} +31 -12
  5. package/dist/chunk-3I6H2ABM.js.map +1 -0
  6. package/dist/docs/SKILL.md +2 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +47 -47
  8. package/dist/docs/references/docs-agents-goals.md +110 -0
  9. package/dist/index.cjs +23 -19
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +14 -10
  13. package/dist/index.js.map +1 -1
  14. package/dist/{observational-memory-6SHFQDPT.cjs → observational-memory-XZTKSWPR.cjs} +26 -26
  15. package/dist/{observational-memory-6SHFQDPT.cjs.map → observational-memory-XZTKSWPR.cjs.map} +1 -1
  16. package/dist/{observational-memory-NIGWGBLT.js → observational-memory-Y5T2OR2Y.js} +3 -3
  17. package/dist/{observational-memory-NIGWGBLT.js.map → observational-memory-Y5T2OR2Y.js.map} +1 -1
  18. package/dist/processors/index.cjs +24 -24
  19. package/dist/processors/index.js +1 -1
  20. package/dist/processors/observational-memory/internal-request-context.d.ts +10 -0
  21. package/dist/processors/observational-memory/internal-request-context.d.ts.map +1 -0
  22. package/dist/processors/observational-memory/model-context.d.ts +0 -8
  23. package/dist/processors/observational-memory/model-context.d.ts.map +1 -1
  24. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  28. package/package.json +13 -13
  29. package/dist/chunk-4TZ5SRFX.cjs.map +0 -1
  30. package/dist/chunk-YJJXL5KY.js.map +0 -1
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.20.3"
6
+ version: "1.20.6-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -18,6 +18,7 @@ Read the individual reference documents for detailed explanations and code examp
18
18
 
19
19
  - [Agent approval](references/docs-agents-agent-approval.md) - Learn how to require approvals, suspend tool execution, and automatically resume suspended tools while keeping humans in control of agent workflows.
20
20
  - [Background tasks](references/docs-agents-background-tasks.md) - Learn how to dispatch long-running tool calls in the background, keep the stream open until they complete, and orchestrate subagents asynchronously.
21
+ - [Goals](references/docs-agents-goals.md) - Learn how to set a durable objective on an agent that is judged in the execution loop, so the agent keeps working until the goal is complete or the run budget is exhausted.
21
22
  - [Agent networks](references/docs-agents-networks.md) - Coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
22
23
  - [Supervisor agents](references/docs-agents-supervisor-agents.md) - Learn how to coordinate multiple agents with delegation hooks, iteration monitoring, message filtering, and task completion scoring.
23
24
  - [Evals with memory](references/docs-evals-evals-with-memory.md) - Run scorers against memory-enabled agents — including observational memory in thread scope — using runEvals and dataset experiments.
@@ -1,120 +1,120 @@
1
1
  {
2
- "version": "1.20.3",
2
+ "version": "1.20.6-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-YJJXL5KY.js",
8
- "line": 787
7
+ "implementation": "dist/chunk-3I6H2ABM.js",
8
+ "line": 795
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-YJJXL5KY.js"
12
+ "implementation": "dist/chunk-3I6H2ABM.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-YJJXL5KY.js",
17
- "line": 7175
16
+ "implementation": "dist/chunk-3I6H2ABM.js",
17
+ "line": 7194
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-YJJXL5KY.js",
22
- "line": 9747
21
+ "implementation": "dist/chunk-3I6H2ABM.js",
22
+ "line": 9766
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-YJJXL5KY.js",
27
- "line": 6506
26
+ "implementation": "dist/chunk-3I6H2ABM.js",
27
+ "line": 6525
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-YJJXL5KY.js",
32
- "line": 3774
31
+ "implementation": "dist/chunk-3I6H2ABM.js",
32
+ "line": 3782
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-YJJXL5KY.js",
37
- "line": 3045
36
+ "implementation": "dist/chunk-3I6H2ABM.js",
37
+ "line": 3053
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-YJJXL5KY.js",
42
- "line": 879
41
+ "implementation": "dist/chunk-3I6H2ABM.js",
42
+ "line": 887
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-YJJXL5KY.js",
47
- "line": 913
46
+ "implementation": "dist/chunk-3I6H2ABM.js",
47
+ "line": 921
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-YJJXL5KY.js",
52
- "line": 3888
51
+ "implementation": "dist/chunk-3I6H2ABM.js",
52
+ "line": 3896
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-YJJXL5KY.js",
57
- "line": 3500
56
+ "implementation": "dist/chunk-3I6H2ABM.js",
57
+ "line": 3508
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-YJJXL5KY.js",
62
- "line": 9967
61
+ "implementation": "dist/chunk-3I6H2ABM.js",
62
+ "line": 9986
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-YJJXL5KY.js",
67
- "line": 3876
66
+ "implementation": "dist/chunk-3I6H2ABM.js",
67
+ "line": 3884
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-YJJXL5KY.js",
72
- "line": 2593
71
+ "implementation": "dist/chunk-3I6H2ABM.js",
72
+ "line": 2601
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-YJJXL5KY.js",
77
- "line": 3899
76
+ "implementation": "dist/chunk-3I6H2ABM.js",
77
+ "line": 3907
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-YJJXL5KY.js",
82
- "line": 2566
81
+ "implementation": "dist/chunk-3I6H2ABM.js",
82
+ "line": 2574
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-YJJXL5KY.js",
87
- "line": 848
86
+ "implementation": "dist/chunk-3I6H2ABM.js",
87
+ "line": 856
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-YJJXL5KY.js",
92
- "line": 3784
91
+ "implementation": "dist/chunk-3I6H2ABM.js",
92
+ "line": 3792
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-YJJXL5KY.js",
97
- "line": 937
96
+ "implementation": "dist/chunk-3I6H2ABM.js",
97
+ "line": 945
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-YJJXL5KY.js",
102
- "line": 893
101
+ "implementation": "dist/chunk-3I6H2ABM.js",
102
+ "line": 901
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-YJJXL5KY.js",
107
- "line": 2623
106
+ "implementation": "dist/chunk-3I6H2ABM.js",
107
+ "line": 2631
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-YJJXL5KY.js",
112
- "line": 870
111
+ "implementation": "dist/chunk-3I6H2ABM.js",
112
+ "line": 878
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-YJJXL5KY.js",
117
- "line": 841
116
+ "implementation": "dist/chunk-3I6H2ABM.js",
117
+ "line": 849
118
118
  },
119
119
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
120
120
  "types": "dist/processors/index.d.ts",
@@ -162,7 +162,7 @@
162
162
  "processors": {
163
163
  "index": "dist/processors/index.js",
164
164
  "chunks": [
165
- "chunk-YJJXL5KY.js",
165
+ "chunk-3I6H2ABM.js",
166
166
  "chunk-LSJJAJAF.js"
167
167
  ]
168
168
  }
@@ -0,0 +1,110 @@
1
+ # Goals
2
+
3
+ **Added in:** `@mastra/core@1.42.0`
4
+
5
+ A goal is a durable, thread-scoped objective: a standing instruction the agent keeps working toward across loop iterations until a judge model decides it is satisfied or a run budget is exhausted. The objective is persisted in thread state, so it survives reloads and is evaluated in-loop — even when a new message arrives in the middle of an already-running turn.
6
+
7
+ Goals build on the same machinery as [`isTaskComplete`](https://mastra.ai/docs/agents/supervisor-agents): an LLM-as-judge scores the agent's output each iteration and gates the loop. The difference is that a goal is **durable** (stored in thread state, not passed per call) and is set and updated through `Agent` methods rather than per-`stream()` options.
8
+
9
+ > **Note:** Goals are experimental and may change in a future release.
10
+
11
+ ## When to use goals
12
+
13
+ Use a goal when you want an agent to keep working toward a single objective across many iterations and messages, without re-supplying the success criteria on every call:
14
+
15
+ - A standing objective the agent should pursue until a judge says it's done.
16
+ - Work that should continue across mid-run messages (a message delivered into a live run is still judged against the goal).
17
+ - An objective that must persist across thread reloads or process restarts.
18
+
19
+ For a one-off completion check within a single `stream()` call, use [`isTaskComplete`](https://mastra.ai/docs/agents/supervisor-agents) instead.
20
+
21
+ ## Quickstart
22
+
23
+ Goals require a configured [storage](https://mastra.ai/docs/memory/storage) backend and a memory-backed thread. Add a `goal` config to the agent — a judge model is required for the goal to do anything — then set an objective for a thread:
24
+
25
+ ```typescript
26
+ import { Agent } from '@mastra/core/agent'
27
+
28
+ const worker = new Agent({
29
+ name: 'worker',
30
+ instructions: 'You complete software tasks end to end.',
31
+ model: 'openai/gpt-5.5',
32
+ memory,
33
+ goal: {
34
+ judge: 'openai/gpt-5-mini',
35
+ maxRuns: 50,
36
+ },
37
+ })
38
+
39
+ // Set the durable objective for a thread.
40
+ await worker.setObjective('Add and test a /health endpoint', {
41
+ threadId,
42
+ resourceId,
43
+ })
44
+
45
+ // The objective is judged each iteration until it's complete or maxRuns is hit.
46
+ const stream = await worker.stream('Start working on the goal', {
47
+ memory: { thread: threadId, resource: resourceId },
48
+ })
49
+ ```
50
+
51
+ The `goal` config auto-registers the state-signal projection, so the model always sees the current objective as `<current-objective>` in its context — no extra setup needed.
52
+
53
+ ## How the goal step works
54
+
55
+ A goal step runs inside the agentic execution loop, right after `isTaskComplete`. On a real candidate answer it scores the conversation against the objective and gates the loop:
56
+
57
+ - **Not satisfied, budget remaining** → the loop continues; per-evaluation feedback is injected so the agent iterates.
58
+ - **Satisfied** → the loop stops and the objective is marked `done`.
59
+ - **Budget exhausted** (`runsUsed >= maxRuns`) → the loop stops but the objective stays `active`, so raising `maxRuns` later can resume it.
60
+
61
+ The step is a no-op for background-task, mid-tool-loop, and working-memory-only iterations — the same gating as `isTaskComplete`.
62
+
63
+ **The judge model is the activation switch.** If no judge resolves (neither the per-objective override nor the agent's `goal.judge`), the goal step does nothing: no scoring, no budget consumed, no `goal` chunk. Effective settings resolve as per-objective record value → agent `goal` config → built-in default (`maxRuns` `50`, a default judge prompt).
64
+
65
+ By default the step uses a built-in LLM-as-judge scorer that returns `1` when the objective is achieved and `0` otherwise. Supply your own scorer with `goal.scorer` to customize judging.
66
+
67
+ ```typescript
68
+ const worker = new Agent({
69
+ name: 'worker',
70
+ instructions: 'You complete software tasks end to end.',
71
+ model: 'openai/gpt-5.5',
72
+ memory,
73
+ goal: {
74
+ // A resolver function lets you inject provider credentials and read the
75
+ // current judge selection at runtime; returning `undefined` keeps the
76
+ // goal step a no-op.
77
+ judge: ({ requestContext }) => resolveJudgeModel(requestContext),
78
+ maxRuns: 30,
79
+ prompt: 'Only mark the goal complete when tests pass.',
80
+ },
81
+ })
82
+ ```
83
+
84
+ Each evaluation emits a typed `goal` stream chunk (`GoalEvaluationPayload`: `objective`, `iteration`, `maxRuns`, `passed`, `status`, `results`, `reason`, `duration`, `timedOut`, `maxRunsReached`, `suppressFeedback`) so a UI can show goal progress mid-run.
85
+
86
+ ## Managing the objective
87
+
88
+ Control the objective for a thread with `Agent` methods. All of them no-op when the run is not memory-backed (they require storage and a `threadId`):
89
+
90
+ ```typescript
91
+ // Read the current objective record.
92
+ const record = await worker.getObjective({ threadId })
93
+
94
+ // Update options on the active objective (only provided fields are written;
95
+ // unset fields fall back to the agent's `goal` config).
96
+ await worker.updateObjectiveOptions({ threadId, maxRuns: 100 })
97
+
98
+ // Drop the objective.
99
+ await worker.clearObjective({ threadId })
100
+ ```
101
+
102
+ Per-objective values written by `setObjective` / `updateObjectiveOptions` take precedence over the agent's `goal` config, and that precedence is remembered in thread state.
103
+
104
+ > **Note:** See the [`GoalEvaluationPayload` in the ChunkType reference](https://mastra.ai/reference/streaming/ChunkType) for the full goal chunk shape.
105
+
106
+ ## Related
107
+
108
+ - [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents) — `isTaskComplete` and the rubric scorer
109
+ - [Signal providers](https://mastra.ai/docs/agents/signal-providers) — how the objective is projected into context
110
+ - [Memory storage](https://mastra.ai/docs/memory/storage) — the storage backend goals require
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk4TZ5SRFX_cjs = require('./chunk-4TZ5SRFX.cjs');
3
+ var chunk2ZNDDQ6X_cjs = require('./chunk-2ZNDDQ6X.cjs');
4
4
  var chunk43FJOLKM_cjs = require('./chunk-43FJOLKM.cjs');
5
5
  var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
6
6
  var agent = require('@mastra/core/agent');
@@ -10,6 +10,7 @@ var observability = require('@mastra/core/observability');
10
10
  var utils = require('@mastra/core/utils');
11
11
  var schema = require('@mastra/schema-compat/schema');
12
12
  var asyncMutex = require('async-mutex');
13
+ var lruCache = require('lru-cache');
13
14
  var xxhash = require('xxhash-wasm');
14
15
  var tools = require('@mastra/core/tools');
15
16
  var tokenx = require('tokenx');
@@ -20,7 +21,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
20
21
 
21
22
  var xxhash__default = /*#__PURE__*/_interopDefault(xxhash);
22
23
 
23
- // ../_vendored/ai_v4/dist/chunk-J65CK2AI.js
24
+ // ../_vendored/ai_v4/dist/chunk-QGLOM3VL.js
24
25
  var __create = Object.create;
25
26
  var __defProp = Object.defineProperty;
26
27
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -22918,7 +22919,7 @@ var ZodFirstPartyTypeKind3;
22918
22919
  ZodFirstPartyTypeKind4["ZodReadonly"] = "ZodReadonly";
22919
22920
  })(ZodFirstPartyTypeKind3 || (ZodFirstPartyTypeKind3 = {}));
22920
22921
 
22921
- // ../_vendored/ai_v5/dist/chunk-LPCSE373.js
22922
+ // ../_vendored/ai_v5/dist/chunk-OMTTDYJT.js
22922
22923
  var marker17 = "vercel.ai.error";
22923
22924
  var symbol18 = Symbol.for(marker17);
22924
22925
  var _a19;
@@ -46034,7 +46035,7 @@ function formatTimestamp(date9) {
46034
46035
  }
46035
46036
  function truncateByTokens(text4, maxTokens, hint) {
46036
46037
  if (tokenx.estimateTokenCount(text4) <= maxTokens) return { text: text4, wasTruncated: false };
46037
- const truncated = chunk4TZ5SRFX_cjs.truncateStringByTokens(text4, maxTokens);
46038
+ const truncated = chunk2ZNDDQ6X_cjs.truncateStringByTokens(text4, maxTokens);
46038
46039
  const suffix = hint ? ` [${hint} for more]` : "";
46039
46040
  return { text: truncated + suffix, wasTruncated: true };
46040
46041
  }
@@ -46086,11 +46087,11 @@ ${JSON.stringify(inv.args, null, 2)}`;
46086
46087
  });
46087
46088
  }
46088
46089
  if (inv.state === "result") {
46089
- const { value: resultValue } = chunk4TZ5SRFX_cjs.resolveToolResultValue(
46090
+ const { value: resultValue } = chunk2ZNDDQ6X_cjs.resolveToolResultValue(
46090
46091
  part,
46091
46092
  inv.result
46092
46093
  );
46093
- const resultStr = chunk4TZ5SRFX_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46094
+ const resultStr = chunk2ZNDDQ6X_cjs.formatToolResultForObserver(resultValue, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46094
46095
  const fullText = `[Tool Result: ${inv.toolName}]
46095
46096
  ${resultStr}`;
46096
46097
  parts.push(makePart(msg, i, "tool-result", fullText, detail, inv.toolName));
@@ -46117,7 +46118,7 @@ ${typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs, null, 2)}`;
46117
46118
  const toolName = part.toolName;
46118
46119
  if (toolName) {
46119
46120
  const rawResult = part.output ?? part.result;
46120
- const resultStr = chunk4TZ5SRFX_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46121
+ const resultStr = chunk2ZNDDQ6X_cjs.formatToolResultForObserver(rawResult, { maxTokens: HIGH_DETAIL_TOOL_RESULT_TOKENS });
46121
46122
  const fullText = `[Tool Result: ${toolName}]
46122
46123
  ${resultStr}`;
46123
46124
  parts.push(makePart(msg, i, "tool-result", fullText, detail, toolName));
@@ -46196,7 +46197,7 @@ function renderFormattedParts(parts, timestamps, options) {
46196
46197
  const text4 = buildRenderedText(parts, timestamps);
46197
46198
  let totalTokens = tokenx.estimateTokenCount(text4);
46198
46199
  if (totalTokens > options.maxTokens) {
46199
- const truncated = chunk4TZ5SRFX_cjs.truncateStringByTokens(text4, options.maxTokens);
46200
+ const truncated = chunk2ZNDDQ6X_cjs.truncateStringByTokens(text4, options.maxTokens);
46200
46201
  return { text: truncated, truncated: true, tokenOffset: totalTokens - options.maxTokens };
46201
46202
  }
46202
46203
  const truncatedIndices = parts.map((p, i) => ({ part: p, index: i })).filter(({ part }) => part.text !== part.fullText).sort((a, b) => expandPriority(a.part) - expandPriority(b.part));
@@ -46229,7 +46230,7 @@ function renderFormattedParts(parts, timestamps, options) {
46229
46230
  if (expandedTokens <= options.maxTokens) {
46230
46231
  return { text: expanded, truncated: false, tokenOffset: 0 };
46231
46232
  }
46232
- const hardTruncated = chunk4TZ5SRFX_cjs.truncateStringByTokens(expanded, options.maxTokens);
46233
+ const hardTruncated = chunk2ZNDDQ6X_cjs.truncateStringByTokens(expanded, options.maxTokens);
46233
46234
  return { text: hardTruncated, truncated: true, tokenOffset: expandedTokens - options.maxTokens };
46234
46235
  }
46235
46236
  async function recallPart({
@@ -46280,7 +46281,7 @@ async function recallPart({
46280
46281
 
46281
46282
  `;
46282
46283
  const fallbackText = `${fallbackNote}${firstNextPart.text}`;
46283
- const truncatedText2 = chunk4TZ5SRFX_cjs.truncateStringByTokens(fallbackText, maxTokens);
46284
+ const truncatedText2 = chunk2ZNDDQ6X_cjs.truncateStringByTokens(fallbackText, maxTokens);
46284
46285
  const wasTruncated2 = truncatedText2 !== fallbackText;
46285
46286
  return {
46286
46287
  text: truncatedText2,
@@ -46295,7 +46296,7 @@ async function recallPart({
46295
46296
  }
46296
46297
  throw new Error(`Part index ${partIndex} not found in message ${cursor}. Available indices: ${availableIndices}`);
46297
46298
  }
46298
- const truncatedText = chunk4TZ5SRFX_cjs.truncateStringByTokens(target.text, maxTokens);
46299
+ const truncatedText = chunk2ZNDDQ6X_cjs.truncateStringByTokens(target.text, maxTokens);
46299
46300
  const wasTruncated = truncatedText !== target.text;
46300
46301
  return {
46301
46302
  text: truncatedText,
@@ -47160,6 +47161,7 @@ var CHARS_PER_TOKEN = 4;
47160
47161
  var DEFAULT_MESSAGE_RANGE = { before: 1, after: 1 };
47161
47162
  var DEFAULT_TOP_K = 4;
47162
47163
  var VECTOR_DELETE_BATCH_SIZE = 100;
47164
+ var DEFAULT_EMBEDDING_CACHE_MAX_SIZE = 1e3;
47163
47165
  var Memory = class extends memory.MastraMemory {
47164
47166
  _omEngine;
47165
47167
  _omEngineInstance;
@@ -47679,14 +47681,16 @@ ${workingMemory}`;
47679
47681
  return chunks;
47680
47682
  }
47681
47683
  hasher = xxhash__default.default();
47682
- // embedding is computationally expensive so cache content -> embeddings/chunks
47683
- embeddingCache = /* @__PURE__ */ new Map();
47684
+ // Embedding is computationally expensive, so cache content -> embeddings/chunks.
47685
+ // Bounded by an LRU so a long-running instance can't retain every embedded
47686
+ // message/query (and its vectors + chunk text) for the life of the process.
47687
+ embeddingCache = new lruCache.LRUCache({ max: DEFAULT_EMBEDDING_CACHE_MAX_SIZE });
47684
47688
  firstEmbed;
47685
47689
  async embedMessageContent(content) {
47686
- const key = (await this.hasher).h32(content);
47690
+ const key = (await this.hasher).h64(content);
47687
47691
  const cached3 = this.embeddingCache.get(key);
47688
47692
  if (cached3) {
47689
- this.logger.debug("Embedding cache hit", { contentHash: key, chunks: cached3.chunks.length });
47693
+ this.logger.debug("Embedding cache hit", { contentHash: key.toString(), chunks: cached3.chunks.length });
47690
47694
  return cached3;
47691
47695
  }
47692
47696
  const chunks = this.chunkText(content);
@@ -48116,7 +48120,7 @@ ${workingMemory}`;
48116
48120
  "Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
48117
48121
  );
48118
48122
  }
48119
- const { ObservationalMemory: OMClass } = await import('./observational-memory-6SHFQDPT.cjs');
48123
+ const { ObservationalMemory: OMClass } = await import('./observational-memory-XZTKSWPR.cjs');
48120
48124
  const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
48121
48125
  await this.indexObservation(observation);
48122
48126
  } : void 0;
@@ -49068,7 +49072,7 @@ Notes:
49068
49072
  if (!effectiveConfig) return null;
49069
49073
  const engine = await this.omEngine;
49070
49074
  if (!engine) return null;
49071
- const { ObservationalMemoryProcessor } = await import('./observational-memory-6SHFQDPT.cjs');
49075
+ const { ObservationalMemoryProcessor } = await import('./observational-memory-XZTKSWPR.cjs');
49072
49076
  return new ObservationalMemoryProcessor(engine, this, {
49073
49077
  temporalMarkers: effectiveConfig.temporalMarkers
49074
49078
  });
@@ -49095,11 +49099,11 @@ Notes:
49095
49099
 
49096
49100
  Object.defineProperty(exports, "ModelByInputTokens", {
49097
49101
  enumerable: true,
49098
- get: function () { return chunk4TZ5SRFX_cjs.ModelByInputTokens; }
49102
+ get: function () { return chunk2ZNDDQ6X_cjs.ModelByInputTokens; }
49099
49103
  });
49100
49104
  Object.defineProperty(exports, "getObservationsAsOf", {
49101
49105
  enumerable: true,
49102
- get: function () { return chunk4TZ5SRFX_cjs.getObservationsAsOf; }
49106
+ get: function () { return chunk2ZNDDQ6X_cjs.getObservationsAsOf; }
49103
49107
  });
49104
49108
  Object.defineProperty(exports, "WORKING_MEMORY_STATE_ID", {
49105
49109
  enumerable: true,