@mastra/memory 1.15.0-alpha.1 → 1.15.0-alpha.3
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 +12 -0
- package/dist/{chunk-ZEKCVX4E.js → chunk-42AZEBIK.js} +36 -10
- package/dist/chunk-42AZEBIK.js.map +1 -0
- package/dist/{chunk-ANKEPFC6.cjs → chunk-WNLRMAHY.cjs} +35 -9
- package/dist/chunk-WNLRMAHY.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +29 -29
- package/dist/index.cjs +13 -13
- package/dist/index.js +4 -4
- package/dist/{observational-memory-NKF66CFX.cjs → observational-memory-3RE2HCRV.cjs} +26 -26
- package/dist/{observational-memory-NKF66CFX.cjs.map → observational-memory-3RE2HCRV.cjs.map} +1 -1
- package/dist/{observational-memory-S6YN56D3.js → observational-memory-MBL257AG.js} +3 -3
- package/dist/{observational-memory-S6YN56D3.js.map → observational-memory-MBL257AG.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +7 -0
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-ANKEPFC6.cjs.map +0 -1
- package/dist/chunk-ZEKCVX4E.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.15.0-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed reflection threshold not respecting per-record overrides set via the PATCH API. Previously, lowering the reflection threshold for a specific record had no effect on the actual reflection trigger — only the default 40k threshold was used. Now per-record overrides are correctly applied in both sync and async reflection paths. ([#15170](https://github.com/mastra-ai/mastra/pull/15170))
|
|
8
|
+
|
|
9
|
+
## 1.15.0-alpha.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fixed message history doubling when using Observational Memory with the Mastra gateway. The local ObservationalMemoryProcessor now detects when the agent's model is routed through the Mastra gateway and skips its input/output processing, since the gateway handles OM server-side. ([#15161](https://github.com/mastra-ai/mastra/pull/15161))
|
|
14
|
+
|
|
3
15
|
## 1.15.0-alpha.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_RETRIEVAL_INSTRUCTIONS, OBSERVATION_CONTINUATION_HINT } from './chunk-LSJJAJAF.js';
|
|
2
2
|
import { coreFeatures } from '@mastra/core/features';
|
|
3
|
-
import { resolveModelConfig } from '@mastra/core/llm';
|
|
3
|
+
import { resolveModelConfig, ModelRouterLanguageModel } from '@mastra/core/llm';
|
|
4
4
|
import { getThreadOMMetadata, setThreadOMMetadata, parseMemoryRequestContext } from '@mastra/core/memory';
|
|
5
5
|
import { MessageHistory } from '@mastra/core/processors';
|
|
6
6
|
import xxhash from 'xxhash-wasm';
|
|
@@ -4124,13 +4124,29 @@ var ReflectorRunner = class {
|
|
|
4124
4124
|
model
|
|
4125
4125
|
});
|
|
4126
4126
|
}
|
|
4127
|
-
getObservationMarkerConfig() {
|
|
4127
|
+
getObservationMarkerConfig(record) {
|
|
4128
4128
|
return {
|
|
4129
4129
|
messageTokens: getMaxThreshold(this.observationConfig.messageTokens),
|
|
4130
|
-
observationTokens: getMaxThreshold(
|
|
4130
|
+
observationTokens: getMaxThreshold(
|
|
4131
|
+
record ? this.getEffectiveReflectionTokens(record) : this.reflectionConfig.observationTokens
|
|
4132
|
+
),
|
|
4131
4133
|
scope: this.scope
|
|
4132
4134
|
};
|
|
4133
4135
|
}
|
|
4136
|
+
/**
|
|
4137
|
+
* Resolve the effective reflection observationTokens for a record.
|
|
4138
|
+
* Only explicit per-record overrides (stored under `_overrides`) win;
|
|
4139
|
+
* the initial config snapshot is ignored so instance-level changes
|
|
4140
|
+
* still take effect for existing records.
|
|
4141
|
+
*/
|
|
4142
|
+
getEffectiveReflectionTokens(record) {
|
|
4143
|
+
const overrides = record.config?._overrides;
|
|
4144
|
+
const recordTokens = overrides?.reflection?.observationTokens;
|
|
4145
|
+
if (recordTokens) {
|
|
4146
|
+
return recordTokens;
|
|
4147
|
+
}
|
|
4148
|
+
return this.reflectionConfig.observationTokens;
|
|
4149
|
+
}
|
|
4134
4150
|
/**
|
|
4135
4151
|
* Call the Reflector agent with escalating compression levels.
|
|
4136
4152
|
*/
|
|
@@ -4319,7 +4335,7 @@ var ReflectorRunner = class {
|
|
|
4319
4335
|
const freshRecord = await this.storage.getObservationalMemory(record.threadId, record.resourceId);
|
|
4320
4336
|
const currentRecord = freshRecord ?? record;
|
|
4321
4337
|
const observationTokens = currentRecord.observationTokenCount ?? 0;
|
|
4322
|
-
const reflectThreshold = getMaxThreshold(this.
|
|
4338
|
+
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(currentRecord));
|
|
4323
4339
|
const bufferActivation = this.reflectionConfig.bufferActivation ?? 0.5;
|
|
4324
4340
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4325
4341
|
const cycleId = `reflect-buf-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
@@ -4348,7 +4364,7 @@ var ReflectorRunner = class {
|
|
|
4348
4364
|
recordId: record.id,
|
|
4349
4365
|
threadId: record.threadId ?? "",
|
|
4350
4366
|
threadIds: record.threadId ? [record.threadId] : [],
|
|
4351
|
-
config: this.getObservationMarkerConfig()
|
|
4367
|
+
config: this.getObservationMarkerConfig(currentRecord)
|
|
4352
4368
|
});
|
|
4353
4369
|
void writer.custom(startMarker).catch(() => {
|
|
4354
4370
|
});
|
|
@@ -4460,7 +4476,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4460
4476
|
threadId: freshRecord.threadId ?? "",
|
|
4461
4477
|
generationCount: afterRecord?.generationCount ?? freshRecord.generationCount ?? 0,
|
|
4462
4478
|
observations: afterRecord?.activeObservations,
|
|
4463
|
-
config: this.getObservationMarkerConfig()
|
|
4479
|
+
config: this.getObservationMarkerConfig(freshRecord)
|
|
4464
4480
|
});
|
|
4465
4481
|
void writer.custom(activationMarker).catch(() => {
|
|
4466
4482
|
});
|
|
@@ -4491,7 +4507,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4491
4507
|
observabilityContext
|
|
4492
4508
|
} = opts;
|
|
4493
4509
|
const lockKey = this.buffering.getLockKey(record.threadId, record.resourceId);
|
|
4494
|
-
const reflectThreshold = getMaxThreshold(this.
|
|
4510
|
+
const reflectThreshold = getMaxThreshold(this.getEffectiveReflectionTokens(record));
|
|
4495
4511
|
if (this.buffering.isAsyncReflectionEnabled() && observationTokens < reflectThreshold) {
|
|
4496
4512
|
const shouldTrigger = (() => {
|
|
4497
4513
|
if (!this.buffering.isAsyncReflectionEnabled()) return false;
|
|
@@ -4570,7 +4586,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
4570
4586
|
recordId: record.id,
|
|
4571
4587
|
threadId,
|
|
4572
4588
|
threadIds: [threadId],
|
|
4573
|
-
config: this.getObservationMarkerConfig()
|
|
4589
|
+
config: this.getObservationMarkerConfig(record)
|
|
4574
4590
|
});
|
|
4575
4591
|
await writer.custom(startMarker).catch(() => {
|
|
4576
4592
|
});
|
|
@@ -8606,6 +8622,10 @@ function getOmObservabilityContext(args) {
|
|
|
8606
8622
|
metrics: args.metrics
|
|
8607
8623
|
};
|
|
8608
8624
|
}
|
|
8625
|
+
var GATEWAY_STATE_KEY = "__isGatewayModel";
|
|
8626
|
+
function isMastraGatewayModel(model) {
|
|
8627
|
+
return model instanceof ModelRouterLanguageModel && model.gatewayId === "mastra";
|
|
8628
|
+
}
|
|
8609
8629
|
var ObservationalMemoryProcessor = class {
|
|
8610
8630
|
id = "observational-memory";
|
|
8611
8631
|
name = "Observational Memory";
|
|
@@ -8641,6 +8661,11 @@ var ObservationalMemoryProcessor = class {
|
|
|
8641
8661
|
omDebug(`[OM:processInputStep:NO-CONTEXT] getThreadContext returned null \u2014 returning early`);
|
|
8642
8662
|
return messageList;
|
|
8643
8663
|
}
|
|
8664
|
+
if (isMastraGatewayModel(model)) {
|
|
8665
|
+
state[GATEWAY_STATE_KEY] = true;
|
|
8666
|
+
omDebug(`[OM:processInputStep:GATEWAY] gateway handles OM \u2014 skipping local processing`);
|
|
8667
|
+
return messageList;
|
|
8668
|
+
}
|
|
8644
8669
|
const { threadId, resourceId } = context;
|
|
8645
8670
|
const memoryContext = parseMemoryRequestContext(requestContext);
|
|
8646
8671
|
const readOnly = memoryContext?.memoryConfig?.readOnly;
|
|
@@ -8757,6 +8782,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
8757
8782
|
const state = _state ?? {};
|
|
8758
8783
|
const context = this.engine.getThreadContext(requestContext, messageList);
|
|
8759
8784
|
if (!context) return messageList;
|
|
8785
|
+
if (state[GATEWAY_STATE_KEY]) return messageList;
|
|
8760
8786
|
const observabilityContext = getOmObservabilityContext(args);
|
|
8761
8787
|
state.__omObservabilityContext = observabilityContext;
|
|
8762
8788
|
return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
|
|
@@ -8808,5 +8834,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
8808
8834
|
}
|
|
8809
8835
|
|
|
8810
8836
|
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
|
|
8811
|
-
//# sourceMappingURL=chunk-
|
|
8812
|
-
//# sourceMappingURL=chunk-
|
|
8837
|
+
//# sourceMappingURL=chunk-42AZEBIK.js.map
|
|
8838
|
+
//# sourceMappingURL=chunk-42AZEBIK.js.map
|