@mastra/memory 1.11.0-alpha.4 → 1.11.1-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,51 @@
1
1
  # @mastra/memory
2
2
 
3
+ ## 1.11.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed reflected observation groups so their metadata stays compact and marks reflection-derived content. ([#14791](https://github.com/mastra-ai/mastra/pull/14791))
8
+
9
+ - Updated dependencies [[`180aaaf`](https://github.com/mastra-ai/mastra/commit/180aaaf4d0903d33a49bc72de2d40ca69a5bc599)]:
10
+ - @mastra/core@1.18.1-alpha.0
11
+
12
+ ## 1.11.0
13
+
14
+ ### Minor Changes
15
+
16
+ - feat(memory): add recall-tool history retrieval for agents using observational memory ([#14567](https://github.com/mastra-ai/mastra/pull/14567))
17
+
18
+ Agents that use observational memory can now use the `recall` tool to retrieve history from past conversations, including raw messages, thread listings, and indexed observation-group memories.
19
+
20
+ Enable observational-memory retrieval when listing tools:
21
+
22
+ ```ts
23
+ const tools = await memory.listTools({
24
+ threadId: 'thread_123',
25
+ resourceId: 'resource_abc',
26
+ observationalMemory: {
27
+ retrieval: { vector: true, scope: 'resource' },
28
+ },
29
+ });
30
+ ```
31
+
32
+ With retrieval enabled, `recall` can browse the current thread, list threads for the current resource, and search indexed observation groups with source ranges.
33
+
34
+ ### Patch Changes
35
+
36
+ - Fixed OM repro capture so recordings keep writing usable artifacts even when live state contains circular values. ([#14744](https://github.com/mastra-ai/mastra/pull/14744))
37
+
38
+ - Fixed observational memory response ID rotation at buffered chunk boundaries so assistant output continues in a fresh message slot. ([#14745](https://github.com/mastra-ai/mastra/pull/14745))
39
+
40
+ - The internal architecture of observational memory has been refactored. The public API and behavior remain unchanged. ([#14453](https://github.com/mastra-ai/mastra/pull/14453))
41
+
42
+ - Fixed observational memory tracing spans so observer and reflector runner work is attached to the active agent trace again. ([#14749](https://github.com/mastra-ai/mastra/pull/14749))
43
+
44
+ - Improved observational memory continuation prompts to reduce leaked context-management language in long conversations. ([#14650](https://github.com/mastra-ai/mastra/pull/14650))
45
+
46
+ - Updated dependencies [[`dc514a8`](https://github.com/mastra-ai/mastra/commit/dc514a83dba5f719172dddfd2c7b858e4943d067), [`e333b77`](https://github.com/mastra-ai/mastra/commit/e333b77e2d76ba57ccec1818e08cebc1993469ff), [`dc9fc19`](https://github.com/mastra-ai/mastra/commit/dc9fc19da4437f6b508cc355f346a8856746a76b), [`60a224d`](https://github.com/mastra-ai/mastra/commit/60a224dd497240e83698cfa5bfd02e3d1d854844), [`fbf22a7`](https://github.com/mastra-ai/mastra/commit/fbf22a7ad86bcb50dcf30459f0d075e51ddeb468), [`f16d92c`](https://github.com/mastra-ai/mastra/commit/f16d92c677a119a135cebcf7e2b9f51ada7a9df4), [`949b7bf`](https://github.com/mastra-ai/mastra/commit/949b7bfd4e40f2b2cba7fef5eb3f108a02cfe938), [`404fea1`](https://github.com/mastra-ai/mastra/commit/404fea13042181f0b0c73a101392ac87c79ceae2), [`ebf5047`](https://github.com/mastra-ai/mastra/commit/ebf5047e825c38a1a356f10b214c1d4260dfcd8d), [`12c647c`](https://github.com/mastra-ai/mastra/commit/12c647cf3a26826eb72d40b42e3c8356ceae16ed), [`d084b66`](https://github.com/mastra-ai/mastra/commit/d084b6692396057e83c086b954c1857d20b58a14), [`79c699a`](https://github.com/mastra-ai/mastra/commit/79c699acf3cd8a77e11c55530431f48eb48456e9), [`62757b6`](https://github.com/mastra-ai/mastra/commit/62757b6db6e8bb86569d23ad0b514178f57053f8), [`675f15b`](https://github.com/mastra-ai/mastra/commit/675f15b7eaeea649158d228ea635be40480c584d), [`b174c63`](https://github.com/mastra-ai/mastra/commit/b174c63a093108d4e53b9bc89a078d9f66202b3f), [`819f03c`](https://github.com/mastra-ai/mastra/commit/819f03c25823373b32476413bd76be28a5d8705a), [`04160ee`](https://github.com/mastra-ai/mastra/commit/04160eedf3130003cf842ad08428c8ff69af4cc1), [`2c27503`](https://github.com/mastra-ai/mastra/commit/2c275032510d131d2cde47f99953abf0fe02c081), [`424a1df`](https://github.com/mastra-ai/mastra/commit/424a1df7bee59abb5c83717a54807fdd674a6224), [`3d70b0b`](https://github.com/mastra-ai/mastra/commit/3d70b0b3524d817173ad870768f259c06d61bd23), [`eef7cb2`](https://github.com/mastra-ai/mastra/commit/eef7cb2abe7ef15951e2fdf792a5095c6c643333), [`260fe12`](https://github.com/mastra-ai/mastra/commit/260fe1295fe7354e39d6def2775e0797a7a277f0), [`12c88a6`](https://github.com/mastra-ai/mastra/commit/12c88a6e32bf982c2fe0c6af62e65a3414519a75), [`43595bf`](https://github.com/mastra-ai/mastra/commit/43595bf7b8df1a6edce7a23b445b5124d2a0b473), [`78670e9`](https://github.com/mastra-ai/mastra/commit/78670e97e76d7422cf7025faf371b2aeafed860d), [`e8a5b0b`](https://github.com/mastra-ai/mastra/commit/e8a5b0b9bc94d12dee4150095512ca27a288d778), [`3b45a13`](https://github.com/mastra-ai/mastra/commit/3b45a138d09d040779c0aba1edbbfc1b57442d23), [`d400e7c`](https://github.com/mastra-ai/mastra/commit/d400e7c8b8d7afa6ba2c71769eace4048e3cef8e), [`f58d1a7`](https://github.com/mastra-ai/mastra/commit/f58d1a7a457588a996c3ecb53201a68f3d28c432), [`a49a929`](https://github.com/mastra-ai/mastra/commit/a49a92904968b4fc67e01effee8c7c8d0464ba85), [`8127d96`](https://github.com/mastra-ai/mastra/commit/8127d96280492e335d49b244501088dfdd59a8f1)]:
47
+ - @mastra/core@1.18.0
48
+
3
49
  ## 1.11.0-alpha.4
4
50
 
5
51
  ### Minor Changes
@@ -717,10 +717,10 @@ function stripReflectionGroupMetadata(body) {
717
717
  function generateAnchorId() {
718
718
  return randomBytes(8).toString("hex");
719
719
  }
720
- function wrapInObservationGroup(observations, range, id = generateAnchorId(), sourceGroupIds) {
720
+ function wrapInObservationGroup(observations, range, id = generateAnchorId(), _sourceGroupIds, kind) {
721
721
  const content = observations.trim();
722
- const sourceGroupIdsAttr = sourceGroupIds?.length ? ` source-group-ids="${sourceGroupIds.join(",")}"` : "";
723
- return `<observation-group id="${id}" range="${range}"${sourceGroupIdsAttr}>
722
+ const kindAttr = kind ? ` kind="${kind}"` : "";
723
+ return `<observation-group id="${id}" range="${range}"${kindAttr}>
724
724
  ${content}
725
725
  </observation-group>`;
726
726
  }
@@ -740,8 +740,8 @@ function parseObservationGroups(observations) {
740
740
  groups.push({
741
741
  id,
742
742
  range,
743
- content: match[2].trim(),
744
- sourceGroupIds: attributes["source-group-ids"]?.split(",").map((part) => part.trim()).filter(Boolean)
743
+ kind: attributes.kind,
744
+ content: match[2].trim()
745
745
  });
746
746
  }
747
747
  return groups;
@@ -752,12 +752,22 @@ function stripObservationGroups(observations) {
752
752
  }
753
753
  return observations.replace(OBSERVATION_GROUP_PATTERN, (_match, _attributes, content) => content.trim()).replace(/\n{3,}/g, "\n\n").trim();
754
754
  }
755
+ function getRangeSegments(range) {
756
+ return range.split(",").map((segment) => segment.trim()).filter(Boolean);
757
+ }
755
758
  function combineObservationGroupRanges(groups) {
756
- return Array.from(
757
- new Set(
758
- groups.flatMap((group) => group.range.split(",")).map((range) => range.trim()).filter(Boolean)
759
- )
760
- ).join(",");
759
+ const segments = groups.flatMap((group) => getRangeSegments(group.range));
760
+ if (segments.length === 0) {
761
+ return "";
762
+ }
763
+ const firstSegment = segments[0];
764
+ const lastSegment = segments[segments.length - 1];
765
+ const firstStart = firstSegment?.split(":")[0]?.trim();
766
+ const lastEnd = lastSegment?.split(":").at(-1)?.trim();
767
+ if (firstStart && lastEnd) {
768
+ return `${firstStart}:${lastEnd}`;
769
+ }
770
+ return Array.from(new Set(segments)).join(",");
761
771
  }
762
772
  function renderObservationGroupsForReflection(observations) {
763
773
  const groups = parseObservationGroups(observations);
@@ -794,15 +804,12 @@ function deriveObservationGroupProvenance(content, groups) {
794
804
  });
795
805
  const fallbackGroup = groups[Math.min(index, groups.length - 1)];
796
806
  const resolvedGroups = matchingGroups.length > 0 ? matchingGroups : fallbackGroup ? [fallbackGroup] : [];
797
- const sourceGroupIds = Array.from(
798
- new Set(resolvedGroups.flatMap((group) => [group.id, ...group.sourceGroupIds ?? []]))
799
- );
800
807
  const canonicalGroupId = getCanonicalGroupId(section.heading, index);
801
808
  return {
802
809
  id: canonicalGroupId,
803
810
  range: combineObservationGroupRanges(resolvedGroups),
804
- content: section.body,
805
- sourceGroupIds
811
+ kind: "reflection",
812
+ content: section.body
806
813
  };
807
814
  });
808
815
  }
@@ -817,13 +824,14 @@ function reconcileObservationGroupsFromReflection(content, sourceObservations) {
817
824
  }
818
825
  const derivedGroups = deriveObservationGroupProvenance(normalizedContent, sourceGroups);
819
826
  if (derivedGroups.length > 0) {
820
- return derivedGroups.map((group) => wrapInObservationGroup(group.content, group.range, group.id, group.sourceGroupIds)).join("\n\n");
827
+ return derivedGroups.map((group) => wrapInObservationGroup(group.content, group.range, group.id, void 0, group.kind)).join("\n\n");
821
828
  }
822
829
  return wrapInObservationGroup(
823
830
  normalizedContent,
824
831
  combineObservationGroupRanges(sourceGroups),
825
832
  generateAnchorId(),
826
- Array.from(new Set(sourceGroups.flatMap((group) => [group.id, ...group.sourceGroupIds ?? []])))
833
+ void 0,
834
+ "reflection"
827
835
  );
828
836
  }
829
837
 
@@ -3821,11 +3829,10 @@ Aim for a 2/10 detail level. Fewer, more generic observations are better than ma
3821
3829
  };
3822
3830
  function buildReflectorPrompt(observations, manualPrompt, compressionLevel, skipContinuationHints) {
3823
3831
  const level = typeof compressionLevel === "number" ? compressionLevel : compressionLevel ? 1 : 0;
3824
- const reflectionView = renderObservationGroupsForReflection(observations) ?? observations;
3825
- const anchoredObservations = injectAnchorIds(reflectionView);
3832
+ const reflectionView = stripObservationGroups(observations);
3826
3833
  let prompt = `## OBSERVATIONS TO REFLECT ON
3827
3834
 
3828
- ${anchoredObservations}
3835
+ ${reflectionView}
3829
3836
 
3830
3837
  ---
3831
3838
 
@@ -8418,5 +8425,5 @@ function getObservationsAsOf(activeObservations, asOf) {
8418
8425
  }
8419
8426
 
8420
8427
  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 };
8421
- //# sourceMappingURL=chunk-D4D6ZFBQ.js.map
8422
- //# sourceMappingURL=chunk-D4D6ZFBQ.js.map
8428
+ //# sourceMappingURL=chunk-2NZR2XHO.js.map
8429
+ //# sourceMappingURL=chunk-2NZR2XHO.js.map