@mastra/memory 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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.
Files changed (169) hide show
  1. package/CHANGELOG.md +4656 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +26 -1
  4. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7450 -0
  5. package/dist/docs/SKILL.md +62 -0
  6. package/dist/docs/assets/SOURCE_MAP.json +11 -0
  7. package/dist/docs/references/docs-agents-agent-approval.md +664 -0
  8. package/dist/docs/references/docs-agents-networks.md +184 -0
  9. package/dist/docs/references/docs-capabilities-subagents.md +454 -0
  10. package/dist/docs/references/docs-evals-evals-with-memory.md +146 -0
  11. package/dist/docs/references/docs-long-running-agents-background-tasks.md +382 -0
  12. package/dist/docs/references/docs-long-running-agents-goals.md +118 -0
  13. package/dist/docs/references/docs-memory-memory-processors.md +385 -0
  14. package/dist/docs/references/docs-memory-message-history.md +348 -0
  15. package/dist/docs/references/docs-memory-multi-user-threads.md +208 -0
  16. package/dist/docs/references/docs-memory-observational-memory.md +835 -0
  17. package/dist/docs/references/docs-memory-overview.md +266 -0
  18. package/dist/docs/references/docs-memory-semantic-recall.md +401 -0
  19. package/dist/docs/references/docs-memory-working-memory.md +431 -0
  20. package/dist/docs/references/docs-storage-overview.md +214 -0
  21. package/dist/docs/references/reference-core-getMemory.md +51 -0
  22. package/dist/docs/references/reference-core-listMemory.md +57 -0
  23. package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
  24. package/dist/docs/references/reference-memory-clone-utilities.md +203 -0
  25. package/dist/docs/references/reference-memory-cloneThread.md +173 -0
  26. package/dist/docs/references/reference-memory-createThread.md +70 -0
  27. package/dist/docs/references/reference-memory-getThreadById.md +26 -0
  28. package/dist/docs/references/reference-memory-listThreads.md +147 -0
  29. package/dist/docs/references/reference-memory-memory-class.md +148 -0
  30. package/dist/docs/references/reference-memory-observational-memory.md +877 -0
  31. package/dist/docs/references/reference-memory-summarizeConversation.md +99 -0
  32. package/dist/docs/references/reference-memory-summarizeThread.md +93 -0
  33. package/dist/docs/references/reference-processors-token-limiter-processor.md +158 -0
  34. package/dist/docs/references/reference-storage-dsql.md +430 -0
  35. package/dist/docs/references/reference-storage-dynamodb.md +284 -0
  36. package/dist/docs/references/reference-storage-libsql.md +143 -0
  37. package/dist/docs/references/reference-storage-mongodb.md +267 -0
  38. package/dist/docs/references/reference-storage-postgresql.md +531 -0
  39. package/dist/docs/references/reference-storage-redis.md +268 -0
  40. package/dist/docs/references/reference-storage-upstash.md +162 -0
  41. package/dist/docs/references/reference-vectors-libsql.md +307 -0
  42. package/dist/docs/references/reference-vectors-mongodb.md +567 -0
  43. package/dist/docs/references/reference-vectors-pg.md +430 -0
  44. package/dist/docs/references/reference-vectors-upstash.md +296 -0
  45. package/dist/index.cjs +35 -893
  46. package/dist/index.d.ts +465 -62
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +2 -887
  49. package/dist/processors/index.cjs +32 -165
  50. package/dist/processors/index.d.ts +1 -2
  51. package/dist/processors/index.d.ts.map +1 -1
  52. package/dist/processors/index.js +2 -158
  53. package/dist/processors/observational-memory/activation-ttl.d.ts +4 -0
  54. package/dist/processors/observational-memory/activation-ttl.d.ts.map +1 -0
  55. package/dist/processors/observational-memory/anchor-ids.d.ts +4 -0
  56. package/dist/processors/observational-memory/anchor-ids.d.ts.map +1 -0
  57. package/dist/processors/observational-memory/buffering-coordinator.d.ts +61 -0
  58. package/dist/processors/observational-memory/buffering-coordinator.d.ts.map +1 -0
  59. package/dist/processors/observational-memory/built-in-extractors.d.ts +15 -0
  60. package/dist/processors/observational-memory/built-in-extractors.d.ts.map +1 -0
  61. package/dist/processors/observational-memory/constants.d.ts +74 -0
  62. package/dist/processors/observational-memory/constants.d.ts.map +1 -0
  63. package/dist/processors/observational-memory/date-utils.d.ts +41 -0
  64. package/dist/processors/observational-memory/date-utils.d.ts.map +1 -0
  65. package/dist/processors/observational-memory/debug.d.ts +3 -0
  66. package/dist/processors/observational-memory/debug.d.ts.map +1 -0
  67. package/dist/processors/observational-memory/extracted-values.d.ts +44 -0
  68. package/dist/processors/observational-memory/extracted-values.d.ts.map +1 -0
  69. package/dist/processors/observational-memory/extraction-runner.d.ts +22 -0
  70. package/dist/processors/observational-memory/extraction-runner.d.ts.map +1 -0
  71. package/dist/processors/observational-memory/extractor.d.ts +76 -0
  72. package/dist/processors/observational-memory/extractor.d.ts.map +1 -0
  73. package/dist/processors/observational-memory/index.d.ts +30 -0
  74. package/dist/processors/observational-memory/index.d.ts.map +1 -0
  75. package/dist/processors/observational-memory/internal-request-context.d.ts +17 -0
  76. package/dist/processors/observational-memory/internal-request-context.d.ts.map +1 -0
  77. package/dist/processors/observational-memory/markers.d.ts +118 -0
  78. package/dist/processors/observational-memory/markers.d.ts.map +1 -0
  79. package/dist/processors/observational-memory/message-utils.d.ts +83 -0
  80. package/dist/processors/observational-memory/message-utils.d.ts.map +1 -0
  81. package/dist/processors/observational-memory/model-by-input-tokens.d.ts +14 -0
  82. package/dist/processors/observational-memory/model-by-input-tokens.d.ts.map +1 -0
  83. package/dist/processors/observational-memory/model-context.d.ts +2 -0
  84. package/dist/processors/observational-memory/model-context.d.ts.map +1 -0
  85. package/dist/processors/observational-memory/observation-groups.d.ts +15 -0
  86. package/dist/processors/observational-memory/observation-groups.d.ts.map +1 -0
  87. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +39 -0
  88. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -0
  89. package/dist/processors/observational-memory/observation-strategies/base.d.ts +122 -0
  90. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -0
  91. package/dist/processors/observational-memory/observation-strategies/index.d.ts +7 -0
  92. package/dist/processors/observational-memory/observation-strategies/index.d.ts.map +1 -0
  93. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts +43 -0
  94. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -0
  95. package/dist/processors/observational-memory/observation-strategies/sync.d.ts +41 -0
  96. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -0
  97. package/dist/processors/observational-memory/observation-strategies/types.d.ts +103 -0
  98. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -0
  99. package/dist/processors/observational-memory/observation-turn/index.d.ts +4 -0
  100. package/dist/processors/observational-memory/observation-turn/index.d.ts.map +1 -0
  101. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
  102. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
  103. package/dist/processors/observational-memory/observation-turn/step.d.ts +53 -0
  104. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -0
  105. package/dist/processors/observational-memory/observation-turn/turn.d.ts +139 -0
  106. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -0
  107. package/dist/processors/observational-memory/observation-turn/types.d.ts +46 -0
  108. package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -0
  109. package/dist/processors/observational-memory/observation-utils.d.ts +16 -0
  110. package/dist/processors/observational-memory/observation-utils.d.ts.map +1 -0
  111. package/dist/processors/observational-memory/observational-memory.d.ts +930 -0
  112. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -0
  113. package/dist/processors/observational-memory/observer-agent.d.ts +190 -0
  114. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -0
  115. package/dist/processors/observational-memory/observer-runner.d.ts +141 -0
  116. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -0
  117. package/dist/processors/observational-memory/operation-registry.d.ts +14 -0
  118. package/dist/processors/observational-memory/operation-registry.d.ts.map +1 -0
  119. package/dist/processors/observational-memory/processor.d.ts +70 -0
  120. package/dist/processors/observational-memory/processor.d.ts.map +1 -0
  121. package/dist/processors/observational-memory/reflector-agent.d.ts +62 -0
  122. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -0
  123. package/dist/processors/observational-memory/reflector-runner.d.ts +133 -0
  124. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -0
  125. package/dist/processors/observational-memory/repro-capture.d.ts +33 -0
  126. package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -0
  127. package/dist/processors/observational-memory/retry.d.ts +63 -0
  128. package/dist/processors/observational-memory/retry.d.ts.map +1 -0
  129. package/dist/processors/observational-memory/string-utils.d.ts +13 -0
  130. package/dist/processors/observational-memory/string-utils.d.ts.map +1 -0
  131. package/dist/processors/observational-memory/summarize.d.ts +92 -0
  132. package/dist/processors/observational-memory/summarize.d.ts.map +1 -0
  133. package/dist/processors/observational-memory/temporal-markers.d.ts +4 -0
  134. package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -0
  135. package/dist/processors/observational-memory/temporary-memory.d.ts +8 -0
  136. package/dist/processors/observational-memory/temporary-memory.d.ts.map +1 -0
  137. package/dist/processors/observational-memory/thresholds.d.ts +52 -0
  138. package/dist/processors/observational-memory/thresholds.d.ts.map +1 -0
  139. package/dist/processors/observational-memory/token-counter.d.ts +57 -0
  140. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -0
  141. package/dist/processors/observational-memory/tool-result-helpers.d.ts +12 -0
  142. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -0
  143. package/dist/processors/observational-memory/tracing.d.ts +17 -0
  144. package/dist/processors/observational-memory/tracing.d.ts.map +1 -0
  145. package/dist/processors/observational-memory/types.d.ts +997 -0
  146. package/dist/processors/observational-memory/types.d.ts.map +1 -0
  147. package/dist/processors/observational-memory/working-memory-extractor.d.ts +5 -0
  148. package/dist/processors/observational-memory/working-memory-extractor.d.ts.map +1 -0
  149. package/dist/processors/working-memory-state/index.d.ts +2 -0
  150. package/dist/processors/working-memory-state/index.d.ts.map +1 -0
  151. package/dist/processors/working-memory-state/processor.d.ts +53 -0
  152. package/dist/processors/working-memory-state/processor.d.ts.map +1 -0
  153. package/dist/src-C1tlhGeW.js +28559 -0
  154. package/dist/src-C1tlhGeW.js.map +1 -0
  155. package/dist/src-DqoifKIy.cjs +28813 -0
  156. package/dist/src-DqoifKIy.cjs.map +1 -0
  157. package/dist/tools/om-tools.d.ts +172 -0
  158. package/dist/tools/om-tools.d.ts.map +1 -0
  159. package/dist/tools/working-memory.d.ts +33 -28
  160. package/dist/tools/working-memory.d.ts.map +1 -1
  161. package/package.json +36 -28
  162. package/dist/index.cjs.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/processors/index.cjs.map +0 -1
  165. package/dist/processors/index.js.map +0 -1
  166. package/dist/processors/token-limiter.d.ts +0 -32
  167. package/dist/processors/token-limiter.d.ts.map +0 -1
  168. package/dist/processors/tool-call-filter.d.ts +0 -20
  169. package/dist/processors/tool-call-filter.d.ts.map +0 -1
@@ -0,0 +1,268 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Redis Storage
4
+
5
+ The Redis storage implementation provides a high-performance storage solution using direct Redis connections via [`node-redis`](https://github.com/redis/node-redis) (the official Redis client for Node.js). It supports standalone Redis, and through custom client configuration, Redis Sentinel and Cluster deployments.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @mastra/redis
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Using Connection String
16
+
17
+ ```typescript
18
+ import { RedisStore } from '@mastra/redis'
19
+
20
+ const storage = new RedisStore({
21
+ id: 'redis-storage',
22
+ connectionString: 'redis://localhost:6379',
23
+ })
24
+
25
+ await storage.init()
26
+ ```
27
+
28
+ ### Using Host/Port Configuration
29
+
30
+ ```typescript
31
+ import { RedisStore } from '@mastra/redis'
32
+
33
+ const storage = new RedisStore({
34
+ id: 'redis-storage',
35
+ host: 'localhost',
36
+ port: 6379,
37
+ password: 'your-password',
38
+ db: 0,
39
+ })
40
+
41
+ await storage.init()
42
+ ```
43
+
44
+ ### Using Pre-configured Client
45
+
46
+ For advanced configurations like Sentinel or Cluster, you can pass a pre-configured Redis client:
47
+
48
+ ```typescript
49
+ import { RedisStore } from '@mastra/redis'
50
+ import { createClient } from 'redis'
51
+
52
+ const client = createClient({
53
+ url: 'redis://localhost:6379',
54
+ socket: {
55
+ reconnectStrategy: retries => Math.min(retries * 50, 2000),
56
+ },
57
+ })
58
+
59
+ // Connect the client before passing to RedisStore
60
+ await client.connect()
61
+
62
+ const storage = new RedisStore({
63
+ id: 'redis-storage',
64
+ client,
65
+ })
66
+ ```
67
+
68
+ ## Parameters
69
+
70
+ **id** (`string`): Unique identifier for the storage instance
71
+
72
+ **connectionString** (`string`): Redis connection URL (e.g., redis\://localhost:6379 or redis\://:password\@localhost:6379)
73
+
74
+ **host** (`string`): Redis host address
75
+
76
+ **port** (`number`): Redis port number (Default: `6379`)
77
+
78
+ **password** (`string`): Redis password for authentication
79
+
80
+ **db** (`number`): Redis database number (Default: `0`)
81
+
82
+ **client** (`RedisClient`): Pre-configured redis client (from the redis package) for advanced setups
83
+
84
+ > **Note:** You must provide either `connectionString`, `host`, or `client`. These options are mutually exclusive.
85
+
86
+ ## Additional Notes
87
+
88
+ ### Key Structure
89
+
90
+ The Redis storage implementation uses the following key patterns:
91
+
92
+ - Threads: `mastra_threads:id:{threadId}`
93
+ - Messages: `mastra_messages:threadId:{threadId}:id:{messageId}`
94
+ - Message index: `msg-idx:{messageId}` (for fast lookups)
95
+ - Thread messages sorted set: `thread:{threadId}:messages`
96
+ - Workflow snapshots: `mastra_workflow_snapshot:namespace:{ns}:workflow_name:{name}:run_id:{id}`
97
+ - Scores: `mastra_scorers:id:{scoreId}`
98
+ - Resources: `mastra_resources:{resourceId}`
99
+
100
+ ### Redis Sentinel
101
+
102
+ For high-availability deployments using Redis Sentinel, create a custom client:
103
+
104
+ ```typescript
105
+ import { RedisStore } from '@mastra/redis'
106
+ import { createClient } from 'redis'
107
+
108
+ const client = createClient({
109
+ url: 'redis://sentinel-host:26379',
110
+ // Configure sentinel options as needed for your setup
111
+ })
112
+
113
+ await client.connect()
114
+
115
+ const storage = new RedisStore({
116
+ id: 'redis-sentinel-storage',
117
+ client,
118
+ })
119
+ ```
120
+
121
+ ### Redis Cluster
122
+
123
+ For Redis Cluster deployments, use the cluster client:
124
+
125
+ ```typescript
126
+ import { RedisStore } from '@mastra/redis'
127
+ import { createCluster } from 'redis'
128
+
129
+ const cluster = createCluster({
130
+ rootNodes: [
131
+ { url: 'redis://node-1:6379' },
132
+ { url: 'redis://node-2:6379' },
133
+ { url: 'redis://node-3:6379' },
134
+ ],
135
+ })
136
+
137
+ await cluster.connect()
138
+
139
+ const storage = new RedisStore({
140
+ id: 'redis-cluster-storage',
141
+ client: cluster,
142
+ })
143
+ ```
144
+
145
+ ### Accessing the Underlying Client
146
+
147
+ You can access the underlying Redis client for custom operations:
148
+
149
+ ```typescript
150
+ const storage = new RedisStore({
151
+ id: 'redis-storage',
152
+ connectionString: 'redis://localhost:6379',
153
+ })
154
+
155
+ await storage.init()
156
+
157
+ const client = storage.getClient()
158
+
159
+ // Custom Redis operations
160
+ await client.set('custom-key', 'value')
161
+ const value = await client.get('custom-key')
162
+ ```
163
+
164
+ ### Closing Connections
165
+
166
+ When shutting down your application, close the Redis connection:
167
+
168
+ ```typescript
169
+ await storage.close()
170
+ ```
171
+
172
+ ## Usage Example
173
+
174
+ ### Adding memory to an agent
175
+
176
+ ```typescript
177
+ import { Memory } from '@mastra/memory'
178
+ import { Agent } from '@mastra/core/agent'
179
+ import { RedisStore } from '@mastra/redis'
180
+
181
+ export const redisAgent = new Agent({
182
+ id: 'redis-agent',
183
+ name: 'Redis Agent',
184
+ instructions:
185
+ 'You are an AI agent with the ability to automatically recall memories from previous interactions.',
186
+ model: 'openai/gpt-5.6-sol',
187
+ memory: new Memory({
188
+ storage: new RedisStore({
189
+ id: 'redis-agent-storage',
190
+ connectionString: process.env.REDIS_URL!,
191
+ }),
192
+ options: {
193
+ lastMessages: 10,
194
+ },
195
+ }),
196
+ })
197
+ ```
198
+
199
+ ### Using the agent
200
+
201
+ ```typescript
202
+ import 'dotenv/config'
203
+
204
+ import { mastra } from './mastra'
205
+
206
+ const threadId = '123'
207
+ const resourceId = 'user-456'
208
+
209
+ const agent = mastra.getAgent('redisAgent')
210
+
211
+ const message = await agent.stream('My name is Mastra', {
212
+ memory: {
213
+ thread: threadId,
214
+ resource: resourceId,
215
+ },
216
+ })
217
+
218
+ await message.textStream.pipeTo(new WritableStream())
219
+
220
+ const stream = await agent.stream("What's my name?", {
221
+ memory: {
222
+ thread: threadId,
223
+ resource: resourceId,
224
+ },
225
+ memoryOptions: {
226
+ lastMessages: 5,
227
+ },
228
+ })
229
+
230
+ for await (const chunk of stream.textStream) {
231
+ process.stdout.write(chunk)
232
+ }
233
+ ```
234
+
235
+ ### Using with Mastra instance
236
+
237
+ ```typescript
238
+ import { Mastra } from '@mastra/core'
239
+ import { RedisStore } from '@mastra/redis'
240
+
241
+ const storage = new RedisStore({
242
+ id: 'mastra-storage',
243
+ host: 'localhost',
244
+ port: 6379,
245
+ })
246
+
247
+ const mastra = new Mastra({
248
+ storage, // init() called automatically
249
+ })
250
+ ```
251
+
252
+ If using storage directly without Mastra, call `init()` explicitly:
253
+
254
+ ```typescript
255
+ import { RedisStore } from '@mastra/redis'
256
+
257
+ const storage = new RedisStore({
258
+ id: 'redis-storage',
259
+ host: 'localhost',
260
+ port: 6379,
261
+ })
262
+
263
+ await storage.init()
264
+
265
+ // Access domain-specific stores via getStore()
266
+ const memoryStore = await storage.getStore('memory')
267
+ const thread = await memoryStore?.getThreadById({ threadId: '...' })
268
+ ```
@@ -0,0 +1,162 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Upstash storage
4
+
5
+ The Upstash storage implementation provides a serverless-friendly storage solution using Upstash's Redis-compatible key-value store.
6
+
7
+ > **Pricing:** When using Mastra with Upstash, the pay-as-you-go model can result in unexpectedly high costs due to the high volume of Redis commands generated during agent conversations. We strongly recommend using a **fixed pricing plan** for predictable costs. See [Upstash pricing](https://upstash.com/pricing/redis) for details and [GitHub issue #5850](https://github.com/mastra-ai/mastra/issues/5850) for context.
8
+
9
+ > **Observability Not Supported:** Upstash storage **doesn't support the observability domain**. Traces from the `MastraStorageExporter` can't be persisted to Upstash, and [Studio's](https://mastra.ai/docs/studio/overview) observability features won't work with Upstash as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse.
10
+
11
+ ## Installation
12
+
13
+ **npm**:
14
+
15
+ ```bash
16
+ npm install @mastra/upstash@latest
17
+ ```
18
+
19
+ **pnpm**:
20
+
21
+ ```bash
22
+ pnpm add @mastra/upstash@latest
23
+ ```
24
+
25
+ **Yarn**:
26
+
27
+ ```bash
28
+ yarn add @mastra/upstash@latest
29
+ ```
30
+
31
+ **Bun**:
32
+
33
+ ```bash
34
+ bun add @mastra/upstash@latest
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```typescript
40
+ import { UpstashStore } from '@mastra/upstash'
41
+
42
+ const storage = new UpstashStore({
43
+ id: 'upstash-storage',
44
+ url: process.env.UPSTASH_URL,
45
+ token: process.env.UPSTASH_TOKEN,
46
+ })
47
+ ```
48
+
49
+ ## Parameters
50
+
51
+ **url** (`string`): Upstash Redis URL
52
+
53
+ **token** (`string`): Upstash Redis authentication token
54
+
55
+ **prefix** (`string`): Key prefix for all stored items (Default: `mastra:`)
56
+
57
+ ## Additional notes
58
+
59
+ ### Key Structure
60
+
61
+ The Upstash storage implementation uses a key-value structure:
62
+
63
+ - Thread keys: `{prefix}thread:{threadId}`
64
+ - Message keys: `{prefix}message:{messageId}`
65
+ - Metadata keys: `{prefix}metadata:{entityId}`
66
+
67
+ ### Serverless Benefits
68
+
69
+ Upstash storage is particularly well-suited for serverless deployments:
70
+
71
+ - No connection management needed
72
+ - Pay-per-request pricing
73
+ - Global replication options
74
+ - Edge-compatible
75
+
76
+ ### Data Persistence
77
+
78
+ Upstash provides:
79
+
80
+ - Automatic data persistence
81
+ - Point-in-time recovery
82
+ - Cross-region replication options
83
+
84
+ ### Performance Considerations
85
+
86
+ For optimal performance:
87
+
88
+ - Use appropriate key prefixes to organize data
89
+ - Monitor Redis memory usage
90
+ - Consider data expiration policies if needed
91
+
92
+ ## Usage example
93
+
94
+ ### Adding memory to an agent
95
+
96
+ To add Upstash memory to an agent use the `Memory` class and create a new `storage` key using `UpstashStore` and a new `vector` key using `UpstashVector`. The configuration can point to either a remote service or a local setup.
97
+
98
+ ```typescript
99
+ import { Memory } from '@mastra/memory'
100
+ import { Agent } from '@mastra/core/agent'
101
+ import { UpstashStore } from '@mastra/upstash'
102
+
103
+ export const upstashAgent = new Agent({
104
+ id: 'upstash-agent',
105
+ name: 'Upstash Agent',
106
+ instructions:
107
+ 'You are an AI agent with the ability to automatically recall memories from previous interactions.',
108
+ model: 'openai/gpt-5.6-sol',
109
+ memory: new Memory({
110
+ storage: new UpstashStore({
111
+ id: 'upstash-agent-storage',
112
+ url: process.env.UPSTASH_REDIS_REST_URL!,
113
+ token: process.env.UPSTASH_REDIS_REST_TOKEN!,
114
+ }),
115
+ options: {
116
+ generateTitle: true, // Explicitly enable automatic title generation
117
+ },
118
+ }),
119
+ })
120
+ ```
121
+
122
+ ### Using the agent
123
+
124
+ Use `memoryOptions` to scope recall for this request. Set `lastMessages: 5` to limit recency-based recall, and use `semanticRecall` to fetch the `topK: 3` most relevant messages, including `messageRange: 2` neighboring messages for context around each match.
125
+
126
+ ```typescript
127
+ import 'dotenv/config'
128
+
129
+ import { mastra } from './mastra'
130
+
131
+ const threadId = '123'
132
+ const resourceId = 'user-456'
133
+
134
+ const agent = mastra.getAgent('upstashAgent')
135
+
136
+ const message = await agent.stream('My name is Mastra', {
137
+ memory: {
138
+ thread: threadId,
139
+ resource: resourceId,
140
+ },
141
+ })
142
+
143
+ await message.textStream.pipeTo(new WritableStream())
144
+
145
+ const stream = await agent.stream("What's my name?", {
146
+ memory: {
147
+ thread: threadId,
148
+ resource: resourceId,
149
+ },
150
+ memoryOptions: {
151
+ lastMessages: 5,
152
+ semanticRecall: {
153
+ topK: 3,
154
+ messageRange: 2,
155
+ },
156
+ },
157
+ })
158
+
159
+ for await (const chunk of stream.textStream) {
160
+ process.stdout.write(chunk)
161
+ }
162
+ ```