@mastra/memory 1.10.1-alpha.3 → 1.11.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 +66 -0
- package/dist/{chunk-SKRONGCV.js → chunk-D4D6ZFBQ.js} +355 -105
- package/dist/chunk-D4D6ZFBQ.js.map +1 -0
- package/dist/{chunk-DTAZSLVU.cjs → chunk-VINRPDYQ.cjs} +355 -105
- package/dist/chunk-VINRPDYQ.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +47 -47
- package/dist/docs/references/docs-memory-observational-memory.md +49 -4
- package/dist/docs/references/reference-memory-observational-memory.md +32 -6
- package/dist/index.cjs +577 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +570 -29
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-XIZTJN3S.cjs → observational-memory-FATH657E.cjs} +26 -26
- package/dist/{observational-memory-XIZTJN3S.cjs.map → observational-memory-FATH657E.cjs.map} +1 -1
- package/dist/{observational-memory-UGDENJPE.js → observational-memory-SN7GKMHZ.js} +3 -3
- package/dist/{observational-memory-UGDENJPE.js.map → observational-memory-SN7GKMHZ.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/base.d.ts +9 -0
- package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +2 -0
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +4 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +27 -2
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts +14 -3
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts +8 -12
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +11 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/tracing.d.ts +17 -0
- package/dist/processors/observational-memory/tracing.d.ts.map +1 -0
- package/dist/processors/observational-memory/types.d.ts +19 -1
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/tools/om-tools.d.ts +96 -4
- package/dist/tools/om-tools.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-DTAZSLVU.cjs.map +0 -1
- package/dist/chunk-SKRONGCV.js.map +0 -1
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.11.0",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"ModelByInputTokens": {
|
|
6
6
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
8
|
-
"line":
|
|
7
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
8
|
+
"line": 666
|
|
9
9
|
},
|
|
10
10
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
11
11
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
12
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js"
|
|
13
13
|
},
|
|
14
14
|
"ObservationalMemory": {
|
|
15
15
|
"types": "dist/processors/index.d.ts",
|
|
16
|
-
"implementation": "dist/chunk-
|
|
17
|
-
"line":
|
|
16
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
17
|
+
"line": 5698
|
|
18
18
|
},
|
|
19
19
|
"ObservationalMemoryProcessor": {
|
|
20
20
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
22
|
-
"line":
|
|
21
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
22
|
+
"line": 8220
|
|
23
23
|
},
|
|
24
24
|
"TokenCounter": {
|
|
25
25
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
27
|
-
"line":
|
|
26
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
27
|
+
"line": 5250
|
|
28
28
|
},
|
|
29
29
|
"buildObserverPrompt": {
|
|
30
30
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
32
|
-
"line":
|
|
31
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
32
|
+
"line": 3277
|
|
33
33
|
},
|
|
34
34
|
"buildObserverSystemPrompt": {
|
|
35
35
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
37
|
-
"line":
|
|
36
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
37
|
+
"line": 2751
|
|
38
38
|
},
|
|
39
39
|
"combineObservationGroupRanges": {
|
|
40
40
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
42
|
-
"line":
|
|
41
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
42
|
+
"line": 755
|
|
43
43
|
},
|
|
44
44
|
"deriveObservationGroupProvenance": {
|
|
45
45
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
47
|
-
"line":
|
|
46
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
47
|
+
"line": 782
|
|
48
48
|
},
|
|
49
49
|
"extractCurrentTask": {
|
|
50
50
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
52
|
-
"line":
|
|
51
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
52
|
+
"line": 3391
|
|
53
53
|
},
|
|
54
54
|
"formatMessagesForObserver": {
|
|
55
55
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
57
|
-
"line":
|
|
56
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
57
|
+
"line": 3017
|
|
58
58
|
},
|
|
59
59
|
"getObservationsAsOf": {
|
|
60
60
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
62
|
-
"line":
|
|
61
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
62
|
+
"line": 8398
|
|
63
63
|
},
|
|
64
64
|
"hasCurrentTaskSection": {
|
|
65
65
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
67
|
-
"line":
|
|
66
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
67
|
+
"line": 3379
|
|
68
68
|
},
|
|
69
69
|
"injectAnchorIds": {
|
|
70
70
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
72
|
-
"line":
|
|
71
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
72
|
+
"line": 2308
|
|
73
73
|
},
|
|
74
74
|
"optimizeObservationsForContext": {
|
|
75
75
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
77
|
-
"line":
|
|
76
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
77
|
+
"line": 3402
|
|
78
78
|
},
|
|
79
79
|
"parseAnchorId": {
|
|
80
80
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
82
|
-
"line":
|
|
81
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
82
|
+
"line": 2281
|
|
83
83
|
},
|
|
84
84
|
"parseObservationGroups": {
|
|
85
85
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
87
|
-
"line":
|
|
86
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
87
|
+
"line": 727
|
|
88
88
|
},
|
|
89
89
|
"parseObserverOutput": {
|
|
90
90
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
92
|
-
"line":
|
|
91
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
92
|
+
"line": 3287
|
|
93
93
|
},
|
|
94
94
|
"reconcileObservationGroupsFromReflection": {
|
|
95
95
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
97
|
-
"line":
|
|
96
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
97
|
+
"line": 809
|
|
98
98
|
},
|
|
99
99
|
"renderObservationGroupsForReflection": {
|
|
100
100
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
102
|
-
"line":
|
|
101
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
102
|
+
"line": 762
|
|
103
103
|
},
|
|
104
104
|
"stripEphemeralAnchorIds": {
|
|
105
105
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
107
|
-
"line":
|
|
106
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
107
|
+
"line": 2338
|
|
108
108
|
},
|
|
109
109
|
"stripObservationGroups": {
|
|
110
110
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
112
|
-
"line":
|
|
111
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
112
|
+
"line": 749
|
|
113
113
|
},
|
|
114
114
|
"wrapInObservationGroup": {
|
|
115
115
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
117
|
-
"line":
|
|
116
|
+
"implementation": "dist/chunk-D4D6ZFBQ.js",
|
|
117
|
+
"line": 720
|
|
118
118
|
},
|
|
119
119
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
120
120
|
"types": "dist/processors/index.d.ts",
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"processors": {
|
|
162
162
|
"index": "dist/processors/index.js",
|
|
163
163
|
"chunks": [
|
|
164
|
-
"chunk-
|
|
164
|
+
"chunk-D4D6ZFBQ.js",
|
|
165
165
|
"chunk-LSJJAJAF.js"
|
|
166
166
|
]
|
|
167
167
|
}
|
|
@@ -95,27 +95,72 @@ The result is a three-tier system:
|
|
|
95
95
|
|
|
96
96
|
Normal OM compresses messages into observations, which is great for staying on task — but the original wording is gone. Retrieval mode fixes this by keeping each observation group linked to the raw messages that produced it. When the agent needs exact wording, tool output, or chronology that the summary compressed away, it can call a `recall` tool to page through the source messages.
|
|
97
97
|
|
|
98
|
+
#### Browsing only
|
|
99
|
+
|
|
100
|
+
Set `retrieval: true` to enable the recall tool for browsing raw messages. No vector store needed. By default, the recall tool can browse across all threads for the current resource.
|
|
101
|
+
|
|
98
102
|
```typescript
|
|
99
103
|
const memory = new Memory({
|
|
100
104
|
options: {
|
|
101
105
|
observationalMemory: {
|
|
102
106
|
model: 'google/gemini-2.5-flash',
|
|
103
|
-
scope: 'thread',
|
|
104
107
|
retrieval: true,
|
|
105
108
|
},
|
|
106
109
|
},
|
|
107
110
|
})
|
|
108
111
|
```
|
|
109
112
|
|
|
113
|
+
#### With semantic search
|
|
114
|
+
|
|
115
|
+
Set `retrieval: { vector: true }` to also enable semantic search. This reuses the vector store and embedder already configured on your Memory instance:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const memory = new Memory({
|
|
119
|
+
storage,
|
|
120
|
+
vector: myVectorStore,
|
|
121
|
+
embedder: myEmbedder,
|
|
122
|
+
options: {
|
|
123
|
+
observationalMemory: {
|
|
124
|
+
model: 'google/gemini-2.5-flash',
|
|
125
|
+
retrieval: { vector: true },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
When vector search is configured, new observation groups are automatically indexed at buffer time and during synchronous observation (fire-and-forget, non-blocking). Semantic search returns observation-group matches with their raw source message ID ranges, so the recall tool can show the summarized memory alongside where it came from.
|
|
132
|
+
|
|
133
|
+
#### Restricting to the current thread
|
|
134
|
+
|
|
135
|
+
By default, the recall tool scope is `'resource'` — the agent can list threads, browse other threads, and search across all conversations. Set `scope: 'thread'` to restrict the agent to only the current thread:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const memory = new Memory({
|
|
139
|
+
options: {
|
|
140
|
+
observationalMemory: {
|
|
141
|
+
model: 'google/gemini-2.5-flash',
|
|
142
|
+
retrieval: { vector: true, scope: 'thread' },
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### What retrieval enables
|
|
149
|
+
|
|
110
150
|
With retrieval mode enabled, OM:
|
|
111
151
|
|
|
112
152
|
- Stores a `range` (e.g. `startId:endId`) on each observation group pointing to the messages it was derived from
|
|
153
|
+
|
|
113
154
|
- Keeps range metadata visible in the agent's context so the agent knows which observations map to which messages
|
|
114
|
-
- Registers a `recall` tool the agent can call to page through the raw messages behind any range
|
|
115
155
|
|
|
116
|
-
|
|
156
|
+
- Registers a `recall` tool the agent can call to:
|
|
157
|
+
|
|
158
|
+
- Page through the raw messages behind any observation group range
|
|
159
|
+
- Search by semantic similarity (`mode: "search"` with a `query` string) — requires `vector: true`
|
|
160
|
+
- List all threads (`mode: "threads"`), browse other threads (`threadId`), and search across all threads (default `scope: 'resource'`)
|
|
161
|
+
- When `scope: 'thread'`: restrict browsing and search to the current thread only
|
|
117
162
|
|
|
118
|
-
See the [recall tool reference](https://mastra.ai/reference/memory/observational-memory) for the full API (detail levels, part indexing, pagination, and token limiting).
|
|
163
|
+
See the [recall tool reference](https://mastra.ai/reference/memory/observational-memory) for the full API (detail levels, part indexing, pagination, cross-thread browsing, and token limiting).
|
|
119
164
|
|
|
120
165
|
## Models
|
|
121
166
|
|
|
@@ -38,7 +38,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
38
38
|
|
|
39
39
|
**shareTokenBudget** (`boolean`): Share the token budget between messages and observations. When enabled, the total budget is \`observation.messageTokens + reflection.observationTokens\`. Messages can use more space when observations are small, and vice versa. This maximizes context usage through flexible allocation. \`shareTokenBudget\` is not yet compatible with async buffering. You must set \`observation: { bufferTokens: false }\` when using this option (this is a temporary limitation). (Default: `false`)
|
|
40
40
|
|
|
41
|
-
**retrieval** (`boolean`): \*\*Experimental.\*\* Enable retrieval-mode observation groups as durable pointers to raw message history.
|
|
41
|
+
**retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource' }`): \*\*Experimental.\*\* Enable retrieval-mode observation groups as durable pointers to raw message history. \`true\` enables cross-thread browsing by default. \`{ vector: true }\` also enables semantic search using Memory's vector store and embedder. \`{ scope: 'thread' }\` restricts the recall tool to the current thread only. Default scope is \`'resource'\`. (Default: `false`)
|
|
42
42
|
|
|
43
43
|
**observation** (`ObservationalMemoryObservationConfig`): Configuration for the observation step. Controls when the Observer agent runs and how it behaves.
|
|
44
44
|
|
|
@@ -578,21 +578,31 @@ The standalone `ObservationalMemory` class accepts all the same options as the `
|
|
|
578
578
|
|
|
579
579
|
## Recall tool
|
|
580
580
|
|
|
581
|
-
When `retrieval
|
|
581
|
+
When `retrieval` is set (any truthy value), a `recall` tool is registered so the agent can page through raw messages behind observation group ranges. By default (scope `'resource'`), the tool supports listing threads (`mode: "threads"`), browsing other threads (`threadId`), and cross-thread search. With `retrieval: { vector: true }`, semantic search is available (`mode: "search"`). Set `scope: 'thread'` to restrict the tool to the current thread only. The tool is automatically added to the agent's tool list — no manual registration is needed.
|
|
582
582
|
|
|
583
583
|
### Parameters
|
|
584
584
|
|
|
585
|
-
**
|
|
585
|
+
**mode** (`'messages' | 'threads' | 'search'`): What to retrieve. \`"messages"\` (default) pages through message history. \`"threads"\` lists all threads for the current user. \`"search"\` finds messages by semantic similarity across all threads (requires vector store and embedder). (Default: `'messages'`)
|
|
586
586
|
|
|
587
|
-
**
|
|
587
|
+
**query** (`string`): Search query for \`mode: "search"\`. Finds messages semantically similar to this text across all threads for the current user.
|
|
588
588
|
|
|
589
|
-
**
|
|
589
|
+
**cursor** (`string`): A message ID to anchor the recall query. Required for \`mode: "messages"\` when browsing the current thread. Extract the start or end ID from an observation group range (e.g. from \`\_range: \\\`startId:endId\\\`\_\`, use either \`startId\` or \`endId\`). If a range string is passed directly, the tool returns a hint explaining how to extract the correct ID. Can be omitted when \`threadId\` is provided to start reading from the beginning of that thread.
|
|
590
|
+
|
|
591
|
+
**threadId** (`string`): Browse a different thread by its ID. Use \`mode: "threads"\` first to discover thread IDs. When provided without a \`cursor\`, reading starts from the beginning of the thread.
|
|
592
|
+
|
|
593
|
+
**page** (`number`): Pagination offset. For messages: positive values page forward from cursor, negative values page backward. For threads: page number (0-indexed). \`0\` is treated as \`1\` for messages. (Default: `1`)
|
|
594
|
+
|
|
595
|
+
**limit** (`number`): Maximum number of items to return per page. (Default: `20`)
|
|
590
596
|
|
|
591
597
|
**detail** (`'low' | 'high'`): Controls how much content is shown per message part. \`'low'\` shows truncated text and tool names with positional indices (\`\[p0]\`, \`\[p1]\`). \`'high'\` shows full content including tool arguments and results, clamped to one part per call with continuation hints. (Default: `'low'`)
|
|
592
598
|
|
|
593
599
|
**partIndex** (`number`): Fetch a single message part at full detail by its positional index. Use this when a low-detail recall shows an interesting part at \`\[p1]\` — call again with \`partIndex: 1\` to see the full content without loading every part.
|
|
594
600
|
|
|
595
|
-
|
|
601
|
+
**before** (`string`): For \`mode: "threads"\` only. Filter to threads created before this date. Accepts ISO 8601 format (e.g. \`"2026-03-15"\`, \`"2026-03-10T00:00:00Z"\`).
|
|
602
|
+
|
|
603
|
+
**after** (`string`): For \`mode: "threads"\` only. Filter to threads created after this date. Accepts ISO 8601 format (e.g. \`"2026-03-01"\`, \`"2026-03-10T00:00:00Z"\`).
|
|
604
|
+
|
|
605
|
+
### Returns (messages mode)
|
|
596
606
|
|
|
597
607
|
**messages** (`string`): Formatted message content. Format depends on the \`detail\` level.
|
|
598
608
|
|
|
@@ -612,6 +622,22 @@ When `retrieval: true` is set with `scope: 'thread'`, OM registers a `recall` to
|
|
|
612
622
|
|
|
613
623
|
**tokenOffset** (`number`): Approximate number of tokens that were trimmed when \`truncated\` is true.
|
|
614
624
|
|
|
625
|
+
### Returns (threads mode)
|
|
626
|
+
|
|
627
|
+
**threads** (`string`): Formatted thread listing. Each thread shows its title, ID, and dates. The current thread is marked with \`← current\`.
|
|
628
|
+
|
|
629
|
+
**count** (`number`): Number of threads returned.
|
|
630
|
+
|
|
631
|
+
**page** (`number`): The page number returned.
|
|
632
|
+
|
|
633
|
+
**hasMore** (`boolean`): Whether more threads exist on the next page.
|
|
634
|
+
|
|
635
|
+
### Returns (search mode)
|
|
636
|
+
|
|
637
|
+
**results** (`string`): Formatted search results grouped by thread. Each result shows the thread title, thread ID, relevance score, message preview, and a cursor ID for browsing into that thread.
|
|
638
|
+
|
|
639
|
+
**count** (`number`): Number of matching messages found.
|
|
640
|
+
|
|
615
641
|
### ModelByInputTokens
|
|
616
642
|
|
|
617
643
|
`ModelByInputTokens` selects a model based on the input token count. It chooses the model for the smallest threshold that covers the actual input size.
|