@mastra/memory 0.2.7-alpha.2 → 0.2.7-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +18 -0
- package/README.md +1 -1
- package/dist/index.cjs +22 -23
- package/dist/index.js +22 -23
- package/package.json +3 -3
- package/src/index.ts +21 -25
- package/src/processors/index.test.ts +3 -1
- package/src/tools/working-memory.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/memory@0.2.7-alpha.
|
|
2
|
+
> @mastra/memory@0.2.7-alpha.3 build /home/runner/work/mastra/mastra/packages/memory
|
|
3
3
|
> pnpm run check && tsup src/index.ts src/processors/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @mastra/memory@0.2.7-alpha.
|
|
6
|
+
> @mastra/memory@0.2.7-alpha.3 check /home/runner/work/mastra/mastra/packages/memory
|
|
7
7
|
> tsc --noEmit
|
|
8
8
|
|
|
9
9
|
[34mCLI[39m Building entry: src/index.ts, src/processors/index.ts
|
|
10
10
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
11
11
|
[34mCLI[39m tsup v8.4.0
|
|
12
12
|
[34mTSC[39m Build start
|
|
13
|
-
[32mTSC[39m ⚡️ Build success in
|
|
13
|
+
[32mTSC[39m ⚡️ Build success in 11095ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
15
|
[34mCLI[39m Target: es2022
|
|
16
16
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
17
17
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.ts[39m
|
|
18
18
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
19
19
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/memory/dist/_tsup-dts-rollup.d.cts[39m
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 6446ms
|
|
21
21
|
[34mCLI[39m Cleaning output folder
|
|
22
22
|
[34mESM[39m Build start
|
|
23
23
|
[34mCJS[39m Build start
|
|
24
|
-
[
|
|
25
|
-
[32mESM[39m [1mdist/processors/index.js [22m[32m5.33 KB[39m
|
|
26
|
-
[32mESM[39m ⚡️ Build success in 238ms
|
|
27
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m13.62 KB[39m
|
|
24
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m13.53 KB[39m
|
|
28
25
|
[32mCJS[39m [1mdist/processors/index.cjs [22m[32m5.54 KB[39m
|
|
29
|
-
[32mCJS[39m ⚡️ Build success in
|
|
26
|
+
[32mCJS[39m ⚡️ Build success in 411ms
|
|
27
|
+
[32mESM[39m [1mdist/processors/index.js [22m[32m5.33 KB[39m
|
|
28
|
+
[32mESM[39m [1mdist/index.js [22m[32m13.50 KB[39m
|
|
29
|
+
[32mESM[39m ⚡️ Build success in 412ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 0.2.7-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5ae0180: Removed prefixed doc references
|
|
8
|
+
- 3e72f94: Updated the internal working memory system to use MD for formatting instead of nested XML - this is more token efficient and makes it more obvious that it's unstructured text
|
|
9
|
+
- Updated dependencies [5ae0180]
|
|
10
|
+
- Updated dependencies [9bfa12b]
|
|
11
|
+
- Updated dependencies [515ebfb]
|
|
12
|
+
- Updated dependencies [88fa727]
|
|
13
|
+
- Updated dependencies [f37f535]
|
|
14
|
+
- Updated dependencies [4d67826]
|
|
15
|
+
- Updated dependencies [6330967]
|
|
16
|
+
- Updated dependencies [8393832]
|
|
17
|
+
- Updated dependencies [6330967]
|
|
18
|
+
- @mastra/core@0.8.0-alpha.3
|
|
19
|
+
- @mastra/rag@0.1.15-alpha.3
|
|
20
|
+
|
|
3
21
|
## 0.2.7-alpha.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Mastra Memory
|
|
2
2
|
|
|
3
|
-
Memory management for Mastra agents. Visit [the docs](https://mastra.ai/docs/agents/
|
|
3
|
+
Memory management for Mastra agents. Visit [the docs](https://mastra.ai/docs/agents/agent-memory) for more information.
|
|
4
4
|
|
|
5
5
|
## License
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var zod = require('zod');
|
|
|
10
10
|
var updateWorkingMemoryTool = {
|
|
11
11
|
description: "Update the working memory with new information",
|
|
12
12
|
parameters: zod.z.object({
|
|
13
|
-
memory: zod.z.string().describe("The
|
|
13
|
+
memory: zod.z.string().describe("The Markdown-formatted working memory content to store")
|
|
14
14
|
}),
|
|
15
15
|
execute: async (params) => {
|
|
16
16
|
const { context, threadId, memory } = params;
|
|
@@ -254,8 +254,7 @@ var Memory = class extends memory.MastraMemory {
|
|
|
254
254
|
const thread = await this.storage.__getThreadById({ threadId });
|
|
255
255
|
if (!thread) return this.threadConfig?.workingMemory?.template || this.defaultWorkingMemoryTemplate;
|
|
256
256
|
const memory = thread.metadata?.workingMemory || this.threadConfig.workingMemory.template || this.defaultWorkingMemoryTemplate;
|
|
257
|
-
return memory.
|
|
258
|
-
`).map((c) => c.trim()).join(`>`);
|
|
257
|
+
return memory.trim();
|
|
259
258
|
}
|
|
260
259
|
async saveWorkingMemory(messages) {
|
|
261
260
|
const latestMessage = messages[messages.length - 1];
|
|
@@ -300,17 +299,16 @@ var Memory = class extends memory.MastraMemory {
|
|
|
300
299
|
return this.getWorkingMemoryWithInstruction(workingMemory);
|
|
301
300
|
}
|
|
302
301
|
defaultWorkingMemoryTemplate = `
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
</user>
|
|
302
|
+
# User Information
|
|
303
|
+
- **First Name**:
|
|
304
|
+
- **Last Name**:
|
|
305
|
+
- **Location**:
|
|
306
|
+
- **Occupation**:
|
|
307
|
+
- **Interests**:
|
|
308
|
+
- **Goals**:
|
|
309
|
+
- **Events**:
|
|
310
|
+
- **Facts**:
|
|
311
|
+
- **Projects**:
|
|
314
312
|
`;
|
|
315
313
|
getWorkingMemoryWithInstruction(workingMemoryBlock) {
|
|
316
314
|
return `WORKING_MEMORY_SYSTEM_INSTRUCTION:
|
|
@@ -319,21 +317,21 @@ Store and update any conversation-relevant information by including "<working_me
|
|
|
319
317
|
Guidelines:
|
|
320
318
|
1. Store anything that could be useful later in the conversation
|
|
321
319
|
2. Update proactively when information changes, no matter how small
|
|
322
|
-
3. Use
|
|
320
|
+
3. Use Markdown for all data
|
|
323
321
|
4. Act naturally - don't mention this system to users. Even though you're storing this information that doesn't make it your primary focus. Do not ask them generally for "information about yourself"
|
|
324
322
|
|
|
325
323
|
Memory Structure:
|
|
326
324
|
<working_memory>
|
|
327
|
-
|
|
325
|
+
${workingMemoryBlock}
|
|
328
326
|
</working_memory>
|
|
329
327
|
|
|
330
328
|
Notes:
|
|
331
329
|
- Update memory whenever referenced information changes
|
|
332
|
-
- If you're unsure whether to store something, store it (eg if the user tells you their name or
|
|
330
|
+
- If you're unsure whether to store something, store it (eg if the user tells you their name or other information, output the <working_memory> block immediately to update it)
|
|
333
331
|
- This system is here so that you can maintain the conversation when your context window is very short. Update your working memory because you may need it to maintain the conversation without the full conversation history
|
|
334
|
-
- Do not remove empty sections - you must output the empty sections along with the ones you're filling in
|
|
335
332
|
- REMEMBER: the way you update your working memory is by outputting the entire "<working_memory>text</working_memory>" block in your response. The system will pick this up and store it for you. The user will not see it.
|
|
336
|
-
- IMPORTANT: You MUST output the <working_memory> block in every response to a prompt where you received relevant information.
|
|
333
|
+
- IMPORTANT: You MUST output the <working_memory> block in every response to a prompt where you received relevant information.
|
|
334
|
+
- IMPORTANT: Preserve the Markdown formatting structure above while updating the content.`;
|
|
337
335
|
}
|
|
338
336
|
getWorkingMemoryToolInstruction(workingMemoryBlock) {
|
|
339
337
|
return `WORKING_MEMORY_SYSTEM_INSTRUCTION:
|
|
@@ -342,7 +340,7 @@ Store and update any conversation-relevant information by calling the updateWork
|
|
|
342
340
|
Guidelines:
|
|
343
341
|
1. Store anything that could be useful later in the conversation
|
|
344
342
|
2. Update proactively when information changes, no matter how small
|
|
345
|
-
3. Use
|
|
343
|
+
3. Use Markdown format for all data
|
|
346
344
|
4. Act naturally - don't mention this system to users. Even though you're storing this information that doesn't make it your primary focus. Do not ask them generally for "information about yourself"
|
|
347
345
|
|
|
348
346
|
Memory Structure:
|
|
@@ -350,11 +348,12 @@ ${workingMemoryBlock}
|
|
|
350
348
|
|
|
351
349
|
Notes:
|
|
352
350
|
- Update memory whenever referenced information changes
|
|
353
|
-
- If you're unsure whether to store something, store it (eg if the user tells you
|
|
351
|
+
- If you're unsure whether to store something, store it (eg if the user tells you information about themselves, call updateWorkingMemory immediately to update it)
|
|
354
352
|
- This system is here so that you can maintain the conversation when your context window is very short. Update your working memory because you may need it to maintain the conversation without the full conversation history
|
|
355
353
|
- Do not remove empty sections - you must include the empty sections along with the ones you're filling in
|
|
356
|
-
- REMEMBER: the way you update your working memory is by calling the updateWorkingMemory tool with the entire
|
|
357
|
-
- IMPORTANT: You MUST call updateWorkingMemory in every response to a prompt where you received relevant information
|
|
354
|
+
- REMEMBER: the way you update your working memory is by calling the updateWorkingMemory tool with the entire Markdown content. The system will store it for you. The user will not see it.
|
|
355
|
+
- IMPORTANT: You MUST call updateWorkingMemory in every response to a prompt where you received relevant information.
|
|
356
|
+
- IMPORTANT: Preserve the Markdown formatting structure above while updating the content.`;
|
|
358
357
|
}
|
|
359
358
|
getTools(config) {
|
|
360
359
|
const mergedConfig = this.getMergedThreadConfig(config);
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { z } from 'zod';
|
|
|
8
8
|
var updateWorkingMemoryTool = {
|
|
9
9
|
description: "Update the working memory with new information",
|
|
10
10
|
parameters: z.object({
|
|
11
|
-
memory: z.string().describe("The
|
|
11
|
+
memory: z.string().describe("The Markdown-formatted working memory content to store")
|
|
12
12
|
}),
|
|
13
13
|
execute: async (params) => {
|
|
14
14
|
const { context, threadId, memory } = params;
|
|
@@ -252,8 +252,7 @@ var Memory = class extends MastraMemory {
|
|
|
252
252
|
const thread = await this.storage.__getThreadById({ threadId });
|
|
253
253
|
if (!thread) return this.threadConfig?.workingMemory?.template || this.defaultWorkingMemoryTemplate;
|
|
254
254
|
const memory = thread.metadata?.workingMemory || this.threadConfig.workingMemory.template || this.defaultWorkingMemoryTemplate;
|
|
255
|
-
return memory.
|
|
256
|
-
`).map((c) => c.trim()).join(`>`);
|
|
255
|
+
return memory.trim();
|
|
257
256
|
}
|
|
258
257
|
async saveWorkingMemory(messages) {
|
|
259
258
|
const latestMessage = messages[messages.length - 1];
|
|
@@ -298,17 +297,16 @@ var Memory = class extends MastraMemory {
|
|
|
298
297
|
return this.getWorkingMemoryWithInstruction(workingMemory);
|
|
299
298
|
}
|
|
300
299
|
defaultWorkingMemoryTemplate = `
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
</user>
|
|
300
|
+
# User Information
|
|
301
|
+
- **First Name**:
|
|
302
|
+
- **Last Name**:
|
|
303
|
+
- **Location**:
|
|
304
|
+
- **Occupation**:
|
|
305
|
+
- **Interests**:
|
|
306
|
+
- **Goals**:
|
|
307
|
+
- **Events**:
|
|
308
|
+
- **Facts**:
|
|
309
|
+
- **Projects**:
|
|
312
310
|
`;
|
|
313
311
|
getWorkingMemoryWithInstruction(workingMemoryBlock) {
|
|
314
312
|
return `WORKING_MEMORY_SYSTEM_INSTRUCTION:
|
|
@@ -317,21 +315,21 @@ Store and update any conversation-relevant information by including "<working_me
|
|
|
317
315
|
Guidelines:
|
|
318
316
|
1. Store anything that could be useful later in the conversation
|
|
319
317
|
2. Update proactively when information changes, no matter how small
|
|
320
|
-
3. Use
|
|
318
|
+
3. Use Markdown for all data
|
|
321
319
|
4. Act naturally - don't mention this system to users. Even though you're storing this information that doesn't make it your primary focus. Do not ask them generally for "information about yourself"
|
|
322
320
|
|
|
323
321
|
Memory Structure:
|
|
324
322
|
<working_memory>
|
|
325
|
-
|
|
323
|
+
${workingMemoryBlock}
|
|
326
324
|
</working_memory>
|
|
327
325
|
|
|
328
326
|
Notes:
|
|
329
327
|
- Update memory whenever referenced information changes
|
|
330
|
-
- If you're unsure whether to store something, store it (eg if the user tells you their name or
|
|
328
|
+
- If you're unsure whether to store something, store it (eg if the user tells you their name or other information, output the <working_memory> block immediately to update it)
|
|
331
329
|
- This system is here so that you can maintain the conversation when your context window is very short. Update your working memory because you may need it to maintain the conversation without the full conversation history
|
|
332
|
-
- Do not remove empty sections - you must output the empty sections along with the ones you're filling in
|
|
333
330
|
- REMEMBER: the way you update your working memory is by outputting the entire "<working_memory>text</working_memory>" block in your response. The system will pick this up and store it for you. The user will not see it.
|
|
334
|
-
- IMPORTANT: You MUST output the <working_memory> block in every response to a prompt where you received relevant information.
|
|
331
|
+
- IMPORTANT: You MUST output the <working_memory> block in every response to a prompt where you received relevant information.
|
|
332
|
+
- IMPORTANT: Preserve the Markdown formatting structure above while updating the content.`;
|
|
335
333
|
}
|
|
336
334
|
getWorkingMemoryToolInstruction(workingMemoryBlock) {
|
|
337
335
|
return `WORKING_MEMORY_SYSTEM_INSTRUCTION:
|
|
@@ -340,7 +338,7 @@ Store and update any conversation-relevant information by calling the updateWork
|
|
|
340
338
|
Guidelines:
|
|
341
339
|
1. Store anything that could be useful later in the conversation
|
|
342
340
|
2. Update proactively when information changes, no matter how small
|
|
343
|
-
3. Use
|
|
341
|
+
3. Use Markdown format for all data
|
|
344
342
|
4. Act naturally - don't mention this system to users. Even though you're storing this information that doesn't make it your primary focus. Do not ask them generally for "information about yourself"
|
|
345
343
|
|
|
346
344
|
Memory Structure:
|
|
@@ -348,11 +346,12 @@ ${workingMemoryBlock}
|
|
|
348
346
|
|
|
349
347
|
Notes:
|
|
350
348
|
- Update memory whenever referenced information changes
|
|
351
|
-
- If you're unsure whether to store something, store it (eg if the user tells you
|
|
349
|
+
- If you're unsure whether to store something, store it (eg if the user tells you information about themselves, call updateWorkingMemory immediately to update it)
|
|
352
350
|
- This system is here so that you can maintain the conversation when your context window is very short. Update your working memory because you may need it to maintain the conversation without the full conversation history
|
|
353
351
|
- Do not remove empty sections - you must include the empty sections along with the ones you're filling in
|
|
354
|
-
- REMEMBER: the way you update your working memory is by calling the updateWorkingMemory tool with the entire
|
|
355
|
-
- IMPORTANT: You MUST call updateWorkingMemory in every response to a prompt where you received relevant information
|
|
352
|
+
- REMEMBER: the way you update your working memory is by calling the updateWorkingMemory tool with the entire Markdown content. The system will store it for you. The user will not see it.
|
|
353
|
+
- IMPORTANT: You MUST call updateWorkingMemory in every response to a prompt where you received relevant information.
|
|
354
|
+
- IMPORTANT: Preserve the Markdown formatting structure above while updating the content.`;
|
|
356
355
|
}
|
|
357
356
|
getTools(config) {
|
|
358
357
|
const mergedConfig = this.getMergedThreadConfig(config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "0.2.7-alpha.
|
|
3
|
+
"version": "0.2.7-alpha.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"postgres": "^3.4.5",
|
|
41
41
|
"redis": "^4.7.0",
|
|
42
42
|
"zod": "^3.24.2",
|
|
43
|
-
"@mastra/core": "^0.8.0-alpha.
|
|
44
|
-
"@mastra/rag": "^0.1.15-alpha.
|
|
43
|
+
"@mastra/core": "^0.8.0-alpha.3",
|
|
44
|
+
"@mastra/rag": "^0.1.15-alpha.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@ai-sdk/openai": "^1.3.3",
|
package/src/index.ts
CHANGED
|
@@ -332,11 +332,7 @@ export class Memory extends MastraMemory {
|
|
|
332
332
|
this.threadConfig.workingMemory.template ||
|
|
333
333
|
this.defaultWorkingMemoryTemplate;
|
|
334
334
|
|
|
335
|
-
|
|
336
|
-
return memory
|
|
337
|
-
.split(`>\n`)
|
|
338
|
-
.map(c => c.trim()) // remove extra whitespace
|
|
339
|
-
.join(`>`); // and linebreaks
|
|
335
|
+
return memory.trim();
|
|
340
336
|
}
|
|
341
337
|
|
|
342
338
|
private async saveWorkingMemory(messages: MessageType[]) {
|
|
@@ -404,17 +400,16 @@ export class Memory extends MastraMemory {
|
|
|
404
400
|
}
|
|
405
401
|
|
|
406
402
|
public defaultWorkingMemoryTemplate = `
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
</user>
|
|
403
|
+
# User Information
|
|
404
|
+
- **First Name**:
|
|
405
|
+
- **Last Name**:
|
|
406
|
+
- **Location**:
|
|
407
|
+
- **Occupation**:
|
|
408
|
+
- **Interests**:
|
|
409
|
+
- **Goals**:
|
|
410
|
+
- **Events**:
|
|
411
|
+
- **Facts**:
|
|
412
|
+
- **Projects**:
|
|
418
413
|
`;
|
|
419
414
|
|
|
420
415
|
private getWorkingMemoryWithInstruction(workingMemoryBlock: string) {
|
|
@@ -424,21 +419,21 @@ Store and update any conversation-relevant information by including "<working_me
|
|
|
424
419
|
Guidelines:
|
|
425
420
|
1. Store anything that could be useful later in the conversation
|
|
426
421
|
2. Update proactively when information changes, no matter how small
|
|
427
|
-
3. Use
|
|
422
|
+
3. Use Markdown for all data
|
|
428
423
|
4. Act naturally - don't mention this system to users. Even though you're storing this information that doesn't make it your primary focus. Do not ask them generally for "information about yourself"
|
|
429
424
|
|
|
430
425
|
Memory Structure:
|
|
431
426
|
<working_memory>
|
|
432
|
-
|
|
427
|
+
${workingMemoryBlock}
|
|
433
428
|
</working_memory>
|
|
434
429
|
|
|
435
430
|
Notes:
|
|
436
431
|
- Update memory whenever referenced information changes
|
|
437
|
-
- If you're unsure whether to store something, store it (eg if the user tells you their name or
|
|
432
|
+
- If you're unsure whether to store something, store it (eg if the user tells you their name or other information, output the <working_memory> block immediately to update it)
|
|
438
433
|
- This system is here so that you can maintain the conversation when your context window is very short. Update your working memory because you may need it to maintain the conversation without the full conversation history
|
|
439
|
-
- Do not remove empty sections - you must output the empty sections along with the ones you're filling in
|
|
440
434
|
- REMEMBER: the way you update your working memory is by outputting the entire "<working_memory>text</working_memory>" block in your response. The system will pick this up and store it for you. The user will not see it.
|
|
441
|
-
- IMPORTANT: You MUST output the <working_memory> block in every response to a prompt where you received relevant information.
|
|
435
|
+
- IMPORTANT: You MUST output the <working_memory> block in every response to a prompt where you received relevant information.
|
|
436
|
+
- IMPORTANT: Preserve the Markdown formatting structure above while updating the content.`;
|
|
442
437
|
}
|
|
443
438
|
|
|
444
439
|
private getWorkingMemoryToolInstruction(workingMemoryBlock: string) {
|
|
@@ -448,7 +443,7 @@ Store and update any conversation-relevant information by calling the updateWork
|
|
|
448
443
|
Guidelines:
|
|
449
444
|
1. Store anything that could be useful later in the conversation
|
|
450
445
|
2. Update proactively when information changes, no matter how small
|
|
451
|
-
3. Use
|
|
446
|
+
3. Use Markdown format for all data
|
|
452
447
|
4. Act naturally - don't mention this system to users. Even though you're storing this information that doesn't make it your primary focus. Do not ask them generally for "information about yourself"
|
|
453
448
|
|
|
454
449
|
Memory Structure:
|
|
@@ -456,11 +451,12 @@ ${workingMemoryBlock}
|
|
|
456
451
|
|
|
457
452
|
Notes:
|
|
458
453
|
- Update memory whenever referenced information changes
|
|
459
|
-
- If you're unsure whether to store something, store it (eg if the user tells you
|
|
454
|
+
- If you're unsure whether to store something, store it (eg if the user tells you information about themselves, call updateWorkingMemory immediately to update it)
|
|
460
455
|
- This system is here so that you can maintain the conversation when your context window is very short. Update your working memory because you may need it to maintain the conversation without the full conversation history
|
|
461
456
|
- Do not remove empty sections - you must include the empty sections along with the ones you're filling in
|
|
462
|
-
- REMEMBER: the way you update your working memory is by calling the updateWorkingMemory tool with the entire
|
|
463
|
-
- IMPORTANT: You MUST call updateWorkingMemory in every response to a prompt where you received relevant information
|
|
457
|
+
- REMEMBER: the way you update your working memory is by calling the updateWorkingMemory tool with the entire Markdown content. The system will store it for you. The user will not see it.
|
|
458
|
+
- IMPORTANT: You MUST call updateWorkingMemory in every response to a prompt where you received relevant information.
|
|
459
|
+
- IMPORTANT: Preserve the Markdown formatting structure above while updating the content.`;
|
|
464
460
|
}
|
|
465
461
|
|
|
466
462
|
public getTools(config?: MemoryConfig): Record<string, CoreTool> {
|
|
@@ -3,11 +3,13 @@ import { createTool } from '@mastra/core';
|
|
|
3
3
|
import type { CoreMessage, MessageType } from '@mastra/core';
|
|
4
4
|
import { Agent } from '@mastra/core/agent';
|
|
5
5
|
import cl100k_base from 'js-tiktoken/ranks/cl100k_base';
|
|
6
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
import { generateConversationHistory } from '../../integration-tests/src/test-utils';
|
|
9
9
|
import { TokenLimiter, ToolCallFilter } from './index';
|
|
10
10
|
|
|
11
|
+
vi.setConfig({ testTimeout: 20_000, hookTimeout: 20_000 });
|
|
12
|
+
|
|
11
13
|
describe('TokenLimiter', () => {
|
|
12
14
|
it('should limit messages to the specified token count', () => {
|
|
13
15
|
// Create messages with predictable token counts (approximately 25 tokens each)
|
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
export const updateWorkingMemoryTool: CoreTool = {
|
|
5
5
|
description: 'Update the working memory with new information',
|
|
6
6
|
parameters: z.object({
|
|
7
|
-
memory: z.string().describe('The
|
|
7
|
+
memory: z.string().describe('The Markdown-formatted working memory content to store'),
|
|
8
8
|
}),
|
|
9
9
|
execute: async (params: any) => {
|
|
10
10
|
const { context, threadId, memory } = params;
|