@mastra/memory 1.42.0-alpha.3 → 1.42.0-alpha.5
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +55 -55
- package/dist/docs/references/docs-agents-human-in-the-loop.md +2 -2
- package/dist/docs/references/docs-agents-networks.md +1 -1
- package/dist/docs/references/docs-guides-context-engineering.md +3 -3
- package/dist/docs/references/docs-harness-background-tasks.md +2 -2
- package/dist/docs/references/docs-harness-goals.md +2 -2
- package/dist/docs/references/docs-knowledge-overview.md +1 -1
- package/dist/docs/references/docs-memory-memory-processors.md +8 -8
- package/dist/docs/references/docs-memory-message-history.md +3 -3
- package/dist/docs/references/docs-memory-observational-memory.md +1 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +2 -2
- package/dist/docs/references/docs-memory-working-memory.md +3 -2
- package/dist/docs/references/docs-signals-overview.md +1 -1
- package/dist/docs/references/docs-storage.md +12 -12
- package/dist/docs/references/docs-subagents.md +26 -3
- package/dist/docs/references/integrations-channels-github.md +1 -1
- package/dist/docs/references/integrations-channels-ring.md +2 -2
- package/dist/docs/references/integrations-databases-aurora-dsql.md +1 -1
- package/dist/docs/references/integrations-databases-elasticsearch.md +1 -1
- package/dist/docs/references/integrations-databases-libsql.md +6 -0
- package/dist/docs/references/integrations-databases-mongodb.md +1 -1
- package/dist/docs/references/integrations-databases-oracledb.md +1 -1
- package/dist/docs/references/integrations-databases-postgresql.md +9 -1
- package/dist/docs/references/integrations-databases-redis.md +1 -1
- package/dist/docs/references/integrations-databases-upstash.md +1 -1
- package/dist/docs/references/reference-memory-memory-class.md +3 -3
- package/dist/docs/references/reference-memory-observational-memory.md +3 -3
- package/dist/docs/references/reference-processors-token-limiter-processor.md +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/cache-boundary.d.ts +21 -0
- package/dist/processors/observational-memory/processor.d.ts +3 -1
- package/dist/processors/observational-memory/thresholds.d.ts +2 -0
- package/dist/{src-CHDmfrJu.js → src-BJGnRDOG.js} +59 -5
- package/dist/{src-DiUUpFI9.cjs → src-C7wq-aPe.cjs} +59 -5
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,243 +1,243 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.42.0-alpha.
|
|
2
|
+
"version": "1.42.0-alpha.5",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"AUTO_MODEL_BY_PROVIDER": {
|
|
6
6
|
"types": "dist/processors/observational-memory/auto-model.d.ts",
|
|
7
|
-
"implementation": "dist/src-
|
|
7
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
8
8
|
"line": 32963
|
|
9
9
|
},
|
|
10
10
|
"Extractor": {
|
|
11
11
|
"types": "dist/processors/observational-memory/extractor.d.ts",
|
|
12
|
-
"implementation": "dist/src-
|
|
12
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
13
13
|
"line": 24432
|
|
14
14
|
},
|
|
15
15
|
"ModelByInputTokens": {
|
|
16
16
|
"types": "dist/processors/observational-memory/model-by-input-tokens.d.ts",
|
|
17
|
-
"implementation": "dist/src-
|
|
17
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
18
18
|
"line": 32746
|
|
19
19
|
},
|
|
20
20
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
21
21
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
22
|
-
"implementation": "dist/src-
|
|
22
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
23
23
|
"line": 24168
|
|
24
24
|
},
|
|
25
25
|
"OBSERVATION_CONTEXT_INSTRUCTIONS": {
|
|
26
26
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
27
|
-
"implementation": "dist/src-
|
|
27
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
28
28
|
"line": 24229
|
|
29
29
|
},
|
|
30
30
|
"OBSERVATION_CONTEXT_PROMPT": {
|
|
31
31
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
32
|
-
"implementation": "dist/src-
|
|
32
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
33
33
|
"line": 24211
|
|
34
34
|
},
|
|
35
35
|
"OBSERVATION_CONTEXT_PROMPT_THREAD": {
|
|
36
36
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
37
|
-
"implementation": "dist/src-
|
|
37
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
38
38
|
"line": 24216
|
|
39
39
|
},
|
|
40
40
|
"OBSERVATION_CONTINUATION_HINT": {
|
|
41
41
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
42
|
-
"implementation": "dist/src-
|
|
42
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
43
43
|
"line": 24198
|
|
44
44
|
},
|
|
45
45
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
46
46
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
47
|
-
"implementation": "dist/src-
|
|
47
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
48
48
|
"line": 26898
|
|
49
49
|
},
|
|
50
50
|
"ObservationalMemory": {
|
|
51
51
|
"types": "dist/processors/observational-memory/observational-memory.d.ts",
|
|
52
|
-
"implementation": "dist/src-
|
|
53
|
-
"line":
|
|
52
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
53
|
+
"line": 38086
|
|
54
54
|
},
|
|
55
55
|
"ObservationalMemoryProcessor": {
|
|
56
56
|
"types": "dist/processors/observational-memory/processor.d.ts",
|
|
57
|
-
"implementation": "dist/src-
|
|
58
|
-
"line":
|
|
57
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
58
|
+
"line": 40967
|
|
59
59
|
},
|
|
60
60
|
"TokenCounter": {
|
|
61
61
|
"types": "dist/processors/observational-memory/token-counter.d.ts",
|
|
62
|
-
"implementation": "dist/src-
|
|
62
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
63
63
|
"line": 29428
|
|
64
64
|
},
|
|
65
65
|
"WorkingMemoryExtractor": {
|
|
66
66
|
"types": "dist/processors/observational-memory/working-memory-extractor.d.ts",
|
|
67
|
-
"implementation": "dist/src-
|
|
67
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
68
68
|
"line": 30484
|
|
69
69
|
},
|
|
70
70
|
"buildObserverPrompt": {
|
|
71
71
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
72
|
-
"implementation": "dist/src-
|
|
72
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
73
73
|
"line": 27580
|
|
74
74
|
},
|
|
75
75
|
"buildObserverSystemPrompt": {
|
|
76
76
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
77
|
-
"implementation": "dist/src-
|
|
77
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
78
78
|
"line": 26792
|
|
79
79
|
},
|
|
80
80
|
"combineObservationGroupRanges": {
|
|
81
81
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
82
|
-
"implementation": "dist/src-
|
|
82
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
83
83
|
"line": 31066
|
|
84
84
|
},
|
|
85
85
|
"deriveObservationGroupProvenance": {
|
|
86
86
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
87
|
-
"implementation": "dist/src-
|
|
87
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
88
88
|
"line": 31110
|
|
89
89
|
},
|
|
90
90
|
"extractCurrentTask": {
|
|
91
91
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
92
|
-
"implementation": "dist/src-
|
|
92
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
93
93
|
"line": 27893
|
|
94
94
|
},
|
|
95
95
|
"formatMessagesForObserver": {
|
|
96
96
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
97
|
-
"implementation": "dist/src-
|
|
97
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
98
98
|
"line": 27331
|
|
99
99
|
},
|
|
100
100
|
"getObservationContextPrompt": {
|
|
101
101
|
"types": "dist/processors/observational-memory/constants.d.ts",
|
|
102
|
-
"implementation": "dist/src-
|
|
102
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
103
103
|
"line": 24222
|
|
104
104
|
},
|
|
105
105
|
"getObservationsAsOf": {
|
|
106
106
|
"types": "dist/processors/observational-memory/observation-utils.d.ts",
|
|
107
|
-
"implementation": "dist/src-
|
|
108
|
-
"line":
|
|
107
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
108
|
+
"line": 41320
|
|
109
109
|
},
|
|
110
110
|
"hasCurrentTaskSection": {
|
|
111
111
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
112
|
-
"implementation": "dist/src-
|
|
112
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
113
113
|
"line": 27881
|
|
114
114
|
},
|
|
115
115
|
"injectAnchorIds": {
|
|
116
116
|
"types": "dist/processors/observational-memory/anchor-ids.d.ts",
|
|
117
|
-
"implementation": "dist/src-
|
|
117
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
118
118
|
"line": 25432
|
|
119
119
|
},
|
|
120
120
|
"optimizeObservationsForContext": {
|
|
121
121
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
122
|
-
"implementation": "dist/src-
|
|
122
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
123
123
|
"line": 27914
|
|
124
124
|
},
|
|
125
125
|
"parseAnchorId": {
|
|
126
126
|
"types": "dist/processors/observational-memory/anchor-ids.d.ts",
|
|
127
|
-
"implementation": "dist/src-
|
|
127
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
128
128
|
"line": 25416
|
|
129
129
|
},
|
|
130
130
|
"parseObservationGroups": {
|
|
131
131
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
132
|
-
"implementation": "dist/src-
|
|
132
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
133
133
|
"line": 31021
|
|
134
134
|
},
|
|
135
135
|
"parseObserverOutput": {
|
|
136
136
|
"types": "dist/processors/observational-memory/observer-agent.d.ts",
|
|
137
|
-
"implementation": "dist/src-
|
|
137
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
138
138
|
"line": 27591
|
|
139
139
|
},
|
|
140
140
|
"reconcileObservationGroupsFromReflection": {
|
|
141
141
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
142
|
-
"implementation": "dist/src-
|
|
142
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
143
143
|
"line": 31129
|
|
144
144
|
},
|
|
145
145
|
"renderObservationGroupsForReflection": {
|
|
146
146
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
147
|
-
"implementation": "dist/src-
|
|
147
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
148
148
|
"line": 31095
|
|
149
149
|
},
|
|
150
150
|
"resolveAutoModelId": {
|
|
151
151
|
"types": "dist/processors/observational-memory/auto-model.d.ts",
|
|
152
|
-
"implementation": "dist/src-
|
|
152
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
153
153
|
"line": 32983
|
|
154
154
|
},
|
|
155
155
|
"stripEphemeralAnchorIds": {
|
|
156
156
|
"types": "dist/processors/observational-memory/anchor-ids.d.ts",
|
|
157
|
-
"implementation": "dist/src-
|
|
157
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
158
158
|
"line": 25455
|
|
159
159
|
},
|
|
160
160
|
"stripObservationGroups": {
|
|
161
161
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
162
|
-
"implementation": "dist/src-
|
|
162
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
163
163
|
"line": 31038
|
|
164
164
|
},
|
|
165
165
|
"summarizeConversation": {
|
|
166
166
|
"types": "dist/processors/observational-memory/summarize.d.ts",
|
|
167
|
-
"implementation": "dist/src-
|
|
167
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
168
168
|
"line": 30096
|
|
169
169
|
},
|
|
170
170
|
"wrapInObservationGroup": {
|
|
171
171
|
"types": "dist/processors/observational-memory/observation-groups.d.ts",
|
|
172
|
-
"implementation": "dist/src-
|
|
172
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
173
173
|
"line": 30992
|
|
174
174
|
},
|
|
175
175
|
"KnowledgeSemanticIndexCoordinator": {
|
|
176
176
|
"types": "dist/removed-subconscious.d.ts",
|
|
177
|
-
"implementation": "dist/src-
|
|
177
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
178
178
|
"line": 30590
|
|
179
179
|
},
|
|
180
180
|
"Memory": {
|
|
181
181
|
"types": "dist/index.d.ts",
|
|
182
|
-
"implementation": "dist/src-
|
|
183
|
-
"line":
|
|
182
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
183
|
+
"line": 41572
|
|
184
184
|
},
|
|
185
185
|
"SUMMARIZE_THREAD_DEFAULTS": {
|
|
186
186
|
"types": "dist/processors/observational-memory/summarize.d.ts",
|
|
187
|
-
"implementation": "dist/src-
|
|
187
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
188
188
|
"line": 30052
|
|
189
189
|
},
|
|
190
190
|
"StaleKnowledgeSemanticIndexError": {
|
|
191
191
|
"types": "dist/removed-subconscious.d.ts",
|
|
192
|
-
"implementation": "dist/src-
|
|
192
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
193
193
|
"line": 30596
|
|
194
194
|
},
|
|
195
195
|
"Subconscious": {
|
|
196
196
|
"types": "dist/removed-subconscious.d.ts",
|
|
197
|
-
"implementation": "dist/src-
|
|
197
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
198
198
|
"line": 30584
|
|
199
199
|
},
|
|
200
200
|
"WORKING_MEMORY_STATE_ID": {
|
|
201
201
|
"types": "dist/processors/working-memory-state/processor.d.ts",
|
|
202
|
-
"implementation": "dist/src-
|
|
202
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
203
203
|
"line": 32792
|
|
204
204
|
},
|
|
205
205
|
"WORKING_MEMORY_STATE_PROCESSOR_ID": {
|
|
206
206
|
"types": "dist/processors/working-memory-state/processor.d.ts",
|
|
207
|
-
"implementation": "dist/src-
|
|
207
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
208
208
|
"line": 32793
|
|
209
209
|
},
|
|
210
210
|
"WorkingMemoryStateProcessor": {
|
|
211
211
|
"types": "dist/processors/working-memory-state/processor.d.ts",
|
|
212
|
-
"implementation": "dist/src-
|
|
212
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
213
213
|
"line": 32794
|
|
214
214
|
},
|
|
215
215
|
"deepMergeWorkingMemory": {
|
|
216
216
|
"types": "dist/tools/working-memory.d.ts",
|
|
217
|
-
"implementation": "dist/src-
|
|
217
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
218
218
|
"line": 30175
|
|
219
219
|
},
|
|
220
220
|
"extractWorkingMemoryContent": {
|
|
221
221
|
"types": "dist/index.d.ts",
|
|
222
|
-
"implementation": "dist/src-
|
|
223
|
-
"line":
|
|
222
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
223
|
+
"line": 41385
|
|
224
224
|
},
|
|
225
225
|
"extractWorkingMemoryTags": {
|
|
226
226
|
"types": "dist/index.d.ts",
|
|
227
|
-
"implementation": "dist/src-
|
|
228
|
-
"line":
|
|
227
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
228
|
+
"line": 41353
|
|
229
229
|
},
|
|
230
230
|
"removeWorkingMemoryTags": {
|
|
231
231
|
"types": "dist/index.d.ts",
|
|
232
|
-
"implementation": "dist/src-
|
|
233
|
-
"line":
|
|
232
|
+
"implementation": "dist/src-BJGnRDOG.js",
|
|
233
|
+
"line": 41366
|
|
234
234
|
}
|
|
235
235
|
},
|
|
236
236
|
"modules": {
|
|
237
237
|
"processors": {
|
|
238
238
|
"index": "dist/processors/index.js",
|
|
239
239
|
"chunks": [
|
|
240
|
-
"src-
|
|
240
|
+
"src-BJGnRDOG.js"
|
|
241
241
|
]
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -179,7 +179,7 @@ const approvedFingerprints = new Set<string>()
|
|
|
179
179
|
export const approvalBoundAgent = new Agent({
|
|
180
180
|
id: 'approval-bound-agent',
|
|
181
181
|
name: 'Approval Bound Agent',
|
|
182
|
-
model: 'openai/gpt-6.
|
|
182
|
+
model: 'openai/gpt-6.2-sol',
|
|
183
183
|
tools: { issueRefundTool, deleteRecordTool },
|
|
184
184
|
hooks: {
|
|
185
185
|
beforeToolCall: ({ toolName, input }) => {
|
|
@@ -671,7 +671,7 @@ const supervisorAgent = new Agent({
|
|
|
671
671
|
name: 'Supervisor Agent',
|
|
672
672
|
instructions: `You coordinate data retrieval tasks.
|
|
673
673
|
Delegate to data-agent for user lookups.`,
|
|
674
|
-
model: 'openai/gpt-6.
|
|
674
|
+
model: 'openai/gpt-6.2-sol',
|
|
675
675
|
agents: { dataAgent },
|
|
676
676
|
memory: new Memory(),
|
|
677
677
|
})
|
|
@@ -31,7 +31,7 @@ export const routingAgent = new Agent({
|
|
|
31
31
|
name: 'Routing Agent',
|
|
32
32
|
instructions: `
|
|
33
33
|
You are a network of writers and researchers. The user will ask you to research a topic. Always respond with a complete report—no bullet points. Write in full paragraphs, like a blog post. Do not answer with incomplete or uncertain information.`,
|
|
34
|
-
model: 'openai/gpt-6.
|
|
34
|
+
model: 'openai/gpt-6.2-sol',
|
|
35
35
|
agents: {
|
|
36
36
|
researchAgent,
|
|
37
37
|
writingAgent,
|
|
@@ -34,7 +34,7 @@ export const supportAgent = new Agent({
|
|
|
34
34
|
name: 'Support Agent',
|
|
35
35
|
instructions: `You help customers understand their account.
|
|
36
36
|
Use plain language and don't invent account details.`,
|
|
37
|
-
model: 'openai/gpt-6.
|
|
37
|
+
model: 'openai/gpt-6.2-sol',
|
|
38
38
|
})
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -167,7 +167,7 @@ import { Memory } from '@mastra/memory'
|
|
|
167
167
|
export const assistant = new Agent({
|
|
168
168
|
id: 'assistant',
|
|
169
169
|
name: 'Assistant',
|
|
170
|
-
model: 'openai/gpt-6.
|
|
170
|
+
model: 'openai/gpt-6.2-sol',
|
|
171
171
|
memory: new Memory({
|
|
172
172
|
options: {
|
|
173
173
|
lastMessages: 20,
|
|
@@ -202,7 +202,7 @@ import { Memory } from '@mastra/memory'
|
|
|
202
202
|
export const assistant = new Agent({
|
|
203
203
|
id: 'assistant',
|
|
204
204
|
name: 'Assistant',
|
|
205
|
-
model: 'openai/gpt-6.
|
|
205
|
+
model: 'openai/gpt-6.2-sol',
|
|
206
206
|
memory: new Memory({
|
|
207
207
|
options: {
|
|
208
208
|
observationalMemory: true,
|
|
@@ -85,7 +85,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
85
85
|
export const researcher = new Agent({
|
|
86
86
|
id: 'researcher',
|
|
87
87
|
instructions: 'You research topics and answer questions.',
|
|
88
|
-
model: 'openai/gpt-6.
|
|
88
|
+
model: 'openai/gpt-6.2-sol',
|
|
89
89
|
tools: { researchTool, summarizeTool },
|
|
90
90
|
backgroundTasks: {
|
|
91
91
|
tools: {
|
|
@@ -286,7 +286,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
286
286
|
const supervisor = new Agent({
|
|
287
287
|
id: 'supervisor',
|
|
288
288
|
instructions: 'Coordinate research and writing using the available agents.',
|
|
289
|
-
model: 'openai/gpt-6.
|
|
289
|
+
model: 'openai/gpt-6.2-sol',
|
|
290
290
|
agents: { researchAgent, writingAgent },
|
|
291
291
|
backgroundTasks: {
|
|
292
292
|
tools: {
|
|
@@ -33,7 +33,7 @@ const worker = new Agent({
|
|
|
33
33
|
id: 'worker',
|
|
34
34
|
name: 'worker',
|
|
35
35
|
instructions: 'You complete software tasks end to end.',
|
|
36
|
-
model: 'openai/gpt-6.
|
|
36
|
+
model: 'openai/gpt-6.2-sol',
|
|
37
37
|
memory,
|
|
38
38
|
goal: {
|
|
39
39
|
judge: 'openai/gpt-6-luna',
|
|
@@ -93,7 +93,7 @@ const worker = new Agent({
|
|
|
93
93
|
id: 'worker',
|
|
94
94
|
name: 'worker',
|
|
95
95
|
instructions: 'You complete software tasks end to end.',
|
|
96
|
-
model: 'openai/gpt-6.
|
|
96
|
+
model: 'openai/gpt-6.2-sol',
|
|
97
97
|
memory,
|
|
98
98
|
goal: {
|
|
99
99
|
// A resolver function lets you inject provider credentials and read the
|
|
@@ -57,7 +57,7 @@ export const agent = new Agent({
|
|
|
57
57
|
id: 'assistant',
|
|
58
58
|
name: 'Assistant',
|
|
59
59
|
instructions: 'You help your team and keep its knowledge up to date.',
|
|
60
|
-
model: 'openai/gpt-6.
|
|
60
|
+
model: 'openai/gpt-6.2-sol',
|
|
61
61
|
memory: new Memory({ storage }),
|
|
62
62
|
knowledge,
|
|
63
63
|
})
|
|
@@ -57,7 +57,7 @@ const agent = new Agent({
|
|
|
57
57
|
id: 'test-agent',
|
|
58
58
|
name: 'Test Agent',
|
|
59
59
|
instructions: 'You are a helpful assistant',
|
|
60
|
-
model: 'openai/gpt-6.
|
|
60
|
+
model: 'openai/gpt-6.2-sol',
|
|
61
61
|
memory: new Memory({
|
|
62
62
|
storage: new LibSQLStore({
|
|
63
63
|
id: 'memory-store',
|
|
@@ -109,7 +109,7 @@ import { openai } from '@ai-sdk/openai'
|
|
|
109
109
|
const agent = new Agent({
|
|
110
110
|
name: 'semantic-agent',
|
|
111
111
|
instructions: 'You are a helpful assistant with semantic memory',
|
|
112
|
-
model: 'openai/gpt-6.
|
|
112
|
+
model: 'openai/gpt-6.2-sol',
|
|
113
113
|
memory: new Memory({
|
|
114
114
|
storage: new LibSQLStore({
|
|
115
115
|
id: 'memory-store',
|
|
@@ -159,7 +159,7 @@ import { openai } from '@ai-sdk/openai'
|
|
|
159
159
|
const agent = new Agent({
|
|
160
160
|
name: 'working-memory-agent',
|
|
161
161
|
instructions: 'You are an assistant with working memory',
|
|
162
|
-
model: 'openai/gpt-6.
|
|
162
|
+
model: 'openai/gpt-6.2-sol',
|
|
163
163
|
memory: new Memory({
|
|
164
164
|
storage: new LibSQLStore({
|
|
165
165
|
id: 'memory-store',
|
|
@@ -191,7 +191,7 @@ const customMessageHistory = new MessageHistory({
|
|
|
191
191
|
const agent = new Agent({
|
|
192
192
|
name: 'custom-memory-agent',
|
|
193
193
|
instructions: 'You are a helpful assistant',
|
|
194
|
-
model: 'openai/gpt-6.
|
|
194
|
+
model: 'openai/gpt-6.2-sol',
|
|
195
195
|
memory: new Memory({
|
|
196
196
|
storage: new LibSQLStore({ id: 'memory-store', url: 'file:memory.db' }),
|
|
197
197
|
options: {
|
|
@@ -264,7 +264,7 @@ const agent = new Agent({
|
|
|
264
264
|
id: 'safe-agent',
|
|
265
265
|
name: 'safe-agent',
|
|
266
266
|
instructions: 'You are a helpful assistant',
|
|
267
|
-
model: 'openai/gpt-6.
|
|
267
|
+
model: 'openai/gpt-6.2-sol',
|
|
268
268
|
memory: new Memory({ options: { lastMessages: 10 } }),
|
|
269
269
|
// Your guardrail runs BEFORE memory saves
|
|
270
270
|
outputProcessors: [contentBlocker],
|
|
@@ -304,7 +304,7 @@ const agent = new Agent({
|
|
|
304
304
|
id: 'validated-agent',
|
|
305
305
|
name: 'validated-agent',
|
|
306
306
|
instructions: 'You are a helpful assistant',
|
|
307
|
-
model: 'openai/gpt-6.
|
|
307
|
+
model: 'openai/gpt-6.2-sol',
|
|
308
308
|
memory: new Memory({ options: { lastMessages: 10 } }),
|
|
309
309
|
// Your guardrail runs AFTER memory loads history
|
|
310
310
|
inputProcessors: [inputValidator],
|
|
@@ -340,7 +340,7 @@ const agent = new Agent({
|
|
|
340
340
|
id: 'writer',
|
|
341
341
|
name: 'writer',
|
|
342
342
|
instructions: 'You write step-by-step migration guides.',
|
|
343
|
-
model: 'openai/gpt-6.
|
|
343
|
+
model: 'openai/gpt-6.2-sol',
|
|
344
344
|
memory,
|
|
345
345
|
})
|
|
346
346
|
|
|
@@ -427,7 +427,7 @@ export const supportAgent = new Agent({
|
|
|
427
427
|
id: 'support-agent',
|
|
428
428
|
name: 'Support agent',
|
|
429
429
|
instructions: 'Answer customer support questions.',
|
|
430
|
-
model: 'openai/gpt-6.
|
|
430
|
+
model: 'openai/gpt-6.2-sol',
|
|
431
431
|
memory: new Memory({ options: { lastMessages: 10 } }),
|
|
432
432
|
inputProcessors: [new AttachmentUploader()],
|
|
433
433
|
})
|
|
@@ -196,7 +196,7 @@ export const supportAgent = new Agent({
|
|
|
196
196
|
id: 'support-agent',
|
|
197
197
|
name: 'Support agent',
|
|
198
198
|
instructions: 'Answer customer support questions.',
|
|
199
|
-
model: 'openai/gpt-6.
|
|
199
|
+
model: 'openai/gpt-6.2-sol',
|
|
200
200
|
memory: new Memory({
|
|
201
201
|
options: {
|
|
202
202
|
generateTitle: true,
|
|
@@ -219,7 +219,7 @@ export const supportAgent = new Agent({
|
|
|
219
219
|
id: 'support-agent',
|
|
220
220
|
name: 'Support agent',
|
|
221
221
|
instructions: 'Answer customer support questions.',
|
|
222
|
-
model: 'openai/gpt-6.
|
|
222
|
+
model: 'openai/gpt-6.2-sol',
|
|
223
223
|
memory: new Memory({
|
|
224
224
|
options: {
|
|
225
225
|
generateTitle: {
|
|
@@ -254,7 +254,7 @@ export const supportAgent = new Agent({
|
|
|
254
254
|
id: 'support-agent',
|
|
255
255
|
name: 'Support agent',
|
|
256
256
|
instructions: 'Answer customer support questions.',
|
|
257
|
-
model: 'openai/gpt-6.
|
|
257
|
+
model: 'openai/gpt-6.2-sol',
|
|
258
258
|
memory: new Memory({
|
|
259
259
|
options: {
|
|
260
260
|
generateTitle: {
|
|
@@ -176,7 +176,7 @@ const memory = new Memory({
|
|
|
176
176
|
})
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
Use a model with a large context window (128,000 tokens or more) that's fast enough to run in the background. Mastra has tested `google/gemini-2.5-flash`, `openai/gpt-6-luna`, `anthropic/claude-haiku-5
|
|
179
|
+
Use a model with a large context window (128,000 tokens or more) that's fast enough to run in the background. Mastra has tested `google/gemini-2.5-flash`, `openai/gpt-6-luna`, `anthropic/claude-haiku-5-5` and `deepseek/deepseek-flash`.
|
|
180
180
|
|
|
181
181
|
To use a different model per role, set `observation.model` and `reflection.model` instead, and leave the top-level `model` out. Setting both throws. Some models keep so much detail that their reflections can stay above the threshold; in testing, `google/gemini-2.5-flash` did this. A common split uses a detail-preserving model as the Observer and one that condenses more aggressively, such as `deepseek/deepseek-flash`, as the Reflector. See [different models per agent](https://mastra.ai/reference/memory/observational-memory).
|
|
182
182
|
|
|
@@ -38,7 +38,7 @@ const agent = new Agent({
|
|
|
38
38
|
id: 'support-agent',
|
|
39
39
|
name: 'SupportAgent',
|
|
40
40
|
instructions: 'You are a helpful support agent.',
|
|
41
|
-
model: 'openai/gpt-6.
|
|
41
|
+
model: 'openai/gpt-6.2-sol',
|
|
42
42
|
memory: new Memory({
|
|
43
43
|
storage: new LibSQLStore({
|
|
44
44
|
id: 'agent-storage',
|
|
@@ -68,7 +68,7 @@ const agent = new Agent({
|
|
|
68
68
|
id: 'support-agent',
|
|
69
69
|
name: 'SupportAgent',
|
|
70
70
|
instructions: 'You are a helpful support agent.',
|
|
71
|
-
model: 'openai/gpt-6.
|
|
71
|
+
model: 'openai/gpt-6.2-sol',
|
|
72
72
|
memory: new Memory({
|
|
73
73
|
storage: new MongoDBStore({
|
|
74
74
|
id: 'agent-storage',
|
|
@@ -34,7 +34,7 @@ const agent = new Agent({
|
|
|
34
34
|
id: 'personal-assistant',
|
|
35
35
|
name: 'PersonalAssistant',
|
|
36
36
|
instructions: 'You are a helpful personal assistant.',
|
|
37
|
-
model: 'openai/gpt-6.
|
|
37
|
+
model: 'openai/gpt-6.2-sol',
|
|
38
38
|
memory: new Memory({
|
|
39
39
|
options: {
|
|
40
40
|
workingMemory: {
|
|
@@ -269,7 +269,8 @@ When a schema is provided, the agent receives the working memory as a JSON objec
|
|
|
269
269
|
Schema-based working memory uses **merge semantics**, meaning the agent only needs to include fields it wants to add or update. Existing fields are preserved automatically.
|
|
270
270
|
|
|
271
271
|
- **Object fields are deep merged:** Only provided fields are updated; others remain unchanged
|
|
272
|
-
-
|
|
272
|
+
- **`null` in agent updates:** Optional schema fields set to `null` keep their existing value. A `null` only removes a key the schema doesn't declare as an optional property, such as a key in a record-style object
|
|
273
|
+
- **`null` in direct merges:** `memory.mergeWorkingMemory()` deletes a field when its value is `null`, including optional fields. Omit the field to keep its value
|
|
273
274
|
- **Arrays are replaced entirely:** When an array field is provided, it replaces the existing array (arrays aren't merged element-by-element)
|
|
274
275
|
|
|
275
276
|
### Concurrent updates
|
|
@@ -31,7 +31,7 @@ const agent = new Agent({
|
|
|
31
31
|
id: 'support-agent',
|
|
32
32
|
name: 'Support Agent',
|
|
33
33
|
instructions: 'Help the user compare options.',
|
|
34
|
-
model: 'openai/gpt-6.
|
|
34
|
+
model: 'openai/gpt-6.2-sol',
|
|
35
35
|
memory: new Memory({
|
|
36
36
|
storage: new LibSQLStore({
|
|
37
37
|
id: 'signals-storage',
|
|
@@ -30,17 +30,17 @@ Use storage when your application needs any of these behaviors:
|
|
|
30
30
|
|
|
31
31
|
Mastra storage is organized into **domains**. A domain owns one type of runtime data, and a storage adapter implements one or more domains.
|
|
32
32
|
|
|
33
|
-
| Domain | What it stores
|
|
34
|
-
| ----------------- |
|
|
35
|
-
| `memory` | Threads, messages, resources, working memory, and other agent memory state. |
|
|
36
|
-
| `workflows` | Workflow snapshots used to suspend and resume runs.
|
|
37
|
-
| `observability` | Traces, spans, metrics, logs, and feedback.
|
|
38
|
-
| `scores` | Eval score records.
|
|
39
|
-
| `datasets` | Dataset records and dataset items used by evals and experiments.
|
|
40
|
-
| `experiments` | Experiment runs and per-item experiment results.
|
|
41
|
-
| `backgroundTasks` | Background task records and execution state.
|
|
42
|
-
| `schedules` | Schedule definitions and trigger history.
|
|
43
|
-
| `threadState` | Durable task, goal, and thread state.
|
|
33
|
+
| Domain | What it stores |
|
|
34
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| `memory` | Threads, messages, resources, working memory, and other agent memory state, including the [pending signals](https://mastra.ai/docs/server/pubsub) of evented agents. |
|
|
36
|
+
| `workflows` | Workflow snapshots used to suspend and resume runs. |
|
|
37
|
+
| `observability` | Traces, spans, metrics, logs, and feedback. |
|
|
38
|
+
| `scores` | Eval score records. |
|
|
39
|
+
| `datasets` | Dataset records and dataset items used by evals and experiments. |
|
|
40
|
+
| `experiments` | Experiment runs and per-item experiment results. |
|
|
41
|
+
| `backgroundTasks` | Background task records and execution state. |
|
|
42
|
+
| `schedules` | Schedule definitions and trigger history. |
|
|
43
|
+
| `threadState` | Durable task, goal, and thread state. |
|
|
44
44
|
|
|
45
45
|
Adapter support varies by domain. For the full domain list and built-in schemas, see the [storage overview reference](https://mastra.ai/reference/storage/overview).
|
|
46
46
|
|
|
@@ -146,7 +146,7 @@ export const supportAgent = new Agent({
|
|
|
146
146
|
id: 'support-agent',
|
|
147
147
|
name: 'Support agent',
|
|
148
148
|
instructions: 'Answer customer support questions.',
|
|
149
|
-
model: 'openai/gpt-6.
|
|
149
|
+
model: 'openai/gpt-6.2-sol',
|
|
150
150
|
memory: new Memory({
|
|
151
151
|
storage: new PostgresStore({
|
|
152
152
|
id: 'support-agent-storage',
|
|
@@ -45,7 +45,7 @@ const parentAgent = new Agent({
|
|
|
45
45
|
id: 'parent-agent',
|
|
46
46
|
instructions: `You coordinate research and writing using specialized agents.
|
|
47
47
|
Delegate to research-agent for facts, then writing-agent for content.`,
|
|
48
|
-
model: 'openai/gpt-6.
|
|
48
|
+
model: 'openai/gpt-6.2-sol',
|
|
49
49
|
agents: { researchAgent, writingAgent },
|
|
50
50
|
memory: new Memory({
|
|
51
51
|
storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
|
|
@@ -61,6 +61,29 @@ for await (const chunk of stream.textStream) {
|
|
|
61
61
|
}
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
## Delegate to workflows
|
|
65
|
+
|
|
66
|
+
A parent agent can also delegate to workflows. Add them to the [`workflows`](https://mastra.ai/reference/agents/agent) option next to `agents`. Mastra converts each workflow to a `workflow-<key>` tool, the same way it converts each subagent to an `agent-<key>` tool. The model calls the tool with `inputData` that matches the workflow's `inputSchema`, plus `initialState` when the workflow defines a `stateSchema`. The tool starts a new run and returns its `runId` with the workflow `result`. When the run finishes with a failed status, the tool returns the `runId` with an `error` message instead, and the model can read it. When the workflow throws during execution, the tool call fails with an `AGENT_WORKFLOW_TOOL_EXECUTION_FAILED` error. Give each workflow a `description` so the parent agent knows when to use it.
|
|
67
|
+
|
|
68
|
+
A delegation doesn't always finish in one call. When a workflow step suspends, the tool call suspends too, and the parent agent emits a `tool-call-suspended` chunk with the step's `suspendPayload`. Resuming the tool call resumes the same workflow run, not a new one. See [use `suspend()` in supervisor agents](https://mastra.ai/docs/agents/human-in-the-loop).
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { Agent } from '@mastra/core/agent'
|
|
72
|
+
import { researchWorkflow } from '../workflows/research-workflow'
|
|
73
|
+
|
|
74
|
+
// researchAgent and writingAgent are defined in this file, as in the Quickstart
|
|
75
|
+
|
|
76
|
+
const parentAgent = new Agent({
|
|
77
|
+
id: 'parent-agent',
|
|
78
|
+
instructions: 'You coordinate research and writing using specialized agents and workflows.',
|
|
79
|
+
model: 'openai/gpt-6.2-sol',
|
|
80
|
+
agents: { researchAgent, writingAgent },
|
|
81
|
+
workflows: { researchWorkflow }, // tool name: "workflow-researchWorkflow"
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The delegation hooks below run for subagents only. For more on workflow tools, see [Workflows as tools](https://mastra.ai/docs/agents/tools).
|
|
86
|
+
|
|
64
87
|
## Delegation hooks
|
|
65
88
|
|
|
66
89
|
Delegation hooks let you intercept, modify, or reject delegations as they happen. Configure them under the `delegation` option, either in the agent's `defaultOptions` or per-call.
|
|
@@ -438,7 +461,7 @@ import { createRubricScorer } from '@mastra/evals/scorers/prebuilt'
|
|
|
438
461
|
const parentAgent = new Agent({
|
|
439
462
|
id: 'parent-agent',
|
|
440
463
|
instructions: 'You coordinate research and writing using specialized agents.',
|
|
441
|
-
model: 'openai/gpt-6.
|
|
464
|
+
model: 'openai/gpt-6.2-sol',
|
|
442
465
|
agents: { researchAgent, writingAgent },
|
|
443
466
|
})
|
|
444
467
|
|
|
@@ -504,7 +527,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
504
527
|
const parentAgent = new Agent({
|
|
505
528
|
id: 'parent-agent',
|
|
506
529
|
instructions: 'Coordinate research and writing using the available agents.',
|
|
507
|
-
model: 'openai/gpt-6.
|
|
530
|
+
model: 'openai/gpt-6.2-sol',
|
|
508
531
|
agents: { researchAgent, writingAgent },
|
|
509
532
|
backgroundTasks: {
|
|
510
533
|
tools: {
|
|
@@ -105,7 +105,7 @@ export const devAgent = new Agent({
|
|
|
105
105
|
id: 'dev-agent',
|
|
106
106
|
name: 'Development Agent',
|
|
107
107
|
instructions: 'Triage pull request activity and help resolve issues.',
|
|
108
|
-
model: 'openai/gpt-6.
|
|
108
|
+
model: 'openai/gpt-6.2-sol',
|
|
109
109
|
memory: new Memory(),
|
|
110
110
|
signals: [githubSignals],
|
|
111
111
|
})
|
|
@@ -70,7 +70,7 @@ export const homeAgent = new Agent({
|
|
|
70
70
|
id: 'home-agent',
|
|
71
71
|
name: 'Home Agent',
|
|
72
72
|
instructions: 'Watch the front door and say briefly whether each event needs attention.',
|
|
73
|
-
model: 'openai/gpt-6.
|
|
73
|
+
model: 'openai/gpt-6.2-sol',
|
|
74
74
|
memory: new Memory(),
|
|
75
75
|
signals: [new RingSignals()],
|
|
76
76
|
})
|
|
@@ -283,7 +283,7 @@ export const homeAgent = new Agent({
|
|
|
283
283
|
id: 'home-agent',
|
|
284
284
|
name: 'Home Agent',
|
|
285
285
|
instructions: 'Watch the front door and say briefly whether each event needs attention.',
|
|
286
|
-
model: 'openai/gpt-6.
|
|
286
|
+
model: 'openai/gpt-6.2-sol',
|
|
287
287
|
memory: new Memory(),
|
|
288
288
|
channels: {
|
|
289
289
|
resolveResourceId: ({ thread, message, defaultResourceId }) =>
|
|
@@ -245,7 +245,7 @@ export const dsqlAgent = new Agent({
|
|
|
245
245
|
name: 'DSQL Agent',
|
|
246
246
|
instructions:
|
|
247
247
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
248
|
-
model: 'openai/gpt-6.
|
|
248
|
+
model: 'openai/gpt-6.2-sol',
|
|
249
249
|
memory: new Memory({
|
|
250
250
|
storage: new DSQLStore({
|
|
251
251
|
id: 'dsql-agent-storage',
|
|
@@ -110,7 +110,7 @@ export const elasticsearchAgent = new Agent({
|
|
|
110
110
|
name: 'Elasticsearch Agent',
|
|
111
111
|
instructions:
|
|
112
112
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
113
|
-
model: 'openai/gpt-6.
|
|
113
|
+
model: 'openai/gpt-6.2-sol',
|
|
114
114
|
memory: new Memory({
|
|
115
115
|
storage: new ElasticSearchStore({
|
|
116
116
|
id: 'elasticsearch-agent-storage',
|
|
@@ -119,6 +119,12 @@ The storage implementation creates the core storage tables automatically, includ
|
|
|
119
119
|
|
|
120
120
|
`LibSQLStore` exposes notification storage through `getStore('notifications')`.
|
|
121
121
|
|
|
122
|
+
### Pending signals
|
|
123
|
+
|
|
124
|
+
The memory domain keeps the [pending signals](https://mastra.ai/docs/server/pubsub) of evented agents as rows of `mastra_messages` under the reserved thread ID `mastra-queue:pending:<threadId>`, and under `mastra-queue:taken:<threadId>` once a run takes them, without a resource ID. When the run saves its messages, the row moves to its thread and becomes a normal message. Message reads by thread or resource, `updateMessages`, `deleteMessages`, and thread cloning never act on a queued signal, and deleting a thread deletes its queued signals with its messages. Thread IDs that start with `mastra-queue:` are reserved: saving such a thread, cloning to it, or saving or listing its messages fails. Processes share pending signals when the store opens a file or a remote database. An in-memory database (`:memory:`), an embedded replica (`syncUrl`), and a local `client` you pass in keep them to one process. A `file:` URL is shared only by processes on the same machine.
|
|
125
|
+
|
|
126
|
+
`init()` adds one nullable column for pending signals, `signalRunId` on `mastra_threads`. Existing messages and threads are unchanged. A store created with `disableInit: true` reads and saves messages before its migration, because those methods don't use the new column, but it needs `init()` or your own migration run against the database before it sends or claims pending signals.
|
|
127
|
+
|
|
122
128
|
## Initialization
|
|
123
129
|
|
|
124
130
|
When you pass storage to the Mastra class, `init()` is called automatically to create the [core schema](https://mastra.ai/reference/storage/overview):
|
|
@@ -212,7 +212,7 @@ export const mongodbAgent = new Agent({
|
|
|
212
212
|
name: 'mongodb-agent',
|
|
213
213
|
instructions:
|
|
214
214
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
215
|
-
model: 'openai/gpt-6.
|
|
215
|
+
model: 'openai/gpt-6.2-sol',
|
|
216
216
|
memory: new Memory({
|
|
217
217
|
storage: new MongoDBStore({
|
|
218
218
|
id: 'mongodb-storage',
|
|
@@ -228,7 +228,7 @@ export const oracleAgent = new Agent({
|
|
|
228
228
|
id: 'oracle-agent',
|
|
229
229
|
name: 'Oracle Agent',
|
|
230
230
|
instructions: 'You are an assistant with persistent OracleDB-backed memory.',
|
|
231
|
-
model: 'openai/gpt-6.
|
|
231
|
+
model: 'openai/gpt-6.2-sol',
|
|
232
232
|
memory: new Memory({ storage }),
|
|
233
233
|
})
|
|
234
234
|
```
|
|
@@ -140,6 +140,14 @@ The storage implementation handles schema creation and updates automatically. It
|
|
|
140
140
|
|
|
141
141
|
`PostgresStore` exposes notification storage through `getStore('notifications')`.
|
|
142
142
|
|
|
143
|
+
### Pending signals
|
|
144
|
+
|
|
145
|
+
The memory domain keeps the [pending signals](https://mastra.ai/docs/server/pubsub) of evented agents as rows of the messages table under the reserved thread ID `mastra-queue:pending:<threadId>`, and under `mastra-queue:taken:<threadId>` once a run takes them, without a resource ID, and every process that shares the database sees them. When the run saves its messages, the row moves to its thread and becomes a normal message. Message reads by thread or resource, `updateMessages`, `deleteMessages`, and thread cloning never act on a queued signal, and deleting a thread deletes its queued signals with its messages. Thread IDs that start with `mastra-queue:` are reserved: saving such a thread, cloning to it, or saving or listing its messages fails.
|
|
146
|
+
|
|
147
|
+
`init()` adds one nullable column, `signalRunId`, to the threads table. `exportSchemas()` includes it. Message reads and saves don't use this column. If you set `disableInit`, run `init()` once or apply the same column with your own migration, as in [separate schema initialization](#separate-schema-initialization), before the store sends or claims pending signals.
|
|
148
|
+
|
|
149
|
+
`saveMessages`, `updateMessages`, `deleteMessages`, `deleteThread`, and `updateThreadResourceId` run at READ COMMITTED, whatever `default_transaction_isolation` is set to. They lock the thread rows they touch for the whole transaction, so concurrent writes to one thread run one after another. [`prune()`](https://mastra.ai/reference/storage/retention) takes no thread lock and can deadlock with the end of a run whose signals are in the rows it deletes. Postgres then cancels one of the two transactions. When `prune()` is the one cancelled, it rejects with the deadlock error, and you can call it again. When the end of the run is cancelled, Mastra logs the warning `Could not close the stored signals of an ended run`.
|
|
150
|
+
|
|
143
151
|
### Observability
|
|
144
152
|
|
|
145
153
|
PostgreSQL supports observability and can handle low trace volumes. Throughput capacity depends on deployment factors such as hardware, schema design, indexing, and retention policies, and should be validated for your specific environment. For high-volume production environments, consider:
|
|
@@ -442,7 +450,7 @@ export const pgAgent = new Agent({
|
|
|
442
450
|
name: 'PG Agent',
|
|
443
451
|
instructions:
|
|
444
452
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
445
|
-
model: 'openai/gpt-6.
|
|
453
|
+
model: 'openai/gpt-6.2-sol',
|
|
446
454
|
memory: new Memory({
|
|
447
455
|
storage: new PostgresStore({
|
|
448
456
|
id: 'pg-agent-storage',
|
|
@@ -165,7 +165,7 @@ export const redisAgent = new Agent({
|
|
|
165
165
|
name: 'Redis Agent',
|
|
166
166
|
instructions:
|
|
167
167
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
168
|
-
model: 'openai/gpt-6.
|
|
168
|
+
model: 'openai/gpt-6.2-sol',
|
|
169
169
|
memory: new Memory({
|
|
170
170
|
storage: new RedisStore({
|
|
171
171
|
id: 'redis-agent-storage',
|
|
@@ -107,7 +107,7 @@ export const upstashAgent = new Agent({
|
|
|
107
107
|
name: 'Upstash Agent',
|
|
108
108
|
instructions:
|
|
109
109
|
'You are an AI agent with the ability to automatically recall memories from previous interactions.',
|
|
110
|
-
model: 'openai/gpt-6.
|
|
110
|
+
model: 'openai/gpt-6.2-sol',
|
|
111
111
|
memory: new Memory({
|
|
112
112
|
storage: new UpstashStore({
|
|
113
113
|
id: 'upstash-agent-storage',
|
|
@@ -16,7 +16,7 @@ export const agent = new Agent({
|
|
|
16
16
|
id: 'test-agent',
|
|
17
17
|
name: 'test-agent',
|
|
18
18
|
instructions: 'You are an agent with memory.',
|
|
19
|
-
model: 'openai/gpt-6.
|
|
19
|
+
model: 'openai/gpt-6.2-sol',
|
|
20
20
|
memory: new Memory({
|
|
21
21
|
options: {
|
|
22
22
|
workingMemory: {
|
|
@@ -148,7 +148,7 @@ import { LibSQLStore, LibSQLVector } from '@mastra/libsql'
|
|
|
148
148
|
export const agent = new Agent({
|
|
149
149
|
name: 'test-agent',
|
|
150
150
|
instructions: 'You are an agent with memory.',
|
|
151
|
-
model: 'openai/gpt-6.
|
|
151
|
+
model: 'openai/gpt-6.2-sol',
|
|
152
152
|
memory: new Memory({
|
|
153
153
|
storage: new LibSQLStore({
|
|
154
154
|
id: 'test-agent-storage',
|
|
@@ -185,7 +185,7 @@ import { PostgresStore, PgVector } from '@mastra/pg'
|
|
|
185
185
|
export const agent = new Agent({
|
|
186
186
|
name: 'pg-agent',
|
|
187
187
|
instructions: 'You are an agent with optimized PostgreSQL memory.',
|
|
188
|
-
model: 'openai/gpt-6.
|
|
188
|
+
model: 'openai/gpt-6.2-sol',
|
|
189
189
|
memory: new Memory({
|
|
190
190
|
storage: new PostgresStore({
|
|
191
191
|
id: 'pg-agent-storage',
|
|
@@ -214,7 +214,7 @@ export const agent = new Agent({
|
|
|
214
214
|
id: 'health-assistant',
|
|
215
215
|
name: 'health-assistant',
|
|
216
216
|
instructions: 'You are a health and wellness assistant.',
|
|
217
|
-
model: 'openai/gpt-6.
|
|
217
|
+
model: 'openai/gpt-6.2-sol',
|
|
218
218
|
memory: new Memory({
|
|
219
219
|
options: {
|
|
220
220
|
observationalMemory: {
|
|
@@ -250,7 +250,7 @@ export const agent = new Agent({
|
|
|
250
250
|
id: 'my-agent',
|
|
251
251
|
name: 'my-agent',
|
|
252
252
|
instructions: 'You are a helpful assistant.',
|
|
253
|
-
model: 'openai/gpt-6.
|
|
253
|
+
model: 'openai/gpt-6.2-sol',
|
|
254
254
|
memory: new Memory({
|
|
255
255
|
options: {
|
|
256
256
|
observationalMemory: {
|
|
@@ -1121,7 +1121,7 @@ const selector = new ModelByInputTokens({
|
|
|
1121
1121
|
upTo: {
|
|
1122
1122
|
10_000: 'google/gemini-2.5-flash', // Fast for small inputs
|
|
1123
1123
|
40_000: 'openai/gpt-6-luna', // Stronger for medium inputs
|
|
1124
|
-
1_000_000: 'openai/gpt-6.
|
|
1124
|
+
1_000_000: 'openai/gpt-6.2-sol', // Most capable for large inputs
|
|
1125
1125
|
},
|
|
1126
1126
|
})
|
|
1127
1127
|
```
|
|
@@ -107,7 +107,7 @@ export const agent = new Agent({
|
|
|
107
107
|
id: 'context-limited-agent',
|
|
108
108
|
name: 'context-limited-agent',
|
|
109
109
|
instructions: 'You are a helpful assistant',
|
|
110
|
-
model: 'openai/gpt-6.
|
|
110
|
+
model: 'openai/gpt-6.2-sol',
|
|
111
111
|
memory: new Memory({/* ... */}),
|
|
112
112
|
inputProcessors: [
|
|
113
113
|
new TokenLimiterProcessor({ limit: 4000 }), // Limits historical messages to ~4000 tokens
|
|
@@ -127,7 +127,7 @@ export const agent = new Agent({
|
|
|
127
127
|
id: 'multi-step-agent',
|
|
128
128
|
name: 'multi-step-agent',
|
|
129
129
|
instructions: 'You are a helpful research assistant with access to tools',
|
|
130
|
-
model: 'openai/gpt-6.
|
|
130
|
+
model: 'openai/gpt-6.2-sol',
|
|
131
131
|
inputProcessors: [
|
|
132
132
|
new TokenLimiterProcessor({ limit: 8000 }), // Applied at every step
|
|
133
133
|
],
|
|
@@ -153,7 +153,7 @@ export const agent = new Agent({
|
|
|
153
153
|
id: 'response-limited-agent',
|
|
154
154
|
name: 'response-limited-agent',
|
|
155
155
|
instructions: 'You are a helpful assistant',
|
|
156
|
-
model: 'openai/gpt-6.
|
|
156
|
+
model: 'openai/gpt-6.2-sol',
|
|
157
157
|
outputProcessors: [
|
|
158
158
|
new TokenLimiterProcessor({
|
|
159
159
|
limit: 1000,
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("./src-
|
|
2
|
+
const require_src = require("./src-C7wq-aPe.cjs");
|
|
3
3
|
let _mastra_core_processors = require("@mastra/core/processors");
|
|
4
4
|
let _mastra_core_memory = require("@mastra/core/memory");
|
|
5
5
|
exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, D as KnowledgeSemanticIndexCoordinator, t as Memory, n as MessageHistory, y as ModelByInputTokens, M as SUMMARIZE_THREAD_DEFAULTS, r as SemanticRecall, O as StaleKnowledgeSemanticIndexError, k as Subconscious, g as WORKING_MEMORY_STATE_ID, _ as WORKING_MEMORY_STATE_PROCESSOR_ID, i as WorkingMemory, A as WorkingMemoryExtractor, v as WorkingMemoryStateProcessor, a as asUserTurn, j as deepMergeWorkingMemory, o as escapeTurnMarkup, s as extractWorkingMemoryContent, c as extractWorkingMemoryTags, d as getObservationsAsOf, l as removeWorkingMemoryTags, h as resolveAutoModelId, u as sealTurnMarkup, N as summarizeConversation } from "./src-
|
|
1
|
+
export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, D as KnowledgeSemanticIndexCoordinator, t as Memory, n as MessageHistory, y as ModelByInputTokens, M as SUMMARIZE_THREAD_DEFAULTS, r as SemanticRecall, O as StaleKnowledgeSemanticIndexError, k as Subconscious, g as WORKING_MEMORY_STATE_ID, _ as WORKING_MEMORY_STATE_PROCESSOR_ID, i as WorkingMemory, A as WorkingMemoryExtractor, v as WorkingMemoryStateProcessor, a as asUserTurn, j as deepMergeWorkingMemory, o as escapeTurnMarkup, s as extractWorkingMemoryContent, c as extractWorkingMemoryTags, d as getObservationsAsOf, l as removeWorkingMemoryTags, h as resolveAutoModelId, u as sealTurnMarkup, N as summarizeConversation } from "./src-BJGnRDOG.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_src = require("../src-
|
|
2
|
+
const require_src = require("../src-C7wq-aPe.cjs");
|
|
3
3
|
exports.AUTO_MODEL_BY_PROVIDER = require_src.AUTO_MODEL_BY_PROVIDER;
|
|
4
4
|
exports.Extractor = require_src.Extractor;
|
|
5
5
|
exports.ModelByInputTokens = require_src.ModelByInputTokens;
|
package/dist/processors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, y as ModelByInputTokens, q as OBSERVATIONAL_MEMORY_DEFAULTS, J as OBSERVATION_CONTEXT_INSTRUCTIONS, Y as OBSERVATION_CONTEXT_PROMPT, X as OBSERVATION_CONTEXT_PROMPT_THREAD, Z as OBSERVATION_CONTINUATION_HINT, F as OBSERVER_SYSTEM_PROMPT, p as ObservationalMemory, f as ObservationalMemoryProcessor, P as TokenCounter, A as WorkingMemoryExtractor, I as buildObserverPrompt, L as buildObserverSystemPrompt, b as combineObservationGroupRanges, x as deriveObservationGroupProvenance, R as extractCurrentTask, z as formatMessagesForObserver, Q as getObservationContextPrompt, d as getObservationsAsOf, B as hasCurrentTaskSection, U as injectAnchorIds, V as optimizeObservationsForContext, W as parseAnchorId, S as parseObservationGroups, H as parseObserverOutput, C as reconcileObservationGroupsFromReflection, w as renderObservationGroupsForReflection, h as resolveAutoModelId, G as stripEphemeralAnchorIds, T as stripObservationGroups, N as summarizeConversation, E as wrapInObservationGroup } from "../src-
|
|
1
|
+
export { m as AUTO_MODEL_BY_PROVIDER, K as Extractor, y as ModelByInputTokens, q as OBSERVATIONAL_MEMORY_DEFAULTS, J as OBSERVATION_CONTEXT_INSTRUCTIONS, Y as OBSERVATION_CONTEXT_PROMPT, X as OBSERVATION_CONTEXT_PROMPT_THREAD, Z as OBSERVATION_CONTINUATION_HINT, F as OBSERVER_SYSTEM_PROMPT, p as ObservationalMemory, f as ObservationalMemoryProcessor, P as TokenCounter, A as WorkingMemoryExtractor, I as buildObserverPrompt, L as buildObserverSystemPrompt, b as combineObservationGroupRanges, x as deriveObservationGroupProvenance, R as extractCurrentTask, z as formatMessagesForObserver, Q as getObservationContextPrompt, d as getObservationsAsOf, B as hasCurrentTaskSection, U as injectAnchorIds, V as optimizeObservationsForContext, W as parseAnchorId, S as parseObservationGroups, H as parseObserverOutput, C as reconcileObservationGroupsFromReflection, w as renderObservationGroupsForReflection, h as resolveAutoModelId, G as stripEphemeralAnchorIds, T as stripObservationGroups, N as summarizeConversation, E as wrapInObservationGroup } from "../src-BJGnRDOG.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProcessLLMRequestArgs } from '@mastra/core/processors';
|
|
2
|
+
type Prompt = ProcessLLMRequestArgs['prompt'];
|
|
3
|
+
/**
|
|
4
|
+
* Hints where the stable part of memory's context ends: the last observation chunk.
|
|
5
|
+
*
|
|
6
|
+
* Memory renders each observation chunk as its own closed `<observations>` block, newest last, and puts what
|
|
7
|
+
* changes more often (date hints, the current task, the suggested response) after them. An update that only adds
|
|
8
|
+
* chunks leaves every earlier message unchanged, so a prompt cache that ends on the last chunk stays valid.
|
|
9
|
+
*
|
|
10
|
+
* The hint is `providerOptions.mastra.cacheBoundary: true`, set on the prompt of one model call only, so it is never
|
|
11
|
+
* stored. Provider adapters never forward `providerOptions.mastra`; a model adapter that supports prompt caching can
|
|
12
|
+
* turn it into a real cache mark within its own limits.
|
|
13
|
+
*
|
|
14
|
+
* Chat Completions endpoints (`*.chat`) get no hint: core merges their leading system messages into one and skips the
|
|
15
|
+
* merge when an earlier message carries `providerOptions`. Only a chunk memory rendered itself is hinted: `rendered` is the
|
|
16
|
+
* text of the system messages memory tagged in the message list this step, so an instruction that only looks like a
|
|
17
|
+
* chunk is never hinted. Returns `undefined` when nothing is hinted.
|
|
18
|
+
*/
|
|
19
|
+
export declare function markObservationCacheBoundary(prompt: Prompt, apiProviderId: string | undefined, rendered: readonly unknown[] | undefined): Prompt | undefined;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=cache-boundary.d.ts.map
|
|
@@ -2,7 +2,7 @@ import type { MastraDBMessage, MessageList } from '@mastra/core/agent';
|
|
|
2
2
|
import type { MemoryRunState } from '@mastra/core/memory';
|
|
3
3
|
import type { MemoryOperationAttributes } from '@mastra/core/observability';
|
|
4
4
|
import { SpanType } from '@mastra/core/observability';
|
|
5
|
-
import type { Processor, ProcessAPIErrorArgs, ProcessAPIErrorResult, ProcessInputStepArgs, ProcessOutputResultArgs, ProcessorSpanPhase } from '@mastra/core/processors';
|
|
5
|
+
import type { Processor, ProcessAPIErrorArgs, ProcessAPIErrorResult, ProcessInputStepArgs, ProcessLLMRequestArgs, ProcessLLMRequestResult, ProcessOutputResultArgs, ProcessorSpanPhase } from '@mastra/core/processors';
|
|
6
6
|
import type { ObservationalMemoryRecord } from '@mastra/core/storage';
|
|
7
7
|
import type { ObservationalMemory } from './observational-memory.js';
|
|
8
8
|
/** Subset of Memory that the processor needs — avoids circular imports. */
|
|
@@ -56,6 +56,8 @@ export declare class ObservationalMemoryProcessor implements Processor<'observat
|
|
|
56
56
|
*/
|
|
57
57
|
private endActiveTurn;
|
|
58
58
|
processInputStep(args: ProcessInputStepArgs): Promise<MessageList | MastraDBMessage[]>;
|
|
59
|
+
/** Hints memory's cache boundary on this model call's prompt only, so the hint is never stored. */
|
|
60
|
+
processLLMRequest({ prompt, model, apiProviderId, messageList }: ProcessLLMRequestArgs): ProcessLLMRequestResult;
|
|
59
61
|
processOutputResult(args: ProcessOutputResultArgs): Promise<MessageList | MastraDBMessage[]>;
|
|
60
62
|
processAPIError(args: ProcessAPIErrorArgs): Promise<ProcessAPIErrorResult | void>;
|
|
61
63
|
get config(): {
|
|
@@ -22,6 +22,8 @@ export declare function calculateDynamicThreshold(threshold: number | ThresholdR
|
|
|
22
22
|
* Resolve bufferTokens config value.
|
|
23
23
|
* Values in (0, 1) are treated as ratios of the message threshold.
|
|
24
24
|
* e.g. bufferTokens: 0.25 with messageTokens: 20_000 → 5_000
|
|
25
|
+
* Ratios resolve to at least 1 and below the threshold, so tiny thresholds
|
|
26
|
+
* (e.g. messageTokens: 2) don't round to 0 or up to the threshold itself.
|
|
25
27
|
*/
|
|
26
28
|
export declare function resolveBufferTokens(bufferTokens: number | false | undefined, messageTokens: number | ThresholdRange): number | undefined;
|
|
27
29
|
/**
|
|
@@ -33697,11 +33697,16 @@ function calculateDynamicThreshold(threshold, currentObservationTokens) {
|
|
|
33697
33697
|
* Resolve bufferTokens config value.
|
|
33698
33698
|
* Values in (0, 1) are treated as ratios of the message threshold.
|
|
33699
33699
|
* e.g. bufferTokens: 0.25 with messageTokens: 20_000 → 5_000
|
|
33700
|
+
* Ratios resolve to at least 1 and below the threshold, so tiny thresholds
|
|
33701
|
+
* (e.g. messageTokens: 2) don't round to 0 or up to the threshold itself.
|
|
33700
33702
|
*/
|
|
33701
33703
|
function resolveBufferTokens(bufferTokens, messageTokens) {
|
|
33702
33704
|
if (bufferTokens === false) return void 0;
|
|
33703
33705
|
if (bufferTokens === void 0) return void 0;
|
|
33704
|
-
if (bufferTokens > 0 && bufferTokens < 1)
|
|
33706
|
+
if (bufferTokens > 0 && bufferTokens < 1) {
|
|
33707
|
+
const threshold = getMaxThreshold(messageTokens);
|
|
33708
|
+
return Math.max(1, Math.min(Math.round(threshold * bufferTokens), threshold - 1));
|
|
33709
|
+
}
|
|
33705
33710
|
return bufferTokens;
|
|
33706
33711
|
}
|
|
33707
33712
|
/**
|
|
@@ -38553,7 +38558,10 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
38553
38558
|
const observationThreshold = getMaxThreshold(this.observationConfig.messageTokens);
|
|
38554
38559
|
if (this.observationConfig.bufferTokens !== void 0) {
|
|
38555
38560
|
if (this.observationConfig.bufferTokens <= 0) throw new Error(`observation.bufferTokens must be > 0, got ${this.observationConfig.bufferTokens}`);
|
|
38556
|
-
if (this.observationConfig.bufferTokens >= observationThreshold)
|
|
38561
|
+
if (this.observationConfig.bufferTokens >= observationThreshold) {
|
|
38562
|
+
if (observationThreshold < 2) throw new Error(`observation.messageTokens must be at least 2 when async buffering is enabled, got ${observationThreshold}. Set observation: { bufferTokens: false } to use a smaller messageTokens.`);
|
|
38563
|
+
throw new Error(`observation.bufferTokens (${this.observationConfig.bufferTokens}) must be less than messageTokens (${observationThreshold})`);
|
|
38564
|
+
}
|
|
38557
38565
|
}
|
|
38558
38566
|
if (this.observationConfig.bufferActivation !== void 0) {
|
|
38559
38567
|
if (this.observationConfig.bufferActivation <= 0) throw new Error(`observation.bufferActivation must be > 0, got ${this.observationConfig.bufferActivation}`);
|
|
@@ -40032,15 +40040,16 @@ ${formattedMessages}
|
|
|
40032
40040
|
transient: true
|
|
40033
40041
|
}).catch(() => {});
|
|
40034
40042
|
let chunkRecorded = false;
|
|
40043
|
+
const bufferedBoundary = Math.max(currentTokens, newTokens);
|
|
40035
40044
|
const recordBufferedChunk = async () => {
|
|
40036
40045
|
if (chunkRecorded) return;
|
|
40037
40046
|
chunkRecorded = true;
|
|
40038
40047
|
const ownsBoundary = BufferingCoordinator.ownsObservationBoundary(bufferKey, boundaryOwner);
|
|
40039
|
-
if (ownsBoundary) BufferingCoordinator.setObservationBoundary(bufferKey,
|
|
40040
|
-
await runOMCommit(lockKey, () => this.storage.setBufferingObservationFlag(record.id, false, ownsBoundary ?
|
|
40048
|
+
if (ownsBoundary) BufferingCoordinator.setObservationBoundary(bufferKey, bufferedBoundary, boundaryOwner);
|
|
40049
|
+
await runOMCommit(lockKey, () => this.storage.setBufferingObservationFlag(record.id, false, ownsBoundary ? bufferedBoundary : void 0)).catch(() => {});
|
|
40041
40050
|
flagCleared = true;
|
|
40042
40051
|
const stillOwnsBoundary = ownsBoundary && BufferingCoordinator.ownsObservationBoundary(bufferKey, boundaryOwner);
|
|
40043
|
-
setBufferingState(false, stillOwnsBoundary ?
|
|
40052
|
+
setBufferingState(false, stillOwnsBoundary ? bufferedBoundary : void 0);
|
|
40044
40053
|
const maxTimestamp = this.getMaxMessageTimestamp(candidateMessages);
|
|
40045
40054
|
BufferingCoordinator.lastBufferedAtTime.set(bufferKey, new Date(maxTimestamp.getTime() + 1));
|
|
40046
40055
|
releaseChunkWrite();
|
|
@@ -40748,6 +40757,44 @@ ${formattedMessages}
|
|
|
40748
40757
|
});
|
|
40749
40758
|
}
|
|
40750
40759
|
};
|
|
40760
|
+
// src/processors/observational-memory/cache-boundary.ts
|
|
40761
|
+
/**
|
|
40762
|
+
* Hints where the stable part of memory's context ends: the last observation chunk.
|
|
40763
|
+
*
|
|
40764
|
+
* Memory renders each observation chunk as its own closed `<observations>` block, newest last, and puts what
|
|
40765
|
+
* changes more often (date hints, the current task, the suggested response) after them. An update that only adds
|
|
40766
|
+
* chunks leaves every earlier message unchanged, so a prompt cache that ends on the last chunk stays valid.
|
|
40767
|
+
*
|
|
40768
|
+
* The hint is `providerOptions.mastra.cacheBoundary: true`, set on the prompt of one model call only, so it is never
|
|
40769
|
+
* stored. Provider adapters never forward `providerOptions.mastra`; a model adapter that supports prompt caching can
|
|
40770
|
+
* turn it into a real cache mark within its own limits.
|
|
40771
|
+
*
|
|
40772
|
+
* Chat Completions endpoints (`*.chat`) get no hint: core merges their leading system messages into one and skips the
|
|
40773
|
+
* merge when an earlier message carries `providerOptions`. Only a chunk memory rendered itself is hinted: `rendered` is the
|
|
40774
|
+
* text of the system messages memory tagged in the message list this step, so an instruction that only looks like a
|
|
40775
|
+
* chunk is never hinted. Returns `undefined` when nothing is hinted.
|
|
40776
|
+
*/
|
|
40777
|
+
function markObservationCacheBoundary(prompt, apiProviderId, rendered) {
|
|
40778
|
+
if (!apiProviderId || apiProviderId.endsWith(".chat")) return void 0;
|
|
40779
|
+
const chunks = new Set(rendered?.filter((content) => typeof content === "string" && isObservationChunk(content)));
|
|
40780
|
+
if (chunks.size === 0) return void 0;
|
|
40781
|
+
let boundary = -1;
|
|
40782
|
+
prompt.forEach((message, index) => {
|
|
40783
|
+
if (message.role === "system" && chunks.has(message.content)) boundary = index;
|
|
40784
|
+
});
|
|
40785
|
+
if (boundary < 0) return void 0;
|
|
40786
|
+
return prompt.map((message, index) => index === boundary ? {
|
|
40787
|
+
...message,
|
|
40788
|
+
providerOptions: {
|
|
40789
|
+
...message.providerOptions,
|
|
40790
|
+
mastra: {
|
|
40791
|
+
...message.providerOptions?.mastra,
|
|
40792
|
+
cacheBoundary: true
|
|
40793
|
+
}
|
|
40794
|
+
}
|
|
40795
|
+
} : message);
|
|
40796
|
+
}
|
|
40797
|
+
const isObservationChunk = (content) => content.startsWith("<observations>\n") && content.endsWith("\n</observations>");
|
|
40751
40798
|
// src/processors/observational-memory/temporal-markers.ts
|
|
40752
40799
|
const TEMPORAL_GAP_REMINDER_TYPE = "temporal-gap";
|
|
40753
40800
|
function getTemporalGapReminderText(gapText, timestamp) {
|
|
@@ -41169,6 +41216,13 @@ var ObservationalMemoryProcessor = class {
|
|
|
41169
41216
|
return messageList;
|
|
41170
41217
|
});
|
|
41171
41218
|
}
|
|
41219
|
+
/** Hints memory's cache boundary on this model call's prompt only, so the hint is never stored. */
|
|
41220
|
+
processLLMRequest({ prompt, model, apiProviderId, messageList }) {
|
|
41221
|
+
const provider = apiProviderId ?? (typeof model?.provider === "string" ? model.provider : void 0);
|
|
41222
|
+
const rendered = messageList?.getSystemMessages("observational-memory").map((message) => message.content);
|
|
41223
|
+
const hinted = markObservationCacheBoundary(prompt, provider, rendered);
|
|
41224
|
+
return hinted ? { prompt: hinted } : void 0;
|
|
41225
|
+
}
|
|
41172
41226
|
async processOutputResult(args) {
|
|
41173
41227
|
const { messageList, requestContext, state: _state } = args;
|
|
41174
41228
|
const state = _state ?? {};
|
|
@@ -33719,11 +33719,16 @@ function calculateDynamicThreshold(threshold, currentObservationTokens) {
|
|
|
33719
33719
|
* Resolve bufferTokens config value.
|
|
33720
33720
|
* Values in (0, 1) are treated as ratios of the message threshold.
|
|
33721
33721
|
* e.g. bufferTokens: 0.25 with messageTokens: 20_000 → 5_000
|
|
33722
|
+
* Ratios resolve to at least 1 and below the threshold, so tiny thresholds
|
|
33723
|
+
* (e.g. messageTokens: 2) don't round to 0 or up to the threshold itself.
|
|
33722
33724
|
*/
|
|
33723
33725
|
function resolveBufferTokens(bufferTokens, messageTokens) {
|
|
33724
33726
|
if (bufferTokens === false) return void 0;
|
|
33725
33727
|
if (bufferTokens === void 0) return void 0;
|
|
33726
|
-
if (bufferTokens > 0 && bufferTokens < 1)
|
|
33728
|
+
if (bufferTokens > 0 && bufferTokens < 1) {
|
|
33729
|
+
const threshold = getMaxThreshold(messageTokens);
|
|
33730
|
+
return Math.max(1, Math.min(Math.round(threshold * bufferTokens), threshold - 1));
|
|
33731
|
+
}
|
|
33727
33732
|
return bufferTokens;
|
|
33728
33733
|
}
|
|
33729
33734
|
/**
|
|
@@ -38575,7 +38580,10 @@ var ObservationalMemory = class ObservationalMemory {
|
|
|
38575
38580
|
const observationThreshold = getMaxThreshold(this.observationConfig.messageTokens);
|
|
38576
38581
|
if (this.observationConfig.bufferTokens !== void 0) {
|
|
38577
38582
|
if (this.observationConfig.bufferTokens <= 0) throw new Error(`observation.bufferTokens must be > 0, got ${this.observationConfig.bufferTokens}`);
|
|
38578
|
-
if (this.observationConfig.bufferTokens >= observationThreshold)
|
|
38583
|
+
if (this.observationConfig.bufferTokens >= observationThreshold) {
|
|
38584
|
+
if (observationThreshold < 2) throw new Error(`observation.messageTokens must be at least 2 when async buffering is enabled, got ${observationThreshold}. Set observation: { bufferTokens: false } to use a smaller messageTokens.`);
|
|
38585
|
+
throw new Error(`observation.bufferTokens (${this.observationConfig.bufferTokens}) must be less than messageTokens (${observationThreshold})`);
|
|
38586
|
+
}
|
|
38579
38587
|
}
|
|
38580
38588
|
if (this.observationConfig.bufferActivation !== void 0) {
|
|
38581
38589
|
if (this.observationConfig.bufferActivation <= 0) throw new Error(`observation.bufferActivation must be > 0, got ${this.observationConfig.bufferActivation}`);
|
|
@@ -40054,15 +40062,16 @@ ${formattedMessages}
|
|
|
40054
40062
|
transient: true
|
|
40055
40063
|
}).catch(() => {});
|
|
40056
40064
|
let chunkRecorded = false;
|
|
40065
|
+
const bufferedBoundary = Math.max(currentTokens, newTokens);
|
|
40057
40066
|
const recordBufferedChunk = async () => {
|
|
40058
40067
|
if (chunkRecorded) return;
|
|
40059
40068
|
chunkRecorded = true;
|
|
40060
40069
|
const ownsBoundary = BufferingCoordinator.ownsObservationBoundary(bufferKey, boundaryOwner);
|
|
40061
|
-
if (ownsBoundary) BufferingCoordinator.setObservationBoundary(bufferKey,
|
|
40062
|
-
await runOMCommit(lockKey, () => this.storage.setBufferingObservationFlag(record.id, false, ownsBoundary ?
|
|
40070
|
+
if (ownsBoundary) BufferingCoordinator.setObservationBoundary(bufferKey, bufferedBoundary, boundaryOwner);
|
|
40071
|
+
await runOMCommit(lockKey, () => this.storage.setBufferingObservationFlag(record.id, false, ownsBoundary ? bufferedBoundary : void 0)).catch(() => {});
|
|
40063
40072
|
flagCleared = true;
|
|
40064
40073
|
const stillOwnsBoundary = ownsBoundary && BufferingCoordinator.ownsObservationBoundary(bufferKey, boundaryOwner);
|
|
40065
|
-
setBufferingState(false, stillOwnsBoundary ?
|
|
40074
|
+
setBufferingState(false, stillOwnsBoundary ? bufferedBoundary : void 0);
|
|
40066
40075
|
const maxTimestamp = this.getMaxMessageTimestamp(candidateMessages);
|
|
40067
40076
|
BufferingCoordinator.lastBufferedAtTime.set(bufferKey, new Date(maxTimestamp.getTime() + 1));
|
|
40068
40077
|
releaseChunkWrite();
|
|
@@ -40770,6 +40779,44 @@ ${formattedMessages}
|
|
|
40770
40779
|
});
|
|
40771
40780
|
}
|
|
40772
40781
|
};
|
|
40782
|
+
// src/processors/observational-memory/cache-boundary.ts
|
|
40783
|
+
/**
|
|
40784
|
+
* Hints where the stable part of memory's context ends: the last observation chunk.
|
|
40785
|
+
*
|
|
40786
|
+
* Memory renders each observation chunk as its own closed `<observations>` block, newest last, and puts what
|
|
40787
|
+
* changes more often (date hints, the current task, the suggested response) after them. An update that only adds
|
|
40788
|
+
* chunks leaves every earlier message unchanged, so a prompt cache that ends on the last chunk stays valid.
|
|
40789
|
+
*
|
|
40790
|
+
* The hint is `providerOptions.mastra.cacheBoundary: true`, set on the prompt of one model call only, so it is never
|
|
40791
|
+
* stored. Provider adapters never forward `providerOptions.mastra`; a model adapter that supports prompt caching can
|
|
40792
|
+
* turn it into a real cache mark within its own limits.
|
|
40793
|
+
*
|
|
40794
|
+
* Chat Completions endpoints (`*.chat`) get no hint: core merges their leading system messages into one and skips the
|
|
40795
|
+
* merge when an earlier message carries `providerOptions`. Only a chunk memory rendered itself is hinted: `rendered` is the
|
|
40796
|
+
* text of the system messages memory tagged in the message list this step, so an instruction that only looks like a
|
|
40797
|
+
* chunk is never hinted. Returns `undefined` when nothing is hinted.
|
|
40798
|
+
*/
|
|
40799
|
+
function markObservationCacheBoundary(prompt, apiProviderId, rendered) {
|
|
40800
|
+
if (!apiProviderId || apiProviderId.endsWith(".chat")) return void 0;
|
|
40801
|
+
const chunks = new Set(rendered?.filter((content) => typeof content === "string" && isObservationChunk(content)));
|
|
40802
|
+
if (chunks.size === 0) return void 0;
|
|
40803
|
+
let boundary = -1;
|
|
40804
|
+
prompt.forEach((message, index) => {
|
|
40805
|
+
if (message.role === "system" && chunks.has(message.content)) boundary = index;
|
|
40806
|
+
});
|
|
40807
|
+
if (boundary < 0) return void 0;
|
|
40808
|
+
return prompt.map((message, index) => index === boundary ? {
|
|
40809
|
+
...message,
|
|
40810
|
+
providerOptions: {
|
|
40811
|
+
...message.providerOptions,
|
|
40812
|
+
mastra: {
|
|
40813
|
+
...message.providerOptions?.mastra,
|
|
40814
|
+
cacheBoundary: true
|
|
40815
|
+
}
|
|
40816
|
+
}
|
|
40817
|
+
} : message);
|
|
40818
|
+
}
|
|
40819
|
+
const isObservationChunk = (content) => content.startsWith("<observations>\n") && content.endsWith("\n</observations>");
|
|
40773
40820
|
// src/processors/observational-memory/temporal-markers.ts
|
|
40774
40821
|
const TEMPORAL_GAP_REMINDER_TYPE = "temporal-gap";
|
|
40775
40822
|
function getTemporalGapReminderText(gapText, timestamp) {
|
|
@@ -41191,6 +41238,13 @@ var ObservationalMemoryProcessor = class {
|
|
|
41191
41238
|
return messageList;
|
|
41192
41239
|
});
|
|
41193
41240
|
}
|
|
41241
|
+
/** Hints memory's cache boundary on this model call's prompt only, so the hint is never stored. */
|
|
41242
|
+
processLLMRequest({ prompt, model, apiProviderId, messageList }) {
|
|
41243
|
+
const provider = apiProviderId ?? (typeof model?.provider === "string" ? model.provider : void 0);
|
|
41244
|
+
const rendered = messageList?.getSystemMessages("observational-memory").map((message) => message.content);
|
|
41245
|
+
const hinted = markObservationCacheBoundary(prompt, provider, rendered);
|
|
41246
|
+
return hinted ? { prompt: hinted } : void 0;
|
|
41247
|
+
}
|
|
41194
41248
|
async processOutputResult(args) {
|
|
41195
41249
|
const { messageList, requestContext, state: _state } = args;
|
|
41196
41250
|
const state = _state ?? {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "1.42.0-alpha.
|
|
3
|
+
"version": "1.42.0-alpha.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"tsx": "^4.23.15",
|
|
68
68
|
"typescript": "^6.0.3",
|
|
69
69
|
"vitest": "5.1.0",
|
|
70
|
-
"@internal/ai-sdk-v4": "0.0.99",
|
|
71
70
|
"@internal/ai-sdk-v5": "0.0.99",
|
|
72
|
-
"@internal/ai-v6": "0.0.99",
|
|
73
|
-
"@internal/ai-v7": "0.0.99",
|
|
74
71
|
"@internal/lint": "0.0.152",
|
|
75
72
|
"@internal/types-builder": "0.0.127",
|
|
76
|
-
"@mastra/core": "1.87.0-alpha.
|
|
73
|
+
"@mastra/core": "1.87.0-alpha.15",
|
|
74
|
+
"@internal/ai-v6": "0.0.99",
|
|
75
|
+
"@internal/ai-v7": "0.0.99",
|
|
76
|
+
"@internal/ai-sdk-v4": "0.0.99"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"@mastra/core": ">=1.85.1-0 <2.0.0-0"
|