@mastra/memory 1.18.2 → 1.18.3-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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.18.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(memory): start background buffering of unobserved messages when agent goes idle ([#16694](https://github.com/mastra-ai/mastra/pull/16694))
8
+
9
+ In OM buffering mode, when the agent goes idle (turn.end()), any unobserved messages are now buffered in the background via a fire-and-forget buffer() call. This ensures observations are computed proactively rather than waiting for the next turn's step.prepare().
10
+
3
11
  ## 1.18.2
4
12
 
5
13
  ### Patch Changes
@@ -2447,7 +2447,12 @@ var ObservationTurn = class {
2447
2447
  return this._currentStep;
2448
2448
  }
2449
2449
  /**
2450
- * Finalize the turn: save any remaining messages and return the latest record state.
2450
+ * Finalize the turn: save any remaining messages and return the current cached record.
2451
+ *
2452
+ * When async observation buffering is enabled and there are unobserved messages,
2453
+ * a background buffer operation is kicked off so that observations are computed
2454
+ * proactively while the agent is idle, rather than waiting for the next turn.
2455
+ * The returned record does not wait for that background buffering pass to finish.
2451
2456
  */
2452
2457
  async end() {
2453
2458
  if (this._ended) throw new Error("Turn already ended");
@@ -2458,6 +2463,24 @@ var ObservationTurn = class {
2458
2463
  if (unsavedMessages.length > 0) {
2459
2464
  await this.om.persistMessages(unsavedMessages, this.threadId, this.resourceId);
2460
2465
  }
2466
+ if (this.om.buffering.isAsyncObservationEnabled()) {
2467
+ const allMessages = this.messageList.get.all.db();
2468
+ const record = this._record;
2469
+ const unobservedMessages = this.om.getUnobservedMessages(allMessages, record);
2470
+ if (unobservedMessages.length > 0) {
2471
+ void this.om.buffer({
2472
+ threadId: this.threadId,
2473
+ resourceId: this.resourceId,
2474
+ messages: unobservedMessages,
2475
+ record,
2476
+ writer: this.writer,
2477
+ requestContext: this.requestContext,
2478
+ observabilityContext: this.observabilityContext
2479
+ }).catch((err) => {
2480
+ omDebug(`[OM:turn.end] idle buffer failed: ${err?.message}`);
2481
+ });
2482
+ }
2483
+ }
2461
2484
  return { record: this._record };
2462
2485
  }
2463
2486
  /**
@@ -9737,5 +9760,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
9737
9760
  exports.stripObservationGroups = stripObservationGroups;
9738
9761
  exports.truncateStringByTokens = truncateStringByTokens;
9739
9762
  exports.wrapInObservationGroup = wrapInObservationGroup;
9740
- //# sourceMappingURL=chunk-4AQHFADP.cjs.map
9741
- //# sourceMappingURL=chunk-4AQHFADP.cjs.map
9763
+ //# sourceMappingURL=chunk-BK3AYI7X.cjs.map
9764
+ //# sourceMappingURL=chunk-BK3AYI7X.cjs.map