@mastra/memory 1.21.3-alpha.1 → 1.22.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 +48 -0
- package/dist/chunk-EGRHWZRV.js +3 -0
- package/dist/{chunk-PZ5AY32C.js.map → chunk-EGRHWZRV.js.map} +1 -1
- package/dist/chunk-KKP6DG65.js +30403 -0
- package/dist/chunk-KKP6DG65.js.map +1 -0
- package/dist/chunk-KXO2ZPM3.cjs +30468 -0
- package/dist/chunk-KXO2ZPM3.cjs.map +1 -0
- package/dist/chunk-NKIQRCOM.cjs +4 -0
- package/dist/{chunk-Q7SFCCGT.cjs.map → chunk-NKIQRCOM.cjs.map} +1 -1
- package/dist/{constants-DVRTNEGY.js → constants-RMCTOZE3.js} +2 -2
- package/dist/{constants-DVRTNEGY.js.map → constants-RMCTOZE3.js.map} +1 -1
- package/dist/{constants-JS5SS7GS.cjs → constants-ZEKSZ4UM.cjs} +2 -2
- package/dist/{constants-JS5SS7GS.cjs.map → constants-ZEKSZ4UM.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +94 -59
- package/dist/docs/references/docs-memory-observational-memory.md +114 -0
- package/dist/docs/references/docs-memory-working-memory.md +2 -0
- package/dist/docs/references/reference-memory-observational-memory.md +90 -0
- package/dist/index.cjs +35 -49119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -49109
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-2KSGEMXM.cjs → observational-memory-GSJXSJXG.cjs} +34 -26
- package/dist/{observational-memory-2KSGEMXM.cjs.map → observational-memory-GSJXSJXG.cjs.map} +1 -1
- package/dist/observational-memory-PBLNZABH.js +4 -0
- package/dist/{observational-memory-VZDCB747.js.map → observational-memory-PBLNZABH.js.map} +1 -1
- package/dist/processors/index.cjs +32 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/built-in-extractors.d.ts +15 -0
- package/dist/processors/observational-memory/built-in-extractors.d.ts.map +1 -0
- package/dist/processors/observational-memory/extracted-values.d.ts +44 -0
- package/dist/processors/observational-memory/extracted-values.d.ts.map +1 -0
- package/dist/processors/observational-memory/extraction-runner.d.ts +22 -0
- package/dist/processors/observational-memory/extraction-runner.d.ts.map +1 -0
- package/dist/processors/observational-memory/extractor.d.ts +73 -0
- package/dist/processors/observational-memory/extractor.d.ts.map +1 -0
- package/dist/processors/observational-memory/index.d.ts +3 -0
- package/dist/processors/observational-memory/index.d.ts.map +1 -1
- package/dist/processors/observational-memory/markers.d.ts +10 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +4 -0
- package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/base.d.ts +2 -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 +4 -0
- package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +20 -0
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +3 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +9 -0
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-agent.d.ts +20 -10
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-runner.d.ts +26 -0
- package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-agent.d.ts +4 -7
- package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +12 -2
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/temporary-memory.d.ts +8 -0
- package/dist/processors/observational-memory/temporary-memory.d.ts.map +1 -0
- package/dist/processors/observational-memory/types.d.ts +55 -0
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/working-memory-extractor.d.ts +5 -0
- package/dist/processors/observational-memory/working-memory-extractor.d.ts.map +1 -0
- package/dist/{working-memory-state-Y2SCKCNU.cjs → working-memory-state-LDPWYVCG.cjs} +2 -2
- package/dist/{working-memory-state-Y2SCKCNU.cjs.map → working-memory-state-LDPWYVCG.cjs.map} +1 -1
- package/dist/{working-memory-state-J7ASTNXX.js → working-memory-state-OMSMSYAW.js} +2 -2
- package/dist/{working-memory-state-J7ASTNXX.js.map → working-memory-state-OMSMSYAW.js.map} +1 -1
- package/package.json +7 -7
- package/dist/chunk-FQLQMPJY.cjs +0 -10074
- package/dist/chunk-FQLQMPJY.cjs.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-Q7SFCCGT.cjs +0 -11
- package/dist/chunk-X7DOZRJK.js +0 -10042
- package/dist/chunk-X7DOZRJK.js.map +0 -1
- package/dist/observational-memory-VZDCB747.js +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-NKIQRCOM.cjs"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVATION_RETRIEVAL_INSTRUCTIONS } from './chunk-LSJJAJAF.js';
|
|
2
|
-
//# sourceMappingURL=constants-
|
|
3
|
-
//# sourceMappingURL=constants-
|
|
2
|
+
//# sourceMappingURL=constants-RMCTOZE3.js.map
|
|
3
|
+
//# sourceMappingURL=constants-RMCTOZE3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-RMCTOZE3.js"}
|
|
@@ -24,5 +24,5 @@ Object.defineProperty(exports, "OBSERVATION_RETRIEVAL_INSTRUCTIONS", {
|
|
|
24
24
|
enumerable: true,
|
|
25
25
|
get: function () { return chunkD4J4XPGM_cjs.OBSERVATION_RETRIEVAL_INSTRUCTIONS; }
|
|
26
26
|
});
|
|
27
|
-
//# sourceMappingURL=constants-
|
|
28
|
-
//# sourceMappingURL=constants-
|
|
27
|
+
//# sourceMappingURL=constants-ZEKSZ4UM.cjs.map
|
|
28
|
+
//# sourceMappingURL=constants-ZEKSZ4UM.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-ZEKSZ4UM.cjs"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,120 +1,130 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.22.0-alpha.3",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
|
+
"Extractor": {
|
|
6
|
+
"types": "dist/processors/index.d.ts",
|
|
7
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
8
|
+
"line": 316
|
|
9
|
+
},
|
|
5
10
|
"ModelByInputTokens": {
|
|
6
11
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
8
|
-
"line":
|
|
12
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
13
|
+
"line": 1354
|
|
9
14
|
},
|
|
10
15
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
11
16
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
17
|
+
"implementation": "dist/chunk-KKP6DG65.js"
|
|
13
18
|
},
|
|
14
19
|
"ObservationalMemory": {
|
|
15
20
|
"types": "dist/processors/index.d.ts",
|
|
16
|
-
"implementation": "dist/chunk-
|
|
17
|
-
"line":
|
|
21
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
22
|
+
"line": 27526
|
|
18
23
|
},
|
|
19
24
|
"ObservationalMemoryProcessor": {
|
|
20
25
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
22
|
-
"line":
|
|
26
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
27
|
+
"line": 30157
|
|
23
28
|
},
|
|
24
29
|
"TokenCounter": {
|
|
25
30
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
27
|
-
"line":
|
|
31
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
32
|
+
"line": 26857
|
|
33
|
+
},
|
|
34
|
+
"WorkingMemoryExtractor": {
|
|
35
|
+
"types": "dist/processors/index.d.ts",
|
|
36
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
37
|
+
"line": 20684
|
|
28
38
|
},
|
|
29
39
|
"buildObserverPrompt": {
|
|
30
40
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
32
|
-
"line":
|
|
41
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
42
|
+
"line": 4465
|
|
33
43
|
},
|
|
34
44
|
"buildObserverSystemPrompt": {
|
|
35
45
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
37
|
-
"line":
|
|
46
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
47
|
+
"line": 3732
|
|
38
48
|
},
|
|
39
49
|
"combineObservationGroupRanges": {
|
|
40
50
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
42
|
-
"line":
|
|
51
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
52
|
+
"line": 1446
|
|
43
53
|
},
|
|
44
54
|
"deriveObservationGroupProvenance": {
|
|
45
55
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
47
|
-
"line":
|
|
56
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
57
|
+
"line": 1480
|
|
48
58
|
},
|
|
49
59
|
"extractCurrentTask": {
|
|
50
60
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
52
|
-
"line":
|
|
61
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
62
|
+
"line": 4588
|
|
53
63
|
},
|
|
54
64
|
"formatMessagesForObserver": {
|
|
55
65
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
57
|
-
"line":
|
|
66
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
67
|
+
"line": 4187
|
|
58
68
|
},
|
|
59
69
|
"getObservationsAsOf": {
|
|
60
70
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
62
|
-
"line":
|
|
71
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
72
|
+
"line": 30379
|
|
63
73
|
},
|
|
64
74
|
"hasCurrentTaskSection": {
|
|
65
75
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
67
|
-
"line":
|
|
76
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
77
|
+
"line": 4576
|
|
68
78
|
},
|
|
69
79
|
"injectAnchorIds": {
|
|
70
80
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
72
|
-
"line":
|
|
81
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
82
|
+
"line": 3287
|
|
73
83
|
},
|
|
74
84
|
"optimizeObservationsForContext": {
|
|
75
85
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
77
|
-
"line":
|
|
86
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
87
|
+
"line": 4599
|
|
78
88
|
},
|
|
79
89
|
"parseAnchorId": {
|
|
80
90
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
82
|
-
"line":
|
|
91
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
92
|
+
"line": 3260
|
|
83
93
|
},
|
|
84
94
|
"parseObservationGroups": {
|
|
85
95
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
87
|
-
"line":
|
|
96
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
97
|
+
"line": 1415
|
|
88
98
|
},
|
|
89
99
|
"parseObserverOutput": {
|
|
90
100
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
92
|
-
"line":
|
|
101
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
102
|
+
"line": 4479
|
|
93
103
|
},
|
|
94
104
|
"reconcileObservationGroupsFromReflection": {
|
|
95
105
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
97
|
-
"line":
|
|
106
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
107
|
+
"line": 1504
|
|
98
108
|
},
|
|
99
109
|
"renderObservationGroupsForReflection": {
|
|
100
110
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
102
|
-
"line":
|
|
111
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
112
|
+
"line": 1460
|
|
103
113
|
},
|
|
104
114
|
"stripEphemeralAnchorIds": {
|
|
105
115
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
107
|
-
"line":
|
|
116
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
117
|
+
"line": 3317
|
|
108
118
|
},
|
|
109
119
|
"stripObservationGroups": {
|
|
110
120
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
112
|
-
"line":
|
|
121
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
122
|
+
"line": 1437
|
|
113
123
|
},
|
|
114
124
|
"wrapInObservationGroup": {
|
|
115
125
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
117
|
-
"line":
|
|
126
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
127
|
+
"line": 1408
|
|
118
128
|
},
|
|
119
129
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
120
130
|
"types": "dist/processors/index.d.ts",
|
|
@@ -132,6 +142,43 @@
|
|
|
132
142
|
"types": "dist/processors/index.d.ts",
|
|
133
143
|
"implementation": "dist/chunk-LSJJAJAF.js"
|
|
134
144
|
},
|
|
145
|
+
"Memory": {
|
|
146
|
+
"types": "dist/index.d.ts",
|
|
147
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
148
|
+
"line": 22108
|
|
149
|
+
},
|
|
150
|
+
"MessageHistory": {
|
|
151
|
+
"types": "dist/index.d.ts",
|
|
152
|
+
"implementation": "dist/chunk-KKP6DG65.js"
|
|
153
|
+
},
|
|
154
|
+
"SemanticRecall": {
|
|
155
|
+
"types": "dist/index.d.ts",
|
|
156
|
+
"implementation": "dist/chunk-KKP6DG65.js"
|
|
157
|
+
},
|
|
158
|
+
"WorkingMemory": {
|
|
159
|
+
"types": "dist/index.d.ts",
|
|
160
|
+
"implementation": "dist/chunk-KKP6DG65.js"
|
|
161
|
+
},
|
|
162
|
+
"deepMergeWorkingMemory": {
|
|
163
|
+
"types": "dist/index.d.ts",
|
|
164
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
165
|
+
"line": 21747
|
|
166
|
+
},
|
|
167
|
+
"extractWorkingMemoryContent": {
|
|
168
|
+
"types": "dist/index.d.ts",
|
|
169
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
170
|
+
"line": 22063
|
|
171
|
+
},
|
|
172
|
+
"extractWorkingMemoryTags": {
|
|
173
|
+
"types": "dist/index.d.ts",
|
|
174
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
175
|
+
"line": 22031
|
|
176
|
+
},
|
|
177
|
+
"removeWorkingMemoryTags": {
|
|
178
|
+
"types": "dist/index.d.ts",
|
|
179
|
+
"implementation": "dist/chunk-KKP6DG65.js",
|
|
180
|
+
"line": 22044
|
|
181
|
+
},
|
|
135
182
|
"WORKING_MEMORY_STATE_ID": {
|
|
136
183
|
"types": "dist/index.d.ts",
|
|
137
184
|
"implementation": "dist/chunk-WCGXQIEN.js"
|
|
@@ -144,25 +191,13 @@
|
|
|
144
191
|
"types": "dist/index.d.ts",
|
|
145
192
|
"implementation": "dist/chunk-WCGXQIEN.js",
|
|
146
193
|
"line": 7
|
|
147
|
-
},
|
|
148
|
-
"MessageHistory": {
|
|
149
|
-
"types": "dist/index.d.ts",
|
|
150
|
-
"implementation": "dist/processors"
|
|
151
|
-
},
|
|
152
|
-
"SemanticRecall": {
|
|
153
|
-
"types": "dist/index.d.ts",
|
|
154
|
-
"implementation": "dist/processors"
|
|
155
|
-
},
|
|
156
|
-
"WorkingMemory": {
|
|
157
|
-
"types": "dist/index.d.ts",
|
|
158
|
-
"implementation": "dist/processors"
|
|
159
194
|
}
|
|
160
195
|
},
|
|
161
196
|
"modules": {
|
|
162
197
|
"processors": {
|
|
163
198
|
"index": "dist/processors/index.js",
|
|
164
199
|
"chunks": [
|
|
165
|
-
"chunk-
|
|
200
|
+
"chunk-KKP6DG65.js",
|
|
166
201
|
"chunk-LSJJAJAF.js"
|
|
167
202
|
]
|
|
168
203
|
}
|
|
@@ -163,6 +163,120 @@ OM uses fast local token estimation for this thresholding work. Text is estimate
|
|
|
163
163
|
|
|
164
164
|
The Observer can also see attachments in the history it reviews. OM keeps readable placeholders like `[Image #1: reference-board.png]` or `[File #1: floorplan.pdf]` in the transcript for readability, and forwards the actual attachment parts alongside the text. Image-like `file` parts are upgraded to image inputs for the Observer when possible, while non-image attachments are forwarded as file parts with normalized token counting. This applies to both normal thread observation and batched resource-scope observation.
|
|
165
165
|
|
|
166
|
+
### Extractors
|
|
167
|
+
|
|
168
|
+
Use extractors when you want OM to persist specific values alongside observations. Built-in values such as **current task**, **suggested response**, and **thread title** use the same extraction pipeline as custom values.
|
|
169
|
+
|
|
170
|
+
The following example extracts a compact user profile from observations:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { Agent } from '@mastra/core/agent'
|
|
174
|
+
import { Extractor, Memory } from '@mastra/memory'
|
|
175
|
+
import { z } from 'zod'
|
|
176
|
+
|
|
177
|
+
const memory = new Memory({
|
|
178
|
+
options: {
|
|
179
|
+
observationalMemory: {
|
|
180
|
+
model: 'openai/gpt-5-mini',
|
|
181
|
+
observation: {
|
|
182
|
+
extract: [
|
|
183
|
+
new Extractor({
|
|
184
|
+
name: 'User profile',
|
|
185
|
+
instructions: 'Extract stable user profile facts that should be remembered.',
|
|
186
|
+
schema: z.object({
|
|
187
|
+
preferredName: z.string().optional(),
|
|
188
|
+
timezone: z.string().optional(),
|
|
189
|
+
tools: z.array(z.string()).optional(),
|
|
190
|
+
}),
|
|
191
|
+
}),
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
export const agent = new Agent({
|
|
199
|
+
name: 'assistant',
|
|
200
|
+
instructions: 'You are a helpful assistant.',
|
|
201
|
+
model: 'openai/gpt-5-mini',
|
|
202
|
+
memory,
|
|
203
|
+
})
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Adding a `schema` makes the extractor run as a follow-up structured output request. Schema-less extractors are inline string extractors emitted directly in the Observer or Reflector response.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
new Extractor({
|
|
210
|
+
name: 'Mood',
|
|
211
|
+
instructions: 'Extract the user mood as a short phrase.',
|
|
212
|
+
})
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
By default, OM shows the last extracted value to the extractor on later runs. Set `includePreviousExtraction: false` when the Observer should not see the previous value.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
new Extractor({
|
|
219
|
+
name: 'Latest blocker',
|
|
220
|
+
instructions: 'Extract any blockers the agent is running into.',
|
|
221
|
+
includePreviousExtraction: false,
|
|
222
|
+
})
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Use dynamic `instructions` or `schema` functions when an extractor needs runtime context, such as the active memory instance or request context:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
new Extractor({
|
|
229
|
+
name: 'Workspace summary',
|
|
230
|
+
instructions: ({ memory }) =>
|
|
231
|
+
memory ? 'Extract workspace facts for this memory instance.' : 'Extract workspace facts.',
|
|
232
|
+
})
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Working memory updates
|
|
236
|
+
|
|
237
|
+
Use `observationalMemory.observation.manageWorkingMemory` to let the Observer manage working memory automatically. The main agent no longer needs to call the working memory tool while it handles the user request, so working memory updates don't depend on the agent remembering to make them.
|
|
238
|
+
|
|
239
|
+
This also keeps working memory prompt-cache friendly. Working memory normally lives in the system prompt, so updates can invalidate the prompt cache. OM-managed working memory defaults `workingMemory.useStateSignals` to `true`, which moves working memory into state signals instead.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { Memory } from '@mastra/memory'
|
|
243
|
+
|
|
244
|
+
const memory = new Memory({
|
|
245
|
+
options: {
|
|
246
|
+
workingMemory: {
|
|
247
|
+
enabled: true,
|
|
248
|
+
},
|
|
249
|
+
observationalMemory: {
|
|
250
|
+
enabled: true,
|
|
251
|
+
observation: {
|
|
252
|
+
manageWorkingMemory: true,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
})
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
This setting adds `WorkingMemoryExtractor`, defaults `workingMemory.agentManaged` to `false`, and defaults `workingMemory.useStateSignals` to `true`. Set `workingMemory.agentManaged: true` if the main agent should still receive working memory tool and instruction injection.
|
|
260
|
+
|
|
261
|
+
Use `onExtracted` to normalize or react to custom extracted values before they are persisted:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
new Extractor({
|
|
265
|
+
name: 'Project status',
|
|
266
|
+
instructions: 'Extract the current project status.',
|
|
267
|
+
schema: z.string(),
|
|
268
|
+
async onExtracted({ current, sendSignal }) {
|
|
269
|
+
await sendSignal?.({
|
|
270
|
+
type: 'user-message',
|
|
271
|
+
contents: `Project status extracted: ${current}`,
|
|
272
|
+
})
|
|
273
|
+
return current.trim().toLowerCase()
|
|
274
|
+
},
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Extractor failures are reported in OM markers and do not block other successful extractor values. See [the API reference](https://mastra.ai/reference/memory/observational-memory) for the full `Extractor` shape.
|
|
279
|
+
|
|
166
280
|
If your Observer model is text-only or its API rejects multimodal input, set `observation.observeAttachments` to `false` to drop attachments before they reach the Observer. The readable placeholders (`[Image #1: ...]`, `[File #1: ...]`) are kept in the transcript so the Observer can still reason about what was shared without receiving the binary payload. The same filter applies to tool results that contain image or file parts:
|
|
167
281
|
|
|
168
282
|
```typescript
|
|
@@ -6,6 +6,8 @@ Think of it as the agent's active thoughts or scratchpad – the key information
|
|
|
6
6
|
|
|
7
7
|
This is useful for maintaining ongoing state that's always relevant and should always be available to the agent.
|
|
8
8
|
|
|
9
|
+
If you use [Observational Memory](https://mastra.ai/docs/memory/observational-memory), `observationalMemory.observation.manageWorkingMemory` lets OM update working memory for the agent.
|
|
10
|
+
|
|
9
11
|
Working memory can persist at two different scopes:
|
|
10
12
|
|
|
11
13
|
- **Resource-scoped** (default): Memory persists across all conversation threads for the same user
|
|
@@ -54,6 +54,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
54
54
|
|
|
55
55
|
**observation.threadTitle** (`boolean`): When \`true\`, the Observer suggests short thread titles and updates the thread title when the conversation topic meaningfully changes. This is opt-in and defaults to disabled.
|
|
56
56
|
|
|
57
|
+
**observation.extract** (`Extractor[]`): Custom values to extract after observation. Schema-less extractors are requested inline in the Observer output. Schema-backed extractors run as a follow-up structured output call and are stored in thread OM metadata.
|
|
58
|
+
|
|
57
59
|
**observation.observeAttachments** (`boolean | string[]`): Controls which image/file attachments are forwarded to the Observer model alongside their placeholder text lines. \`true\` (default) forwards all attachments. \`false\` drops all attachments while keeping placeholders visible. An array is a case-insensitive mimeType allowlist supporting exact matches (\`'application/pdf'\`), wildcard subtypes (\`'image/\*'\`), and bare \`'\*'\` for everything. Useful when the Observer model is text-only (e.g. some DeepSeek endpoints) while the main agent uses a multimodal model. Tool-result attachments are filtered using the same rule.
|
|
58
60
|
|
|
59
61
|
**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.
|
|
@@ -86,6 +88,8 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
|
|
|
86
88
|
|
|
87
89
|
**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.
|
|
88
90
|
|
|
91
|
+
**reflection.extract** (`Extractor[]`): Custom values to extract after reflection. Schema-less extractors are requested inline in the Reflector output. Schema-backed extractors run as a follow-up structured output call and are stored in thread OM metadata.
|
|
92
|
+
|
|
89
93
|
**reflection.observationTokens** (`number`): Token count of observations that triggers reflection. When observation tokens exceed this threshold, the Reflector agent is called to condense them.
|
|
90
94
|
|
|
91
95
|
**reflection.modelSettings** (`ObservationalMemoryModelSettings`): Model settings for the Reflector agent.
|
|
@@ -112,8 +116,86 @@ OM persists token payload estimates so repeated counting can reuse prior token e
|
|
|
112
116
|
- Per-message and per-conversation overhead are always recomputed at runtime and aren't cached.
|
|
113
117
|
- `data-*` and `reasoning` parts are skipped and don't receive cache entries.
|
|
114
118
|
|
|
119
|
+
## Extractor API
|
|
120
|
+
|
|
121
|
+
`Extractor` defines a value that OM should extract during observation or reflection. Built-in OM values such as `current-task`, `suggested-response`, and `thread-title` use the same extractor pipeline as custom values.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { Memory, Extractor } from '@mastra/memory'
|
|
125
|
+
import { z } from 'zod'
|
|
126
|
+
|
|
127
|
+
const memory = new Memory({
|
|
128
|
+
options: {
|
|
129
|
+
observationalMemory: {
|
|
130
|
+
model: 'openai/gpt-5-mini',
|
|
131
|
+
observation: {
|
|
132
|
+
extract: [
|
|
133
|
+
new Extractor({
|
|
134
|
+
name: 'User profile',
|
|
135
|
+
instructions: 'Extract stable user profile facts that should be remembered.',
|
|
136
|
+
schema: z.object({
|
|
137
|
+
name: z.string().optional(),
|
|
138
|
+
timezone: z.string().optional(),
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**name** (`string`): Human-readable extractor name. OM slugifies this value into the extractor slug. Names must be unique after slug generation.
|
|
149
|
+
|
|
150
|
+
**slug** (`string`): Generated stable identifier for persisted values and XML tags. Slugs use lowercase letters, numbers, and hyphens. Built-in slugs and reserved XML tags cannot be used by custom extractors.
|
|
151
|
+
|
|
152
|
+
**instructions** (`string | (context) => string`): Instructions for what to extract and when to update the value. Use a function to derive instructions from runtime context.
|
|
153
|
+
|
|
154
|
+
**schema** (`ZodType<T> | (context) => ZodType<T> | undefined`): Optional Zod schema for structured extraction. When provided, OM runs a follow-up structured output call after the main OM operation. When omitted, the extractor is an inline string extractor emitted in the Observer or Reflector response. Use a function to derive the schema from runtime context.
|
|
155
|
+
|
|
156
|
+
**includePreviousExtraction** (`boolean`): Controls whether the previous extraction is shown to the extractor on future OM runs. Set to \`false\` for values that should only come from the current OM run. (Default: `true`)
|
|
157
|
+
|
|
158
|
+
**onExtracted** (`(context) => T | void | Promise<T | void>`): Optional hook called after a custom extractor returns a value and before metadata is persisted. Returning a value replaces the extracted value. Throwing records an extraction failure.
|
|
159
|
+
|
|
160
|
+
### Extraction behavior
|
|
161
|
+
|
|
162
|
+
- Extracted values are stored in thread OM metadata under `om.extracted`.
|
|
163
|
+
- Built-in extractor values are also mirrored to the compatibility metadata fields `currentTask`, `suggestedResponse`, and `threadTitle`.
|
|
164
|
+
- `thread-title` updates the thread title only when `observation.threadTitle` is enabled.
|
|
165
|
+
- `observation.extract` runs during observation. `reflection.extract` runs during reflection.
|
|
166
|
+
- Schema-backed extractors add a follow-up structured output request.
|
|
167
|
+
- Schema-less extractors are inline string extractors emitted directly in the Observer or Reflector output.
|
|
168
|
+
- Dynamic extractor functions receive runtime context, including `source`, `threadId`, `resourceId`, `mainAgent`, `memory`, and `requestContext` when available.
|
|
169
|
+
- `WorkingMemoryExtractor` uses the normal extractor pipeline to update working memory through the active `Memory` instance. It uses structured extraction when working memory has a JSON schema and skips OM metadata persistence, so the working memory payload isn't duplicated under OM extracted metadata.
|
|
170
|
+
- `observationalMemory.observation.manageWorkingMemory` adds `WorkingMemoryExtractor`, defaults `workingMemory.agentManaged` to `false`, and defaults `workingMemory.useStateSignals` to `true` when working memory is enabled.
|
|
171
|
+
- Extraction failures are reported in OM marker data and do not discard other successful extracted values.
|
|
172
|
+
|
|
115
173
|
## Examples
|
|
116
174
|
|
|
175
|
+
### Working memory updates
|
|
176
|
+
|
|
177
|
+
Use `observationalMemory.observation.manageWorkingMemory` when OM should update working memory.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { Memory } from '@mastra/memory'
|
|
181
|
+
|
|
182
|
+
const memory = new Memory({
|
|
183
|
+
options: {
|
|
184
|
+
workingMemory: {
|
|
185
|
+
enabled: true,
|
|
186
|
+
},
|
|
187
|
+
observationalMemory: {
|
|
188
|
+
enabled: true,
|
|
189
|
+
observation: {
|
|
190
|
+
manageWorkingMemory: true,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Set `workingMemory.agentManaged: true` if the main agent should still receive working memory tool and instruction injection.
|
|
198
|
+
|
|
117
199
|
### Resource scope with custom thresholds (experimental)
|
|
118
200
|
|
|
119
201
|
```typescript
|
|
@@ -431,6 +513,10 @@ Emitted when observation or reflection completes successfully.
|
|
|
431
513
|
|
|
432
514
|
**suggestedResponse** (`string`): Suggested response extracted by the Observer.
|
|
433
515
|
|
|
516
|
+
**extractedValues** (`Record<string, unknown>`): Values extracted during this OM operation, keyed by extractor slug.
|
|
517
|
+
|
|
518
|
+
**extractionFailures** (`Array<{ slug: string; error: string }>`): Extractor failures from this OM operation. Successful extractor values are still included.
|
|
519
|
+
|
|
434
520
|
**recordId** (`string`): The OM record ID.
|
|
435
521
|
|
|
436
522
|
**threadId** (`string`): This thread's ID.
|
|
@@ -495,6 +581,10 @@ Emitted when async buffering completes. The content is stored but not yet activa
|
|
|
495
581
|
|
|
496
582
|
**observations** (`string`): The buffered content.
|
|
497
583
|
|
|
584
|
+
**extractedValues** (`Record<string, unknown>`): Values extracted during this buffered OM operation, keyed by extractor slug.
|
|
585
|
+
|
|
586
|
+
**extractionFailures** (`Array<{ slug: string; error: string }>`): Extractor failures from this buffered OM operation. Successful extractor values are still included.
|
|
587
|
+
|
|
498
588
|
**recordId** (`string`): The OM record ID.
|
|
499
589
|
|
|
500
590
|
**threadId** (`string`): This thread's ID.
|