@@ -34,11 +34,11 @@ const agent = new Agent(withSupermemory(
3434 model: openai (" gpt-4o" ),
3535 instructions: " You are a helpful assistant." ,
3636 },
37- " user-123" , // containerTag - scopes memories to this user
37+ " user-123" , // containerTag - scopes memories to this user
38+ " conv-456" , // conversationId - groups messages into the same document
3839 {
3940 mode: " full" ,
4041 addMemory: " always" ,
41- threadId: " conv-456" ,
4242 }
4343))
4444
@@ -52,10 +52,8 @@ const response = await agent.generate("What do you know about me?")
5252 const agent = new Agent (withSupermemory (
5353 { id: " my-assistant" , model: openai (" gpt-4o" ), ... },
5454 " user-123" ,
55- {
56- addMemory: " always" ,
57- threadId: " conv-456" // Required for conversation grouping
58- }
55+ " conv-456" ,
56+ { addMemory: " always" }
5957 ))
6058 ```
6159</Note >
@@ -100,7 +98,6 @@ sequenceDiagram
10098| ` baseUrl ` | ` string ` | ` https://api.supermemory.ai ` | Custom API endpoint |
10199| ` mode ` | ` "profile" \| "query" \| "full" ` | ` "profile" ` | Memory search mode |
102100| ` addMemory ` | ` "always" \| "never" ` | ` "never" ` | Auto-save conversations |
103- | ` threadId ` | ` string ` | - | Conversation ID for grouping messages |
104101| ` verbose ` | ` boolean ` | ` false ` | Enable debug logging |
105102| ` promptTemplate ` | ` function ` | - | Custom memory formatting |
106103
@@ -111,19 +108,19 @@ sequenceDiagram
111108** Profile Mode (Default)** - Retrieves the user's complete profile without query-based filtering:
112109
113110``` typescript
114- const agent = new Agent (withSupermemory (config , " user-123" , { mode: " profile" }))
111+ const agent = new Agent (withSupermemory (config , " user-123" , " conv-456 " , { mode: " profile" }))
115112```
116113
117114** Query Mode** - Searches memories based on the user's message:
118115
119116``` typescript
120- const agent = new Agent (withSupermemory (config , " user-123" , { mode: " query" }))
117+ const agent = new Agent (withSupermemory (config , " user-123" , " conv-456 " , { mode: " query" }))
121118```
122119
123120** Full Mode** - Combines profile AND query-based search for maximum context:
124121
125122``` typescript
126- const agent = new Agent (withSupermemory (config , " user-123" , { mode: " full" }))
123+ const agent = new Agent (withSupermemory (config , " user-123" , " conv-456 " , { mode: " full" }))
127124
128125### Mode Comparison
129126
@@ -137,27 +134,21 @@ const agent = new Agent(withSupermemory(config, "user-123", { mode: "full" }))
137134
138135## Saving Conversations
139136
140- Enable automatic conversation saving with ` addMemory: "always" ` . A ` threadId ` is required to group messages :
137+ Enable automatic conversation saving with ` addMemory: "always" ` . The ` conversationId ` parameter groups messages into the same document :
141138
142139` ` ` typescript
143140const agent = new Agent(withSupermemory(
144141 { id: "my-assistant", model: openai("gpt-4o"), instructions: "..." },
145142 "user-123",
146- {
147- addMemory: "always",
148- threadId: "conv-456",
149- }
143+ "conv-456",
144+ { addMemory: "always" }
150145))
151146
152147// All messages in this conversation are saved
153148await agent.generate("I prefer TypeScript over JavaScript")
154149await agent.generate("My favorite framework is Next.js")
155150` ` `
156151
157- <Warning >
158- Without a ` threadId ` , the output processor will log a warning and skip saving . Always provide a ` threadId ` when using ` addMemory: "always" ` .
159- < / Warning >
160-
161152-- -
162153
163154## Custom Prompt Templates
@@ -183,6 +174,7 @@ const claudePrompt = (data: MemoryPromptData) => `
183174const agent = new Agent(withSupermemory(
184175 { id: "my-assistant", model: openai("gpt-4o"), instructions: "..." },
185176 "user-123",
177+ "conv-456",
186178 {
187179 mode: "full",
188180 promptTemplate: claudePrompt,
@@ -210,7 +202,7 @@ const agent = new Agent({
210202 name: "My Assistant",
211203 model: openai("gpt-4o"),
212204 inputProcessors: [
213- createSupermemoryProcessor("user-123", {
205+ createSupermemoryProcessor("user-123", "conv-456", {
214206 mode: "full",
215207 verbose: true,
216208 }),
@@ -232,9 +224,8 @@ const agent = new Agent({
232224 name: "My Assistant",
233225 model: openai("gpt-4o"),
234226 outputProcessors: [
235- createSupermemoryOutputProcessor("user-123", {
227+ createSupermemoryOutputProcessor("user-123", "conv-456", {
236228 addMemory: "always",
237- threadId: "conv-456",
238229 }),
239230 ],
240231})
@@ -249,10 +240,9 @@ import { Agent } from "@mastra/core/agent"
249240import { createSupermemoryProcessors } from "@supermemory/tools/mastra"
250241import { openai } from "@ai-sdk/openai"
251242
252- const { input, output } = createSupermemoryProcessors("user-123", {
243+ const { input, output } = createSupermemoryProcessors("user-123", "conv-456", {
253244 mode: "full",
254245 addMemory: "always",
255- threadId: "conv-456",
256246 verbose: true,
257247})
258248
@@ -269,7 +259,7 @@ const agent = new Agent({
269259
270260## Using RequestContext
271261
272- Mastra ' s `RequestContext` can provide `threadId` dynamically :
262+ Mastra ' s `RequestContext` can provide a dynamic conversation ID override :
273263
274264` ` ` typescript
275265import { Agent } from "@mastra/core/agent"
@@ -280,14 +270,14 @@ import { openai } from "@ai-sdk/openai"
280270const agent = new Agent(withSupermemory(
281271 { id: "my-assistant", model: openai("gpt-4o"), instructions: "..." },
282272 "user-123",
273+ "default-conv-id",
283274 {
284275 mode: "full",
285276 addMemory: "always",
286- // threadId not set - will use RequestContext
287277 }
288278))
289279
290- // Set threadId dynamically via RequestContext
280+ // Override conversationId dynamically via RequestContext
291281const ctx = new RequestContext()
292282ctx.set(MASTRA_THREAD_ID_KEY, "dynamic-thread-id")
293283
@@ -304,6 +294,7 @@ Enable detailed logging for debugging:
304294const agent = new Agent(withSupermemory(
305295 { id: "my-assistant", model: openai("gpt-4o"), instructions: "..." },
306296 "user-123",
297+ "conv-456",
307298 { verbose: true }
308299))
309300
@@ -330,7 +321,8 @@ const agent = new Agent(withSupermemory(
330321 inputProcessors: [myLoggingProcessor],
331322 outputProcessors: [myAnalyticsProcessor],
332323 },
333- "user-123"
324+ "user-123",
325+ "conv-456"
334326))
335327` ` `
336328
@@ -346,13 +338,15 @@ Enhances a Mastra agent config with memory capabilities.
346338function withSupermemory<T extends AgentConfig>(
347339 config: T,
348340 containerTag: string,
341+ conversationId: string,
349342 options?: SupermemoryMastraOptions
350343): T
351344` ` `
352345
353346** Parameters :**
354347- ` config ` - The Mastra agent configuration object
355348- ` containerTag ` - User / container ID for scoping memories
349+ - ` conversationId ` - Conversation ID to group messages into the same document
356350- ` options ` - Configuration options
357351
358352** Returns :** Enhanced config with Supermemory processors injected
@@ -364,6 +358,7 @@ Creates an input processor for memory injection.
364358` ` ` typescript
365359function createSupermemoryProcessor(
366360 containerTag: string,
361+ conversationId: string,
367362 options?: SupermemoryMastraOptions
368363): SupermemoryInputProcessor
369364` ` `
@@ -375,6 +370,7 @@ Creates an output processor for conversation saving.
375370` ` ` typescript
376371function createSupermemoryOutputProcessor(
377372 containerTag: string,
373+ conversationId: string,
378374 options?: SupermemoryMastraOptions
379375): SupermemoryOutputProcessor
380376` ` `
@@ -386,6 +382,7 @@ Creates both processors with shared configuration.
386382` ` ` typescript
387383function createSupermemoryProcessors(
388384 containerTag: string,
385+ conversationId: string,
389386 options?: SupermemoryMastraOptions
390387): {
391388 input: SupermemoryInputProcessor
@@ -401,7 +398,6 @@ interface SupermemoryMastraOptions {
401398 baseUrl?: string
402399 mode?: "profile" | "query" | "full"
403400 addMemory?: "always" | "never"
404- threadId?: string
405401 verbose?: boolean
406402 promptTemplate?: (data: MemoryPromptData) => string
407403}
@@ -423,13 +419,14 @@ Processors gracefully handle errors without breaking the agent:
423419
424420- ** API errors ** - Logged and skipped ; agent continues without memories
425421- ** Missing API key ** - Throws immediately with helpful error message
426- - ** Missing threadId ** - Warns in console ; skips saving
422+ - ** Empty conversationId ** - Throws immediately with helpful ` [supermemory] ` - prefixed error message
427423
428424` ` ` typescript
429425// Missing API key throws immediately
430426const agent = new Agent(withSupermemory(
431427 { id: "my-assistant", model: openai("gpt-4o"), instructions: "..." },
432428 "user-123",
429+ "conv-456",
433430 { apiKey: undefined } // Will check SUPERMEMORY_API_KEY env
434431))
435432// Error: SUPERMEMORY_API_KEY is not set
0 commit comments