@mastra/memory 1.39.0-alpha.1 → 1.39.0-alpha.2

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.
@@ -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.39.0-alpha.1"
6
+ version: "1.39.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.39.0-alpha.1",
2
+ "version": "1.39.0-alpha.2",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {},
5
5
  "modules": {
@@ -144,7 +144,8 @@ const stream = await agent.stream('Clean up old records', {
144
144
  },
145
145
  })
146
146
 
147
- return result.answers.requiresApproval.probability >= 0.7
147
+ // A refused question has no probability, so it falls back to requiring approval.
148
+ return (result.answers.requiresApproval.probability ?? 1) >= 0.7
148
149
  },
149
150
  })
150
151
  ```
@@ -203,7 +203,7 @@ const memory = new Memory({
203
203
 
204
204
  ### Retries and failure policy
205
205
 
206
- Observer and Reflector model calls are retried on transient provider errors, and a turn aborts if they still fail. Each stage is controlled independently by:
206
+ Observer and Reflector model calls are retried on transient provider errors. By default, a synchronous observation or reflection that still fails aborts the turn. Each stage is controlled independently by:
207
207
 
208
208
  - `maxRetries`: retries after the initial model call (default `8`).
209
209
  - `failurePolicy`: what happens once retries are exhausted, either `'abort'` (default) or `'continue'`.
@@ -231,7 +231,9 @@ With `failurePolicy: 'continue'`, Mastra retries as configured, reports the fail
231
231
 
232
232
  A provider outage usually takes out both stages, so set the policy on both if you want the turn to survive one.
233
233
 
234
- This policy applies only to Observer and Reflector model and provider failures in synchronous, resource-scoped, and buffered observation. Persistence, indexing, transform, locking, invariant, and explicit abort failures remain fatal. It doesn't prevent the underlying provider or network error, change `blockAfter`, or change attachment handling.
234
+ This policy applies only to Observer and Reflector model and provider failures when observation or reflection runs synchronously: at `blockAfter`, when async buffering is disabled, and in resource-scoped observation. In those paths, persistence, indexing, transform, locking, invariant, and explicit abort failures remain fatal. It doesn't prevent the underlying provider or network error, change `blockAfter`, or change attachment handling.
235
+
236
+ Background (async buffered) observation and reflection failures never stop the turn, whatever the policy. They're reported as `om_buffering_failed`, and the failed input stays pending. If it keeps growing, it reaches `blockAfter`, where synchronous observation applies `failurePolicy`.
235
237
 
236
238
  > **Warning:** `'continue'` has no backstop for a sustained outage. Unobserved messages stay pending and keep accruing in the main agent's context. A long outage moves the failure from the memory layer to the model's context limit.
237
239
 
@@ -75,7 +75,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
75
75
 
76
76
  **observation.maxRetries** (`number`): Retries after the initial Observer model call on transient provider errors. Governs OM's own retry ladder; the Observer model call itself is configured with no provider-level retries.
77
77
 
78
- **observation.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Observer retries are exhausted. 'abort' aborts the agent turn. 'continue' emits the existing failure diagnostic, keeps the failed input pending for a later cycle, and allows the main agent turn to continue. Persistence, indexing, transform, locking, invariant, and explicit abort failures remain fatal. This setting doesn't prevent the underlying provider error or change blockAfter or attachment handling, and it has no backstop for a sustained outage: pending messages keep accruing in the main agent's context until they reach the model's context limit.
78
+ **observation.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Observer retries are exhausted in a synchronous observation. Background buffered observation failures are reported as om\_buffering\_failed and never stop the turn. 'abort' aborts the agent turn. 'continue' emits the existing failure diagnostic, keeps the failed input pending for a later cycle, and allows the main agent turn to continue. Persistence, indexing, transform, locking, invariant, and explicit abort failures remain fatal. This setting doesn't prevent the underlying provider error or change blockAfter or attachment handling, and it has no backstop for a sustained outage: pending messages keep accruing in the main agent's context until they reach the model's context limit.
79
79
 
80
80
  **observation.messageTokens** (`number`): Token count of unobserved messages that triggers observation. When unobserved message tokens exceed this threshold, the Observer agent is called. Text is estimated locally with tokenx. Image parts are included with model-aware heuristics when possible, with deterministic fallbacks when image metadata is incomplete. Image-like file parts are counted the same way when uploads are normalized as files.
81
81
 
@@ -111,7 +111,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
111
111
 
112
112
  **reflection.maxRetries** (`number`): Retries after the initial Reflector model call on transient provider errors. Governs OM's own retry ladder; the Reflector model call itself is configured with no provider-level retries.
113
113
 
114
- **reflection.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Reflector retries are exhausted. 'abort' aborts the agent turn. 'continue' emits the failure diagnostic and allows the turn to continue, leaving already-persisted observations committed and deferring reflection to the next threshold crossing. A provider outage usually takes out both stages, so set the policy on observation too if the turn should survive one.
114
+ **reflection.failurePolicy** (`'abort' | 'continue'`): Terminal policy once Reflector retries are exhausted in a synchronous reflection. Background buffered reflection failures are reported as om\_buffering\_failed and never stop the turn. 'abort' aborts the agent turn. 'continue' emits the failure diagnostic and allows the turn to continue, leaving already-persisted observations committed and deferring reflection to the next threshold crossing. A provider outage usually takes out both stages, so set the policy on observation too if the turn should survive one.
115
115
 
116
116
  **reflection.instruction** (`string`): Custom instruction appended to the Reflector's system prompt. Use this to customize how the Reflector consolidates observations, such as prioritizing certain types of information.
117
117
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-DWeW4ai9.cjs");
2
+ const require_src = require("./src-CJiR-m2F.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
5
5
  exports.Extractor = require_src.Extractor;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { C as WorkingMemoryExtractor, E as summarizeConversation, G as Subconscious, K as KnowledgeSemanticIndexCoordinator, T as SUMMARIZE_THREAD_DEFAULTS, Y as ModelByInputTokens, a as extractWorkingMemoryContent, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, h as WorkingMemoryStateProcessor, i as WorkingMemory, m as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, p as WORKING_MEMORY_STATE_ID, q as StaleKnowledgeSemanticIndexError, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, w as deepMergeWorkingMemory } from "./src-YPRno9w9.js";
1
+ import { C as WorkingMemoryExtractor, E as summarizeConversation, G as Subconscious, K as KnowledgeSemanticIndexCoordinator, T as SUMMARIZE_THREAD_DEFAULTS, Y as ModelByInputTokens, a as extractWorkingMemoryContent, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, h as WorkingMemoryStateProcessor, i as WorkingMemory, m as WORKING_MEMORY_STATE_PROCESSOR_ID, n as MessageHistory, o as extractWorkingMemoryTags, p as WORKING_MEMORY_STATE_ID, q as StaleKnowledgeSemanticIndexError, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, w as deepMergeWorkingMemory } from "./src-BDhP0_OK.js";
2
2
  export { AUTO_MODEL_BY_PROVIDER, Extractor, KnowledgeSemanticIndexCoordinator, Memory, MessageHistory, ModelByInputTokens, SUMMARIZE_THREAD_DEFAULTS, SemanticRecall, StaleKnowledgeSemanticIndexError, Subconscious, WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemory, WorkingMemoryExtractor, WorkingMemoryStateProcessor, deepMergeWorkingMemory, extractWorkingMemoryContent, extractWorkingMemoryTags, getObservationsAsOf, removeWorkingMemoryTags, resolveAutoModelId, summarizeConversation };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-DWeW4ai9.cjs");
2
+ const require_src = require("../src-CJiR-m2F.cjs");
3
3
  exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.KnowledgeSemanticIndexCoordinator = require_src.KnowledgeSemanticIndexCoordinator;
@@ -1,2 +1,2 @@
1
- import { $ as renderSubconsciousActivity, A as buildObserverSystemPrompt, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as TokenCounter, E as summarizeConversation, F as parseObserverOutput, G as Subconscious, H as OBSERVATION_CONTEXT_PROMPT_THREAD, I as injectAnchorIds, J as SubconsciousRemindExtractor, K as KnowledgeSemanticIndexCoordinator, L as parseAnchorId, M as formatMessagesForObserver, N as hasCurrentTaskSection, O as OBSERVER_SYSTEM_PROMPT, P as optimizeObservationsForContext, Q as publishSubconsciousActivity, R as stripEphemeralAnchorIds, S as wrapInObservationGroup, U as OBSERVATION_CONTINUATION_HINT, V as OBSERVATION_CONTEXT_PROMPT, W as getObservationContextPrompt, X as SUBCONSCIOUS_ACTIVITY_STATE_ID, Y as ModelByInputTokens, Z as buildSubconsciousActivitySnapshot, _ as deriveObservationGroupProvenance, b as renderObservationGroupsForReflection, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, g as combineObservationGroupRanges, j as extractCurrentTask, k as buildObserverPrompt, l as ObservationalMemoryProcessor, q as StaleKnowledgeSemanticIndexError, u as ObservationalMemory, v as parseObservationGroups, x as stripObservationGroups, y as reconcileObservationGroupsFromReflection, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-YPRno9w9.js";
1
+ import { $ as renderSubconsciousActivity, A as buildObserverSystemPrompt, B as OBSERVATION_CONTEXT_INSTRUCTIONS, C as WorkingMemoryExtractor, D as TokenCounter, E as summarizeConversation, F as parseObserverOutput, G as Subconscious, H as OBSERVATION_CONTEXT_PROMPT_THREAD, I as injectAnchorIds, J as SubconsciousRemindExtractor, K as KnowledgeSemanticIndexCoordinator, L as parseAnchorId, M as formatMessagesForObserver, N as hasCurrentTaskSection, O as OBSERVER_SYSTEM_PROMPT, P as optimizeObservationsForContext, Q as publishSubconsciousActivity, R as stripEphemeralAnchorIds, S as wrapInObservationGroup, U as OBSERVATION_CONTINUATION_HINT, V as OBSERVATION_CONTEXT_PROMPT, W as getObservationContextPrompt, X as SUBCONSCIOUS_ACTIVITY_STATE_ID, Y as ModelByInputTokens, Z as buildSubconsciousActivitySnapshot, _ as deriveObservationGroupProvenance, b as renderObservationGroupsForReflection, c as getObservationsAsOf, d as AUTO_MODEL_BY_PROVIDER, et as Extractor, f as resolveAutoModelId, g as combineObservationGroupRanges, j as extractCurrentTask, k as buildObserverPrompt, l as ObservationalMemoryProcessor, q as StaleKnowledgeSemanticIndexError, u as ObservationalMemory, v as parseObservationGroups, x as stripObservationGroups, y as reconcileObservationGroupsFromReflection, z as OBSERVATIONAL_MEMORY_DEFAULTS } from "../src-BDhP0_OK.js";
2
2
  export { AUTO_MODEL_BY_PROVIDER, Extractor, KnowledgeSemanticIndexCoordinator, ModelByInputTokens, OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTEXT_PROMPT_THREAD, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, SUBCONSCIOUS_ACTIVITY_STATE_ID, StaleKnowledgeSemanticIndexError, Subconscious, SubconsciousRemindExtractor, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, buildSubconsciousActivitySnapshot, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationContextPrompt, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, publishSubconsciousActivity, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, renderSubconsciousActivity, resolveAutoModelId, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
@@ -14,4 +14,11 @@ import { RequestContext } from '@mastra/core/request-context';
14
14
  * fails MessageList's resourceId validation.
15
15
  */
16
16
  export declare function withOmInternalThreadId(requestContext: RequestContext | undefined, omAgentId: string): RequestContext | undefined;
17
+ /**
18
+ * A copy of `requestContext` whose reserved thread and resource ids name the
19
+ * thread a background agent addresses. The reserved ids outrank the memory
20
+ * target of a run, so forwarding the parent's ids, or rewriting them to some
21
+ * other id, runs the agent on a thread other than its own.
22
+ */
23
+ export declare function withOwnThreadIds(requestContext: RequestContext | undefined, threadId: string, resourceId: string): RequestContext | undefined;
17
24
  //# sourceMappingURL=internal-request-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal-request-context.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/internal-request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEpF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,SAAS,EAAE,MAAM,GAChB,cAAc,GAAG,SAAS,CAW5B"}
1
+ {"version":3,"file":"internal-request-context.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/internal-request-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE5G;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,SAAS,EAAE,MAAM,GAChB,cAAc,GAAG,SAAS,CAW5B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,cAAc,GAAG,SAAS,CAO5B"}
@@ -1,7 +1,8 @@
1
1
  import { Agent } from '@mastra/core/agent';
2
2
  import type { KnowledgeScope } from '@mastra/core/storage';
3
3
  import type { Memory } from '../../../index.js';
4
- import { Extractor, type ExtractorOnExtractedContext } from '../extractor.js';
4
+ import { Extractor } from '../extractor.js';
5
+ import type { ExtractorOnExtractedContext } from '../extractor.js';
5
6
  import type { ObservationalMemoryModel } from '../types.js';
6
7
  import type { ResolvedSubconsciousAgent, ResolvedSubconsciousConfig } from './types.js';
7
8
  export declare const CURATION_AGENT = "curate";
@@ -1 +1 @@
1
- {"version":3,"file":"curate.d.ts","sourceRoot":"","sources":["../../../../src/processors/observational-memory/subconscious/curate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,sBAAsB,CAAC;AAG7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,KAAK,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAOzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAErF,eAAO,MAAM,cAAc,WAAW,CAAC;AAmCvC,eAAO,MAAM,mBAAmB,mlBAAmlB,CAAC;AAEpnB,KAAK,cAAc,GAAG,IAAI,CACxB,2BAA2B,EAC3B,aAAa,GAAG,WAAW,GAAG,gBAAgB,GAAG,YAAY,GAAG,UAAU,CAC3E,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAO3E;AAED,qBAAa,2BAA4B,SAAQ,SAAS,CAAC,OAAO,CAAC;gBAE/D,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,0BAA0B,EACxC,gBAAgB,EAAE,MAAM,MAAM,EAC9B,OAAO,CAAC,EAAE,wBAAwB,EAClC,aAAa,GAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,IAAwC;CA0BnF;AA8BD,mHAAmH;AACnH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAMvD;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,MAAM,kEAqBrB;AA6CD,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,0BAA0B,EACxC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,KAAK,CAAC,CAuChB"}
1
+ {"version":3,"file":"curate.d.ts","sourceRoot":"","sources":["../../../../src/processors/observational-memory/subconscious/curate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,sBAAsB,CAAC;AAG7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAOzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAErF,eAAO,MAAM,cAAc,WAAW,CAAC;AAmCvC,eAAO,MAAM,mBAAmB,mlBAAmlB,CAAC;AAEpnB,KAAK,cAAc,GAAG,IAAI,CACxB,2BAA2B,EAC3B,aAAa,GAAG,WAAW,GAAG,gBAAgB,GAAG,YAAY,GAAG,UAAU,CAC3E,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAO3E;AAED,qBAAa,2BAA4B,SAAQ,SAAS,CAAC,OAAO,CAAC;gBAE/D,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,0BAA0B,EACxC,gBAAgB,EAAE,MAAM,MAAM,EAC9B,OAAO,CAAC,EAAE,wBAAwB,EAClC,aAAa,GAAE,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,IAAwC;CA0BnF;AA8BD,mHAAmH;AACnH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAMvD;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,MAAM,kEA6BrB;AA6CD,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,yBAAyB,EACjC,YAAY,EAAE,0BAA0B,EACxC,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,KAAK,CAAC,CAuChB"}