@mastra/memory 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012
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 +461 -3
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +51 -5
- package/dist/{chunk-4FMHSWZD.cjs → chunk-6ODYOMHN.cjs} +1279 -492
- package/dist/chunk-6ODYOMHN.cjs.map +1 -0
- package/dist/{chunk-C7PARRAD.js → chunk-Z5GWA7LB.js} +1280 -493
- package/dist/chunk-Z5GWA7LB.js.map +1 -0
- package/dist/{constants-HXOCZPB7.cjs → constants-PJXB7ZIS.cjs} +2 -2
- package/dist/{constants-HXOCZPB7.cjs.map → constants-PJXB7ZIS.cjs.map} +1 -1
- package/dist/{constants-BDOITAO3.js → constants-XEHPYRDJ.js} +2 -2
- package/dist/{constants-BDOITAO3.js.map → constants-XEHPYRDJ.js.map} +1 -1
- package/dist/docs/SKILL.md +3 -1
- package/dist/docs/assets/SOURCE_MAP.json +47 -59
- package/dist/docs/references/docs-agents-background-tasks.md +242 -0
- package/dist/docs/references/docs-agents-supervisor-agents.md +65 -0
- package/dist/docs/references/docs-memory-memory-processors.md +3 -3
- package/dist/docs/references/docs-memory-message-history.md +8 -2
- package/dist/docs/references/docs-memory-observational-memory.md +65 -8
- package/dist/docs/references/docs-memory-storage.md +1 -2
- package/dist/docs/references/docs-memory-working-memory.md +2 -2
- package/dist/docs/references/reference-memory-clone-utilities.md +4 -2
- package/dist/docs/references/reference-memory-cloneThread.md +4 -2
- package/dist/docs/references/reference-memory-observational-memory.md +4 -0
- package/dist/docs/references/reference-storage-redis.md +266 -0
- package/dist/docs/references/reference-vectors-mongodb.md +0 -2
- package/dist/index.cjs +1168 -553
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +35 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1158 -535
- package/dist/index.js.map +1 -1
- package/dist/{observational-memory-5YDQLKHE.cjs → observational-memory-OVSEK47Z.cjs} +26 -26
- package/dist/{observational-memory-5YDQLKHE.cjs.map → observational-memory-OVSEK47Z.cjs.map} +1 -1
- package/dist/{observational-memory-B7AUSTEY.js → observational-memory-UMDC4VC2.js} +3 -3
- package/dist/{observational-memory-B7AUSTEY.js.map → observational-memory-UMDC4VC2.js.map} +1 -1
- package/dist/processors/index.cjs +24 -24
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/date-utils.d.ts +6 -0
- package/dist/processors/observational-memory/date-utils.d.ts.map +1 -1
- package/dist/processors/observational-memory/index.d.ts +1 -1
- package/dist/processors/observational-memory/index.d.ts.map +1 -1
- package/dist/processors/observational-memory/markers.d.ts +5 -0
- package/dist/processors/observational-memory/markers.d.ts.map +1 -1
- package/dist/processors/observational-memory/message-utils.d.ts.map +1 -1
- package/dist/processors/observational-memory/model-context.d.ts +10 -0
- package/dist/processors/observational-memory/model-context.d.ts.map +1 -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 +3 -3
- package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-strategies/types.d.ts +9 -0
- package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +6 -2
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/types.d.ts +1 -0
- package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -1
- package/dist/processors/observational-memory/observational-memory.d.ts +54 -3
- package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
- package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts +5 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/dist/processors/observational-memory/reflector-runner.d.ts +14 -2
- package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
- package/dist/processors/observational-memory/repro-capture.d.ts +8 -0
- package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -1
- package/dist/processors/observational-memory/string-utils.d.ts +13 -0
- package/dist/processors/observational-memory/string-utils.d.ts.map +1 -0
- package/dist/processors/observational-memory/temporal-markers.d.ts +4 -0
- package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -0
- package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
- package/dist/processors/observational-memory/types.d.ts +56 -2
- package/dist/processors/observational-memory/types.d.ts.map +1 -1
- package/dist/tools/om-tools.d.ts +14 -2
- package/dist/tools/om-tools.d.ts.map +1 -1
- package/dist/tools/working-memory.d.ts.map +1 -1
- package/package.json +15 -15
- package/dist/chunk-3PUO6DLX.js +0 -439
- package/dist/chunk-3PUO6DLX.js.map +0 -1
- package/dist/chunk-4FMHSWZD.cjs.map +0 -1
- package/dist/chunk-C7PARRAD.js.map +0 -1
- package/dist/chunk-CK4U3AYR.cjs +0 -84
- package/dist/chunk-CK4U3AYR.cjs.map +0 -1
- package/dist/chunk-DAJJSFVA.cjs +0 -441
- package/dist/chunk-DAJJSFVA.cjs.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -10
- package/dist/chunk-DGUM43GV.js.map +0 -1
- package/dist/chunk-EQ4M72KU.js +0 -439
- package/dist/chunk-EQ4M72KU.js.map +0 -1
- package/dist/chunk-IDRQZVB4.cjs +0 -84
- package/dist/chunk-IDRQZVB4.cjs.map +0 -1
- package/dist/chunk-JEQ2X3Z6.cjs +0 -12
- package/dist/chunk-JEQ2X3Z6.cjs.map +0 -1
- package/dist/chunk-RC6RZVYE.js +0 -79
- package/dist/chunk-RC6RZVYE.js.map +0 -1
- package/dist/chunk-SVPZMV27.js +0 -79
- package/dist/chunk-SVPZMV27.js.map +0 -1
- package/dist/chunk-ZD3BKU5O.cjs +0 -441
- package/dist/chunk-ZD3BKU5O.cjs.map +0 -1
- package/dist/token-APYSY3BW-2DN6RAUY.js +0 -61
- package/dist/token-APYSY3BW-2DN6RAUY.js.map +0 -1
- package/dist/token-APYSY3BW-POD4OUWN.cjs +0 -63
- package/dist/token-APYSY3BW-POD4OUWN.cjs.map +0 -1
- package/dist/token-APYSY3BW-YTVQELJT.js +0 -61
- package/dist/token-APYSY3BW-YTVQELJT.js.map +0 -1
- package/dist/token-APYSY3BW-ZQ7TMBY7.cjs +0 -63
- package/dist/token-APYSY3BW-ZQ7TMBY7.cjs.map +0 -1
- package/dist/token-util-RMHT2CPJ-6TGPE335.cjs +0 -10
- package/dist/token-util-RMHT2CPJ-6TGPE335.cjs.map +0 -1
- package/dist/token-util-RMHT2CPJ-77HHGIQN.cjs +0 -10
- package/dist/token-util-RMHT2CPJ-77HHGIQN.cjs.map +0 -1
- package/dist/token-util-RMHT2CPJ-RJEA3FAN.js +0 -8
- package/dist/token-util-RMHT2CPJ-RJEA3FAN.js.map +0 -1
- package/dist/token-util-RMHT2CPJ-WJZ2SYAR.js +0 -8
- package/dist/token-util-RMHT2CPJ-WJZ2SYAR.js.map +0 -1
|
@@ -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-PJXB7ZIS.cjs.map
|
|
28
|
+
//# sourceMappingURL=constants-PJXB7ZIS.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-PJXB7ZIS.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-XEHPYRDJ.js.map
|
|
3
|
+
//# sourceMappingURL=constants-XEHPYRDJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"constants-XEHPYRDJ.js"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-memory
|
|
|
3
3
|
description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/memory"
|
|
6
|
-
version: "0.0.0-studio-
|
|
6
|
+
version: "0.0.0-studio-cli-20260504022012"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -17,6 +17,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
17
17
|
### Docs
|
|
18
18
|
|
|
19
19
|
- [Agent approval](references/docs-agents-agent-approval.md) - Learn how to require approvals, suspend tool execution, and automatically resume suspended tools while keeping humans in control of agent workflows.
|
|
20
|
+
- [Background tasks](references/docs-agents-background-tasks.md) - Learn how to dispatch long-running tool calls in the background, keep the stream open until they complete, and orchestrate subagents asynchronously.
|
|
20
21
|
- [Agent networks](references/docs-agents-networks.md) - Coordinate multiple agents, workflows, and tools using agent networks for complex, non-deterministic task execution.
|
|
21
22
|
- [Supervisor agents](references/docs-agents-supervisor-agents.md) - Learn how to coordinate multiple agents with delegation hooks, iteration monitoring, message filtering, and task completion scoring.
|
|
22
23
|
- [Memory processors](references/docs-memory-memory-processors.md) - Learn how to use memory processors in Mastra to filter, trim, and transform messages before they're sent to the language model to manage context window limits.
|
|
@@ -43,6 +44,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
43
44
|
- [Reference: libSQL storage](references/reference-storage-libsql.md) - Documentation for the libSQL storage implementation in Mastra.
|
|
44
45
|
- [Reference: MongoDB storage](references/reference-storage-mongodb.md) - Documentation for the MongoDB storage implementation in Mastra.
|
|
45
46
|
- [Reference: PostgreSQL storage](references/reference-storage-postgresql.md) - Documentation for the PostgreSQL storage implementation in Mastra.
|
|
47
|
+
- [Reference: Redis Storage](references/reference-storage-redis.md) - Documentation for the Redis storage implementation in Mastra.
|
|
46
48
|
- [Reference: Upstash storage](references/reference-storage-upstash.md) - Documentation for the Upstash storage implementation in Mastra.
|
|
47
49
|
- [Reference: libSQL vector store](references/reference-vectors-libsql.md) - Documentation for the LibSQLVector class in Mastra, which provides vector search using libSQL with vector extensions.
|
|
48
50
|
- [Reference: MongoDB vector store](references/reference-vectors-mongodb.md) - Documentation for the MongoDBVector class in Mastra, which provides vector search using MongoDB Atlas and Atlas Vector Search.
|
|
@@ -1,120 +1,120 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.0-studio-
|
|
2
|
+
"version": "0.0.0-studio-cli-20260504022012",
|
|
3
3
|
"package": "@mastra/memory",
|
|
4
4
|
"exports": {
|
|
5
5
|
"ModelByInputTokens": {
|
|
6
6
|
"types": "dist/processors/index.d.ts",
|
|
7
|
-
"implementation": "dist/chunk-
|
|
8
|
-
"line":
|
|
7
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
8
|
+
"line": 745
|
|
9
9
|
},
|
|
10
10
|
"OBSERVER_SYSTEM_PROMPT": {
|
|
11
11
|
"types": "dist/processors/index.d.ts",
|
|
12
|
-
"implementation": "dist/chunk-
|
|
12
|
+
"implementation": "dist/chunk-Z5GWA7LB.js"
|
|
13
13
|
},
|
|
14
14
|
"ObservationalMemory": {
|
|
15
15
|
"types": "dist/processors/index.d.ts",
|
|
16
|
-
"implementation": "dist/chunk-
|
|
17
|
-
"line":
|
|
16
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
17
|
+
"line": 6580
|
|
18
18
|
},
|
|
19
19
|
"ObservationalMemoryProcessor": {
|
|
20
20
|
"types": "dist/processors/index.d.ts",
|
|
21
|
-
"implementation": "dist/chunk-
|
|
22
|
-
"line":
|
|
21
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
22
|
+
"line": 9124
|
|
23
23
|
},
|
|
24
24
|
"TokenCounter": {
|
|
25
25
|
"types": "dist/processors/index.d.ts",
|
|
26
|
-
"implementation": "dist/chunk-
|
|
27
|
-
"line":
|
|
26
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
27
|
+
"line": 6050
|
|
28
28
|
},
|
|
29
29
|
"buildObserverPrompt": {
|
|
30
30
|
"types": "dist/processors/index.d.ts",
|
|
31
|
-
"implementation": "dist/chunk-
|
|
32
|
-
"line":
|
|
31
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
32
|
+
"line": 3567
|
|
33
33
|
},
|
|
34
34
|
"buildObserverSystemPrompt": {
|
|
35
35
|
"types": "dist/processors/index.d.ts",
|
|
36
|
-
"implementation": "dist/chunk-
|
|
37
|
-
"line":
|
|
36
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
37
|
+
"line": 2950
|
|
38
38
|
},
|
|
39
39
|
"combineObservationGroupRanges": {
|
|
40
40
|
"types": "dist/processors/index.d.ts",
|
|
41
|
-
"implementation": "dist/chunk-
|
|
42
|
-
"line":
|
|
41
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
42
|
+
"line": 837
|
|
43
43
|
},
|
|
44
44
|
"deriveObservationGroupProvenance": {
|
|
45
45
|
"types": "dist/processors/index.d.ts",
|
|
46
|
-
"implementation": "dist/chunk-
|
|
47
|
-
"line":
|
|
46
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
47
|
+
"line": 871
|
|
48
48
|
},
|
|
49
49
|
"extractCurrentTask": {
|
|
50
50
|
"types": "dist/processors/index.d.ts",
|
|
51
|
-
"implementation": "dist/chunk-
|
|
52
|
-
"line":
|
|
51
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
52
|
+
"line": 3681
|
|
53
53
|
},
|
|
54
54
|
"formatMessagesForObserver": {
|
|
55
55
|
"types": "dist/processors/index.d.ts",
|
|
56
|
-
"implementation": "dist/chunk-
|
|
57
|
-
"line":
|
|
56
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
57
|
+
"line": 3293
|
|
58
58
|
},
|
|
59
59
|
"getObservationsAsOf": {
|
|
60
60
|
"types": "dist/processors/index.d.ts",
|
|
61
|
-
"implementation": "dist/chunk-
|
|
62
|
-
"line":
|
|
61
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
62
|
+
"line": 9330
|
|
63
63
|
},
|
|
64
64
|
"hasCurrentTaskSection": {
|
|
65
65
|
"types": "dist/processors/index.d.ts",
|
|
66
|
-
"implementation": "dist/chunk-
|
|
67
|
-
"line":
|
|
66
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
67
|
+
"line": 3669
|
|
68
68
|
},
|
|
69
69
|
"injectAnchorIds": {
|
|
70
70
|
"types": "dist/processors/index.d.ts",
|
|
71
|
-
"implementation": "dist/chunk-
|
|
72
|
-
"line":
|
|
71
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
72
|
+
"line": 2498
|
|
73
73
|
},
|
|
74
74
|
"optimizeObservationsForContext": {
|
|
75
75
|
"types": "dist/processors/index.d.ts",
|
|
76
|
-
"implementation": "dist/chunk-
|
|
77
|
-
"line":
|
|
76
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
77
|
+
"line": 3692
|
|
78
78
|
},
|
|
79
79
|
"parseAnchorId": {
|
|
80
80
|
"types": "dist/processors/index.d.ts",
|
|
81
|
-
"implementation": "dist/chunk-
|
|
82
|
-
"line":
|
|
81
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
82
|
+
"line": 2471
|
|
83
83
|
},
|
|
84
84
|
"parseObservationGroups": {
|
|
85
85
|
"types": "dist/processors/index.d.ts",
|
|
86
|
-
"implementation": "dist/chunk-
|
|
87
|
-
"line":
|
|
86
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
87
|
+
"line": 806
|
|
88
88
|
},
|
|
89
89
|
"parseObserverOutput": {
|
|
90
90
|
"types": "dist/processors/index.d.ts",
|
|
91
|
-
"implementation": "dist/chunk-
|
|
92
|
-
"line":
|
|
91
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
92
|
+
"line": 3577
|
|
93
93
|
},
|
|
94
94
|
"reconcileObservationGroupsFromReflection": {
|
|
95
95
|
"types": "dist/processors/index.d.ts",
|
|
96
|
-
"implementation": "dist/chunk-
|
|
97
|
-
"line":
|
|
96
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
97
|
+
"line": 895
|
|
98
98
|
},
|
|
99
99
|
"renderObservationGroupsForReflection": {
|
|
100
100
|
"types": "dist/processors/index.d.ts",
|
|
101
|
-
"implementation": "dist/chunk-
|
|
102
|
-
"line":
|
|
101
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
102
|
+
"line": 851
|
|
103
103
|
},
|
|
104
104
|
"stripEphemeralAnchorIds": {
|
|
105
105
|
"types": "dist/processors/index.d.ts",
|
|
106
|
-
"implementation": "dist/chunk-
|
|
107
|
-
"line":
|
|
106
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
107
|
+
"line": 2528
|
|
108
108
|
},
|
|
109
109
|
"stripObservationGroups": {
|
|
110
110
|
"types": "dist/processors/index.d.ts",
|
|
111
|
-
"implementation": "dist/chunk-
|
|
112
|
-
"line":
|
|
111
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
112
|
+
"line": 828
|
|
113
113
|
},
|
|
114
114
|
"wrapInObservationGroup": {
|
|
115
115
|
"types": "dist/processors/index.d.ts",
|
|
116
|
-
"implementation": "dist/chunk-
|
|
117
|
-
"line":
|
|
116
|
+
"implementation": "dist/chunk-Z5GWA7LB.js",
|
|
117
|
+
"line": 799
|
|
118
118
|
},
|
|
119
119
|
"OBSERVATIONAL_MEMORY_DEFAULTS": {
|
|
120
120
|
"types": "dist/processors/index.d.ts",
|
|
@@ -132,18 +132,6 @@
|
|
|
132
132
|
"types": "dist/processors/index.d.ts",
|
|
133
133
|
"implementation": "dist/chunk-LSJJAJAF.js"
|
|
134
134
|
},
|
|
135
|
-
"extractWorkingMemoryContent": {
|
|
136
|
-
"types": "dist/index.d.ts",
|
|
137
|
-
"implementation": "dist/memory"
|
|
138
|
-
},
|
|
139
|
-
"extractWorkingMemoryTags": {
|
|
140
|
-
"types": "dist/index.d.ts",
|
|
141
|
-
"implementation": "dist/memory"
|
|
142
|
-
},
|
|
143
|
-
"removeWorkingMemoryTags": {
|
|
144
|
-
"types": "dist/index.d.ts",
|
|
145
|
-
"implementation": "dist/memory"
|
|
146
|
-
},
|
|
147
135
|
"MessageHistory": {
|
|
148
136
|
"types": "dist/index.d.ts",
|
|
149
137
|
"implementation": "dist/processors"
|
|
@@ -161,7 +149,7 @@
|
|
|
161
149
|
"processors": {
|
|
162
150
|
"index": "dist/processors/index.js",
|
|
163
151
|
"chunks": [
|
|
164
|
-
"chunk-
|
|
152
|
+
"chunk-Z5GWA7LB.js",
|
|
165
153
|
"chunk-LSJJAJAF.js"
|
|
166
154
|
]
|
|
167
155
|
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# Background tasks
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.29.0`
|
|
4
|
+
|
|
5
|
+
Background tasks let an agent dispatch a long-running tool call without blocking the agentic loop. The tool returns an immediate acknowledgement, the LLM continues responding, and the task runs to completion in the background. When it finishes, its result is written to memory and if you use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) the agent is re-invoked automatically so the result is processed in the same call.
|
|
6
|
+
|
|
7
|
+
## When to use background tasks
|
|
8
|
+
|
|
9
|
+
Use background tasks when a tool call may take long enough that the user shouldn't wait for it before seeing a response. Common cases:
|
|
10
|
+
|
|
11
|
+
- Subagent delegations that themselves run multi-step research or writing.
|
|
12
|
+
- Tool calls that hit slow external services, queues, or large data jobs.
|
|
13
|
+
- Workflows triggered from a tool call that may take minutes to complete.
|
|
14
|
+
|
|
15
|
+
For tool calls that return quickly, foreground execution using `agent.stream()` and `agent.generate()` is simpler.
|
|
16
|
+
|
|
17
|
+
> **Note:** Background tasks require a configured [storage](https://mastra.ai/docs/memory/storage) backend on the Mastra instance. Tasks are persisted so they survive process restarts.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
Background tasks are off by default. Enable them by setting `backgroundTasks.enabled` on the Mastra instance:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Mastra } from '@mastra/core'
|
|
25
|
+
import { LibSQLStore } from '@mastra/libsql'
|
|
26
|
+
|
|
27
|
+
export const mastra = new Mastra({
|
|
28
|
+
storage: new LibSQLStore({ id: 'storage', url: 'file:mastra.db' }),
|
|
29
|
+
backgroundTasks: {
|
|
30
|
+
enabled: true,
|
|
31
|
+
globalConcurrency: 10,
|
|
32
|
+
perAgentConcurrency: 5,
|
|
33
|
+
backpressure: 'queue',
|
|
34
|
+
defaultTimeoutMs: 300_000,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The full set of options is listed in the [backgroundTasks configuration reference](https://mastra.ai/reference/configuration).
|
|
40
|
+
|
|
41
|
+
## Run a tool in the background
|
|
42
|
+
|
|
43
|
+
Enabling the manager doesn't run anything in the background by itself as every tool defaults to foreground execution. You can run a tool in the background at one of three layers, in priority order:
|
|
44
|
+
|
|
45
|
+
1. **LLM per-call override**: the model decides it should run in the background and includes a `_background` field in the tool arguments.
|
|
46
|
+
2. **Agent-level config**: the agent declares which of its tools are background-eligible.
|
|
47
|
+
3. **Tool-level config**: the tool itself declares it as background-eligible.
|
|
48
|
+
|
|
49
|
+
### Tool-level
|
|
50
|
+
|
|
51
|
+
Set `backgroundTasks.enabled: true` on the tool definition. Tools opted in at this layer run in the background whenever called by an agent that has the manager enabled.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { createTool } from '@mastra/core/tools'
|
|
55
|
+
import { z } from 'zod'
|
|
56
|
+
|
|
57
|
+
export const researchTool = createTool({
|
|
58
|
+
id: 'research',
|
|
59
|
+
description: 'Run a long research job',
|
|
60
|
+
inputSchema: z.object({ topic: z.string() }),
|
|
61
|
+
backgroundTasks: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
timeoutMs: 600_000,
|
|
64
|
+
maxRetries: 1,
|
|
65
|
+
},
|
|
66
|
+
execute: async ({ context }) => {
|
|
67
|
+
// ...
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Agent-level
|
|
73
|
+
|
|
74
|
+
Use `backgroundTasks.tools` on the agent to opt in specific tools, override timeouts for individual tools, or run all background-eligible tools in the background. Use `disabled: true` to short-circuit background dispatch for the agent entirely.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { Agent } from '@mastra/core/agent'
|
|
78
|
+
|
|
79
|
+
export const researcher = new Agent({
|
|
80
|
+
id: 'researcher',
|
|
81
|
+
instructions: 'You research topics and answer questions.',
|
|
82
|
+
model: 'openai/gpt-5.4',
|
|
83
|
+
tools: { researchTool, summarizeTool },
|
|
84
|
+
backgroundTasks: {
|
|
85
|
+
tools: {
|
|
86
|
+
researchTool: { enabled: true, timeoutMs: 600_000 },
|
|
87
|
+
summarizeTool: false,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Set `tools: 'all'` to opt in every tool the agent has.
|
|
94
|
+
|
|
95
|
+
### LLM per-call override
|
|
96
|
+
|
|
97
|
+
When a tool is registered on an agent that has background tasks enabled, the model can include a `_background` field in the tool arguments to override the resolved configuration for that specific call. The model only includes what it wants to override, all fields in `_background` are optional. The override is stripped from the arguments before the tool runs.
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"topic": "solana",
|
|
102
|
+
"_background": { "enabled": true, "timeoutMs": 900_000 }
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Resolution order
|
|
107
|
+
|
|
108
|
+
When a tool call is dispatched, the resolved background config is computed in this priority order:
|
|
109
|
+
|
|
110
|
+
1. LLM `_background` override (if present in the call's arguments).
|
|
111
|
+
2. Agent-level `backgroundTasks.tools` entry for the tool.
|
|
112
|
+
3. Tool-level `backgroundTasks` config.
|
|
113
|
+
4. Manager defaults (`defaultTimeoutMs`, `defaultRetries`).
|
|
114
|
+
|
|
115
|
+
If the agent has `backgroundTasks.disabled: true`, every tool call runs synchronously regardless of the layers above.
|
|
116
|
+
|
|
117
|
+
## Background tasks related stream chunks
|
|
118
|
+
|
|
119
|
+
When a tool call dispatches as a background task, two streams may surface lifecycle events for it: the agent's own stream and the [`backgroundTaskManager.stream()`](https://mastra.ai/docs/streaming/background-task-streaming) SSE stream. Each stream covers a different set of chunk types:
|
|
120
|
+
|
|
121
|
+
| Chunk type | When it fires | Emitted by |
|
|
122
|
+
| --------------------------- | -------------------------------------------------------------------------------------- | -------------- |
|
|
123
|
+
| `background-task-started` | The task has been enqueued and assigned a `taskId`. | Agent stream |
|
|
124
|
+
| `background-task-running` | The task picked up a worker and started executing. | Manager stream |
|
|
125
|
+
| `background-task-progress` | Shows number of running background tasks. | Agent stream |
|
|
126
|
+
| `background-task-output` | A streamed output chunk from the task's `execute`. | Manager stream |
|
|
127
|
+
| `background-task-completed` | The task finished successfully. The `payload.result` matches the eventual tool result. | Manager stream |
|
|
128
|
+
| `background-task-failed` | The task threw or timed out. | Manager stream |
|
|
129
|
+
| `background-task-cancelled` | The task was cancelled before completing. | Manager stream |
|
|
130
|
+
|
|
131
|
+
`agent.stream().fullStream` only emits the agent-loop chunks (`background-task-started`, `background-task-progress`) on its own. `agent.streamUntilIdle()` emits the same two chunks and additionally subscribes to the manager pubsub for the run's memory scope and pipes the five manager chunks (`background-task-running`, `background-task-output`, `background-task-completed`, `background-task-failed`, `background-task-cancelled`) into the same `fullStream`, so consumers of `streamUntilIdle().fullStream` see all seven types.
|
|
132
|
+
|
|
133
|
+
`backgroundTaskManager.stream()` only emits the five manager chunks.
|
|
134
|
+
|
|
135
|
+
The full payload shapes are documented in the [background task chunks reference](https://mastra.ai/reference/streaming/ChunkType).
|
|
136
|
+
|
|
137
|
+
## Keep the agent stream open with `streamUntilIdle()`
|
|
138
|
+
|
|
139
|
+
`agent.stream()` returns once the LLM emits a final response even if a background task is still running. Use `agent.streamUntilIdle()` when you want the stream to stay open until every dispatched background task has completed and the LLM has had a chance to respond to the result:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const stream = await agent.streamUntilIdle('Research solana for me', {
|
|
143
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
144
|
+
maxIdleMs: 5 * 60_000,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
for await (const chunk of stream.fullStream) {
|
|
148
|
+
// chunks from the initial turn AND any continuation turns triggered by
|
|
149
|
+
// background task completions flow through here
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
When a background task completes, the result is injected into the agent memory, `streamUntilIdle()` re-enters the agentic loop so the LLM can react to it. The stream closes when no tasks are running and no completions are queued.
|
|
154
|
+
|
|
155
|
+
`maxIdleMs` caps how long the stream waits between turns. The timer only runs while the wrapper is between turns, so a slow first token won't close the stream. The default is 5 minutes.
|
|
156
|
+
|
|
157
|
+
> **Note:** Visit [`Agent.streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) for the full API.
|
|
158
|
+
|
|
159
|
+
### Aggregate properties
|
|
160
|
+
|
|
161
|
+
`streamUntilIdle()` returns a `MastraModelOutput` that looks like the one from `stream()`, but only `fullStream` spans the initial turn **and** any auto-continuations. Aggregate properties (`text`, `toolCalls`, `toolResults`, `finishReason`, `messageList`, `getFullOutput()`) still resolve against the **first turn's** internal buffer. If you need an aggregate view across continuations, consume `fullStream` yourself and accumulate.
|
|
162
|
+
|
|
163
|
+
## Subagents in the background
|
|
164
|
+
|
|
165
|
+
Subagent invocations are dispatched as tool calls under the hood, so the same background configuration applies. The recommended pattern is to opt each subagent in on the supervisor, it's clearer and lets you tune `timeoutMs` per subagent in one place:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { Agent } from '@mastra/core/agent'
|
|
169
|
+
|
|
170
|
+
const supervisor = new Agent({
|
|
171
|
+
id: 'supervisor',
|
|
172
|
+
instructions: 'Coordinate research and writing using the available agents.',
|
|
173
|
+
model: 'openai/gpt-5.4',
|
|
174
|
+
agents: { researchAgent, writingAgent },
|
|
175
|
+
backgroundTasks: {
|
|
176
|
+
tools: {
|
|
177
|
+
researchAgent: { enabled: true, timeoutMs: 900_000 },
|
|
178
|
+
writingAgent: { enabled: true, timeoutMs: 900_000 },
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
|
|
184
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
185
|
+
})
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Inheriting from the subagent
|
|
189
|
+
|
|
190
|
+
If a subagent isn't listed under the supervisor's `backgroundTasks.tools` but has background-eligible tools of its own (either via tool-level `backgroundTasks.enabled: true` or its own `backgroundTasks.tools` entry) the framework still dispatches the entire subagent invocation as a background task. The supervisor inherits the subagent's intent: the subagent itself becomes the background task, and its inner tools run in the foreground inside the subagent's loop.
|
|
191
|
+
|
|
192
|
+
The background config used for the inherited dispatch (for example `waitTimeoutMs`) is derived from the subagent's own `backgroundTasks` config.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
const researchAgent = new Agent({
|
|
196
|
+
id: 'research-agent',
|
|
197
|
+
description: 'Gathers factual information.',
|
|
198
|
+
model: 'openai/gpt-5-mini',
|
|
199
|
+
tools: { deepResearchTool },
|
|
200
|
+
backgroundTasks: {
|
|
201
|
+
tools: {
|
|
202
|
+
deepResearchTool: { enabled: true, timeoutMs: 600_000 },
|
|
203
|
+
},
|
|
204
|
+
waitTimeoutMs: 900_000,
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
When this `researchAgent` is delegated to from a supervisor that has no backgroundTask configuration for the `researchAgent`, the supervisor still dispatches the whole `researchAgent` invocation as a background task, and `deepResearchTool` runs in the foreground inside that invocation, instead of dispatching its own nested background task.
|
|
210
|
+
|
|
211
|
+
Use this pattern when you want a subagent to behave consistently in the background regardless of which supervisor invokes it. Use the supervisor-side opt-in (above) when you want to tune background behavior centrally per supervisor.
|
|
212
|
+
|
|
213
|
+
## Lifecycle callbacks
|
|
214
|
+
|
|
215
|
+
Each layer can register terminal-state callbacks. They don't replace one another, and success/failure hooks fire for their respective outcomes:
|
|
216
|
+
|
|
217
|
+
- Tool-level `backgroundTasks.onComplete` / `onFailed`: scoped to one tool.
|
|
218
|
+
- Agent-level `backgroundTasks.onTaskComplete` / `onTaskFailed`: scoped to all tasks dispatched by this agent.
|
|
219
|
+
- Manager-level `onTaskComplete` / `onTaskFailed`: scoped globally.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
export const mastra = new Mastra({
|
|
223
|
+
storage,
|
|
224
|
+
backgroundTasks: {
|
|
225
|
+
enabled: true,
|
|
226
|
+
onTaskComplete: task => {
|
|
227
|
+
logger.info('Background task complete', { taskId: task.id, toolName: task.toolName })
|
|
228
|
+
},
|
|
229
|
+
onTaskFailed: task => {
|
|
230
|
+
logger.error('Background task failed', { taskId: task.id, error: task.error })
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Related
|
|
237
|
+
|
|
238
|
+
- [`Agent.streamUntilIdle()` reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
239
|
+
- [backgroundTasks configuration reference](https://mastra.ai/reference/configuration)
|
|
240
|
+
- [Supervisor agents](https://mastra.ai/docs/agents/supervisor-agents)
|
|
241
|
+
- [Stream chunk types](https://mastra.ai/reference/streaming/ChunkType)
|
|
242
|
+
- [Storage](https://mastra.ai/docs/memory/storage)
|
|
@@ -167,6 +167,22 @@ const stream = await supervisor.stream('Research AI trends', {
|
|
|
167
167
|
|
|
168
168
|
The callback receives `messages` (the full conversation history), `primitiveId` (the subagent ID), and `prompt` (the delegation prompt). Return the filtered array of messages.
|
|
169
169
|
|
|
170
|
+
## Subagent result context
|
|
171
|
+
|
|
172
|
+
When a subagent completes, the supervisor model receives the subagent's text response in later iterations. Nested tool calls and subagent metadata, such as thread and resource IDs, are not added to the supervisor model context.
|
|
173
|
+
|
|
174
|
+
Application code and UI integrations can still inspect the raw delegation result, including `subAgentToolResults`, from the tool result payload. This keeps debugging and display data available without sending nested tool arguments or outputs back into the supervisor's next model call.
|
|
175
|
+
|
|
176
|
+
Set `includeSubAgentToolResultsInModelContext` to include the full subagent result, including nested tool results and subagent metadata, in the supervisor model context.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
await supervisor.generate('Research AI trends', {
|
|
180
|
+
delegation: {
|
|
181
|
+
includeSubAgentToolResultsInModelContext: true,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
170
186
|
## Iteration monitoring
|
|
171
187
|
|
|
172
188
|
`onIterationComplete` is called after each iteration of the supervisor loop. Use it to log progress, inject feedback, or stop execution early.
|
|
@@ -300,10 +316,59 @@ Success criteria:
|
|
|
300
316
|
})
|
|
301
317
|
```
|
|
302
318
|
|
|
319
|
+
## Running subagents in the background
|
|
320
|
+
|
|
321
|
+
Subagent invocations are dispatched as tool calls, so they can run as [background tasks](https://mastra.ai/docs/agents/background-tasks). This is useful when one or more delegations are long-running and you don't want them to block the supervisor's response.
|
|
322
|
+
|
|
323
|
+
Enable the [backgroundTasks manager](https://mastra.ai/reference/configuration) on the Mastra instance, then opt subagents in on the supervisor:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
const supervisor = new Agent({
|
|
327
|
+
id: 'supervisor',
|
|
328
|
+
instructions: 'Coordinate research and writing using the available agents.',
|
|
329
|
+
model: 'openai/gpt-5.4',
|
|
330
|
+
agents: { researchAgent, writingAgent },
|
|
331
|
+
backgroundTasks: {
|
|
332
|
+
tools: {
|
|
333
|
+
researchAgent: { enabled: true, timeoutMs: 900_000 },
|
|
334
|
+
writingAgent: { enabled: true, timeoutMs: 900_000 },
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
const stream = await supervisor.streamUntilIdle('Research AI in education and write an article', {
|
|
340
|
+
memory: { thread: 't1', resource: 'u1' },
|
|
341
|
+
})
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Use [`streamUntilIdle()`](https://mastra.ai/reference/streaming/agents/streamUntilIdle) instead of `stream()` so the stream stays open until the subagents complete and the supervisor has had a chance to respond to their results.
|
|
345
|
+
|
|
346
|
+
If a subagent isn't listed on the supervisor but has its own background-eligible tools, the supervisor still dispatches the subagent as a background task and inherits its config. See [Inheriting from the subagent](https://mastra.ai/docs/agents/background-tasks) for details.
|
|
347
|
+
|
|
348
|
+
## Subagent versioning
|
|
349
|
+
|
|
350
|
+
When using the [editor](https://mastra.ai/docs/editor/overview), you can control which stored version of each subagent the supervisor uses at runtime. Set version overrides on the Mastra instance or per invocation:
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
const result = await supervisor.generate('Research and write about AI safety', {
|
|
354
|
+
versions: {
|
|
355
|
+
agents: {
|
|
356
|
+
'research-agent': { status: 'published' },
|
|
357
|
+
'writing-agent': { versionId: 'draft-456' },
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
})
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Version overrides propagate automatically through delegation. See [Subagent versioning](https://mastra.ai/docs/editor/overview) for details on resolution order and server API usage.
|
|
364
|
+
|
|
303
365
|
## Related
|
|
304
366
|
|
|
367
|
+
- [Background tasks](https://mastra.ai/docs/agents/background-tasks)
|
|
368
|
+
- [Subagent versioning](https://mastra.ai/docs/editor/overview)
|
|
305
369
|
- [Guide: Research coordinator](https://mastra.ai/guides/guide/research-coordinator)
|
|
306
370
|
- [Agent.stream() reference](https://mastra.ai/reference/streaming/agents/stream)
|
|
371
|
+
- [Agent.streamUntilIdle() reference](https://mastra.ai/reference/streaming/agents/streamUntilIdle)
|
|
307
372
|
- [Agent.generate() reference](https://mastra.ai/reference/agents/generate)
|
|
308
373
|
- [Agent approval](https://mastra.ai/docs/agents/agent-approval)
|
|
309
374
|
- [Memory in multi-agent systems](https://mastra.ai/docs/memory/overview)
|
|
@@ -307,8 +307,8 @@ Both scenarios are safe - guardrails prevent inappropriate content from being pe
|
|
|
307
307
|
|
|
308
308
|
## Related documentation
|
|
309
309
|
|
|
310
|
-
- [Processors](https://mastra.ai/docs/agents/processors)
|
|
311
|
-
- [Guardrails](https://mastra.ai/docs/agents/guardrails)
|
|
312
|
-
- [Memory Overview](https://mastra.ai/docs/memory/overview)
|
|
310
|
+
- [Processors](https://mastra.ai/docs/agents/processors): General processor concepts and custom processor creation
|
|
311
|
+
- [Guardrails](https://mastra.ai/docs/agents/guardrails): Security and validation processors
|
|
312
|
+
- [Memory Overview](https://mastra.ai/docs/memory/overview): Memory types and configuration
|
|
313
313
|
|
|
314
314
|
When creating custom processors avoid mutating the input `messages` array or its objects directly.
|
|
@@ -6,6 +6,12 @@ You can also retrieve message history to display past conversations in your UI.
|
|
|
6
6
|
|
|
7
7
|
> **Info:** Each message belongs to a thread (the conversation) and a resource (the user or entity it's associated with). See [Threads and resources](https://mastra.ai/docs/memory/storage) for more detail.
|
|
8
8
|
|
|
9
|
+
> **Warning:** When you use memory with a client application, send **only the new message** from the client instead of the full conversation history.
|
|
10
|
+
>
|
|
11
|
+
> Sending the full history is redundant because Mastra loads messages from storage, and it can cause message ordering bugs when client-side timestamps conflict with stored timestamps.
|
|
12
|
+
>
|
|
13
|
+
> For an AI SDK example, see [Using Mastra Memory](https://mastra.ai/guides/build-your-ui/ai-sdk-ui).
|
|
14
|
+
|
|
9
15
|
## Getting started
|
|
10
16
|
|
|
11
17
|
Install the Mastra memory module along with a [storage adapter](https://mastra.ai/docs/memory/storage) for your database. The examples below use `@mastra/libsql`, which stores data locally in a `mastra.db` file.
|
|
@@ -100,8 +106,8 @@ await agent.stream('Hello', {
|
|
|
100
106
|
|
|
101
107
|
You can use this history in two ways:
|
|
102
108
|
|
|
103
|
-
- **Automatic inclusion
|
|
104
|
-
- [**Manual querying**](#querying)
|
|
109
|
+
- **Automatic inclusion**: Mastra automatically fetches and includes recent messages in the context window. By default, it includes the last 10 messages, keeping agents grounded in the conversation. You can adjust this number with `lastMessages`, but in most cases you don't need to think about it.
|
|
110
|
+
- [**Manual querying**](#querying): For more control, use the `recall()` function to query threads and messages directly. This lets you choose exactly which memories are included in the context window, or fetch messages to render conversation history in your UI.
|
|
105
111
|
|
|
106
112
|
> **Tip:** When memory is enabled, [Studio](https://mastra.ai/docs/studio/overview) uses message history to display past conversations in the chat sidebar.
|
|
107
113
|
|