Skip to content

Commit 9b8fc1c

Browse files
committed
Fix mastra shared memory breaking when using libsql backend
1 parent e060e31 commit 9b8fc1c

File tree

1 file changed

+19
-16
lines changed
  • typescript-sdk/apps/dojo/src/mastra

1 file changed

+19
-16
lines changed

typescript-sdk/apps/dojo/src/mastra/index.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,41 @@ import { createTool } from "@mastra/core";
99
import { z } from "zod";
1010

1111

12-
let storage: LibSQLStore | DynamoDBStore
1312

14-
if (process.env.DYNAMODB_TABLE_NAME) {
15-
storage = new DynamoDBStore({
16-
name: "dynamodb",
17-
config: {
18-
tableName: process.env.DYNAMODB_TABLE_NAME
19-
},
20-
});
21-
} else {
22-
storage = new LibSQLStore({ url: "file::memory:" });
13+
function getStorage(): LibSQLStore | DynamoDBStore {
14+
if (process.env.DYNAMODB_TABLE_NAME) {
15+
return new DynamoDBStore({
16+
name: "dynamodb",
17+
config: {
18+
tableName: process.env.DYNAMODB_TABLE_NAME
19+
},
20+
});
21+
} else {
22+
return new LibSQLStore({ url: "file::memory:" });
23+
}
2324
}
2425

26+
27+
2528
export const mastra = new Mastra({
2629
agents: {
2730
agentic_chat: new Agent({
2831
name: "agentic_chat",
2932
instructions: `
3033
You are a helpful weather assistant that provides accurate weather information.
31-
34+
3235
Your primary function is to help users get weather details for specific locations. When responding:
3336
- Always ask for a location if none is provided
3437
- If the location name isn’t in English, please translate it
3538
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
3639
- Include relevant details like humidity, wind conditions, and precipitation
3740
- Keep responses concise but informative
38-
41+
3942
Use the weatherTool to fetch current weather data.
4043
`,
4144
model: openai("gpt-4o"),
4245
memory: new Memory({
43-
storage: storage,
46+
storage: getStorage(),
4447
options: {
4548
workingMemory: {
4649
enabled: true,
@@ -54,7 +57,7 @@ export const mastra = new Mastra({
5457
shared_state: new Agent({
5558
name: "shared_state",
5659
instructions: `
57-
You are a helpful assistant for creating recipes.
60+
You are a helpful assistant for creating recipes.
5861
5962
IMPORTANT:
6063
1. Create a recipe using the existing ingredients and instructions. Make sure the recipe is complete.
@@ -63,11 +66,11 @@ export const mastra = new Mastra({
6366
4. 'ingredients' is always an array of objects with 'icon', 'name', and 'amount' fields
6467
5. 'instructions' is always an array of strings
6568
66-
If you have just created or modified the recipe, just answer in one sentence what you did. dont describe the recipe, just say what you did.
69+
If you have just created or modified the recipe, just answer in one sentence what you did. dont describe the recipe, just say what you did. Do not mention "working memory", "memory", or "state" in your answer.
6770
`,
6871
model: openai("gpt-4o"),
6972
memory: new Memory({
70-
storage: storage,
73+
storage: getStorage(),
7174
options: {
7275
workingMemory: {
7376
enabled: true,

0 commit comments

Comments
 (0)