@mastra/mcp-docs-server 0.13.5-alpha.0 → 0.13.6

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 (93) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +76 -76
  2. package/.docs/organized/changelogs/%40mastra%2Fagui.md +61 -61
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +54 -54
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +211 -211
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +75 -75
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +91 -91
  7. package/.docs/organized/changelogs/%40mastra%2Fcore.md +185 -185
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +237 -237
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +143 -143
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +143 -143
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +235 -235
  12. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +84 -84
  13. package/.docs/organized/changelogs/%40mastra%2Fevals.md +56 -56
  14. package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
  15. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +75 -75
  16. package/.docs/organized/changelogs/%40mastra%2Flance.md +55 -0
  17. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +56 -56
  18. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +25 -25
  19. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +38 -38
  20. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +119 -119
  21. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +58 -58
  22. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +69 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fpg.md +119 -119
  24. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +244 -244
  25. package/.docs/organized/changelogs/%40mastra%2Frag.md +73 -73
  26. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +24 -0
  27. package/.docs/organized/changelogs/%40mastra%2Fserver.md +211 -211
  28. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +76 -76
  29. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +44 -44
  30. package/.docs/organized/changelogs/create-mastra.md +126 -126
  31. package/.docs/organized/changelogs/mastra.md +256 -256
  32. package/.docs/organized/code-examples/agent.md +6 -0
  33. package/.docs/organized/code-examples/agui.md +3 -3
  34. package/.docs/organized/code-examples/ai-sdk-useChat.md +2 -2
  35. package/.docs/organized/code-examples/ai-sdk-v5.md +201 -0
  36. package/.docs/organized/code-examples/assistant-ui.md +2 -2
  37. package/.docs/organized/code-examples/bird-checker-with-nextjs-and-eval.md +2 -2
  38. package/.docs/organized/code-examples/bird-checker-with-nextjs.md +2 -2
  39. package/.docs/organized/code-examples/client-side-tools.md +1 -1
  40. package/.docs/organized/code-examples/crypto-chatbot.md +5 -5
  41. package/.docs/organized/code-examples/openapi-spec-writer.md +2 -2
  42. package/.docs/organized/code-examples/workflow-with-suspend-resume.md +181 -0
  43. package/.docs/raw/agents/agent-memory.mdx +126 -0
  44. package/.docs/raw/agents/dynamic-agents.mdx +34 -2
  45. package/.docs/raw/agents/overview.mdx +21 -33
  46. package/.docs/raw/community/licensing.mdx +27 -19
  47. package/.docs/raw/deployment/cloud-providers/amazon-ec2.mdx +60 -26
  48. package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
  49. package/.docs/raw/deployment/cloud-providers/index.mdx +44 -9
  50. package/.docs/raw/deployment/server-deployment.mdx +56 -0
  51. package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +9 -30
  52. package/.docs/raw/deployment/serverless-platforms/index.mdx +13 -13
  53. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +291 -216
  54. package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +0 -34
  55. package/.docs/raw/frameworks/agentic-uis/copilotkit.mdx +162 -181
  56. package/.docs/raw/frameworks/servers/express.mdx +1 -1
  57. package/.docs/raw/frameworks/web-frameworks/astro.mdx +2 -2
  58. package/.docs/raw/frameworks/web-frameworks/next-js.mdx +1 -1
  59. package/.docs/raw/frameworks/web-frameworks/sveltekit.mdx +4 -4
  60. package/.docs/raw/frameworks/web-frameworks/vite-react.mdx +1 -1
  61. package/.docs/raw/getting-started/installation.mdx +10 -7
  62. package/.docs/raw/getting-started/model-capability.mdx +1 -1
  63. package/.docs/raw/memory/overview.mdx +8 -0
  64. package/.docs/raw/memory/semantic-recall.mdx +6 -0
  65. package/.docs/raw/observability/tracing.mdx +30 -0
  66. package/.docs/raw/rag/retrieval.mdx +24 -5
  67. package/.docs/raw/reference/agents/agent.mdx +2 -2
  68. package/.docs/raw/reference/cli/create-mastra.mdx +7 -0
  69. package/.docs/raw/reference/cli/dev.mdx +4 -3
  70. package/.docs/raw/reference/client-js/agents.mdx +8 -0
  71. package/.docs/raw/reference/memory/query.mdx +35 -14
  72. package/.docs/raw/reference/observability/providers/keywordsai.mdx +73 -0
  73. package/.docs/raw/reference/rag/rerankWithScorer.mdx +213 -0
  74. package/.docs/raw/reference/storage/mssql.mdx +108 -0
  75. package/.docs/raw/server-db/custom-api-routes.mdx +67 -0
  76. package/.docs/raw/server-db/production-server.mdx +66 -0
  77. package/.docs/raw/tools-mcp/mcp-overview.mdx +28 -7
  78. package/.docs/raw/workflows/control-flow.mdx +91 -93
  79. package/.docs/raw/workflows/input-data-mapping.mdx +31 -43
  80. package/.docs/raw/workflows/overview.mdx +22 -12
  81. package/.docs/raw/workflows/pausing-execution.mdx +49 -4
  82. package/.docs/raw/workflows/suspend-and-resume.mdx +17 -16
  83. package/.docs/raw/workflows/using-with-agents-and-tools.mdx +16 -13
  84. package/.docs/raw/workflows-legacy/overview.mdx +11 -0
  85. package/LICENSE.md +11 -42
  86. package/package.json +7 -9
  87. package/.docs/raw/deployment/custom-api-routes.mdx +0 -55
  88. package/.docs/raw/deployment/server.mdx +0 -116
  89. package/.docs/raw/frameworks/ai-sdk-v5.mdx +0 -91
  90. /package/.docs/raw/{local-dev/mastra-dev.mdx → server-db/local-dev-playground.mdx} +0 -0
  91. /package/.docs/raw/{client-js/overview.mdx → server-db/mastra-client.mdx} +0 -0
  92. /package/.docs/raw/{deployment → server-db}/middleware.mdx +0 -0
  93. /package/.docs/raw/{storage/overview.mdx → server-db/storage.mdx} +0 -0
@@ -0,0 +1,201 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "mastra-ai-sdk-v5-use-chat-example",
5
+ "dependencies": {
6
+ "@ai-sdk/openai": "2.0.0-beta.1",
7
+ "@ai-sdk/react": "2.0.0-beta.1",
8
+ "@mastra/core": "0.0.0-ai-v5-20250625173645",
9
+ "@mastra/libsql": "0.0.0-ai-v5-20250625173645",
10
+ "@mastra/loggers": "0.0.0-ai-v5-20250625173645",
11
+ "@mastra/memory": "0.0.0-ai-v5-20250625173645",
12
+ "@mastra/pg": "0.0.0-ai-v5-20250625173645",
13
+ "@mastra/rag": "0.0.0-ai-v5-20250625173645",
14
+ "@mastra/server": "0.0.0-ai-v5-20250625173645",
15
+ "next": "15.2.4",
16
+ "react": "^19.0.0",
17
+ "react-dom": "^19.0.0",
18
+ "swr": "^2.3.3",
19
+ "zod": "^3.25.67"
20
+ },
21
+ "devDependencies": {
22
+ "@eslint/eslintrc": "^3",
23
+ "@types/node": "^20",
24
+ "@types/react": "^19",
25
+ "@types/react-dom": "^19",
26
+ "eslint": "^9",
27
+ "eslint-config-next": "15.1.7",
28
+ "mastra": "0.0.0-ai-v5-20250625173645",
29
+ "postcss": "^8",
30
+ "tailwindcss": "^3.4.1",
31
+ "typescript": "^5"
32
+ }
33
+ }
34
+ ```
35
+
36
+ ### mastra/agents/index.ts
37
+ ```typescript
38
+ import { Agent } from "@mastra/core/agent";
39
+ import { openai } from "@ai-sdk/openai";
40
+
41
+ import { weatherTool } from "../tools";
42
+ import { Memory } from "@mastra/memory";
43
+ import { LibSQLStore } from "@mastra/libsql";
44
+
45
+ export const memory = new Memory({
46
+ storage: new LibSQLStore({
47
+ url: `file:./mastra.db`,
48
+ }),
49
+ options: {
50
+ semanticRecall: false,
51
+ workingMemory: {
52
+ enabled: false,
53
+ },
54
+ lastMessages: 5,
55
+ },
56
+ });
57
+
58
+ export const weatherAgent = new Agent({
59
+ name: "Weather Agent",
60
+ instructions: `
61
+ You are a helpful weather assistant that provides accurate weather information.
62
+
63
+ Your primary function is to help users get weather details for specific locations. When responding:
64
+ - Always ask for a location if none is provided
65
+ - If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
66
+ - Include relevant details like humidity, wind conditions, and precipitation
67
+ - Keep responses concise but informative
68
+
69
+ Use the weatherTool to fetch current weather data.
70
+
71
+ `,
72
+ model: openai("gpt-4o"),
73
+ tools: {
74
+ weatherTool,
75
+ },
76
+ memory,
77
+ });
78
+
79
+ ```
80
+
81
+ ### mastra/index.ts
82
+ ```typescript
83
+ import { ConsoleLogger } from "@mastra/core/logger";
84
+ import { Mastra } from "@mastra/core/mastra";
85
+
86
+ import { weatherAgent } from "./agents";
87
+
88
+ export const mastra = new Mastra({
89
+ agents: { weatherAgent },
90
+ logger: new ConsoleLogger(),
91
+ // aiSdkCompat: "v4",
92
+ });
93
+
94
+ ```
95
+
96
+ ### mastra/tools/index.ts
97
+ ```typescript
98
+ import { createTool } from "@mastra/core/tools";
99
+ import { z } from "zod";
100
+
101
+ interface GeocodingResponse {
102
+ results: {
103
+ latitude: number;
104
+ longitude: number;
105
+ name: string;
106
+ }[];
107
+ }
108
+ interface WeatherResponse {
109
+ current: {
110
+ time: string;
111
+ temperature_2m: number;
112
+ apparent_temperature: number;
113
+ relative_humidity_2m: number;
114
+ wind_speed_10m: number;
115
+ wind_gusts_10m: number;
116
+ weather_code: number;
117
+ };
118
+ }
119
+
120
+ export const weatherTool = createTool({
121
+ id: "get-weather",
122
+ description: "Get current weather for a location",
123
+ inputSchema: z.object({
124
+ location: z.string().describe("City name"),
125
+ }),
126
+ outputSchema: z.object({
127
+ temperature: z.number(),
128
+ feelsLike: z.number(),
129
+ humidity: z.number(),
130
+ windSpeed: z.number(),
131
+ windGust: z.number(),
132
+ conditions: z.string(),
133
+ location: z.string(),
134
+ }),
135
+ execute: async ({ context }) => {
136
+ return await getWeather(context.location);
137
+ },
138
+ });
139
+
140
+ const getWeather = async (location: string) => {
141
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
142
+ const geocodingResponse = await fetch(geocodingUrl);
143
+ const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
144
+
145
+ if (!geocodingData.results?.[0]) {
146
+ throw new Error(`Location '${location}' not found`);
147
+ }
148
+
149
+ const { latitude, longitude, name } = geocodingData.results[0];
150
+
151
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
152
+
153
+ const response = await fetch(weatherUrl);
154
+ const data = (await response.json()) as WeatherResponse;
155
+
156
+ return {
157
+ temperature: data.current.temperature_2m,
158
+ feelsLike: data.current.apparent_temperature,
159
+ humidity: data.current.relative_humidity_2m,
160
+ windSpeed: data.current.wind_speed_10m,
161
+ windGust: data.current.wind_gusts_10m,
162
+ conditions: getWeatherCondition(data.current.weather_code),
163
+ location: name,
164
+ };
165
+ };
166
+
167
+ function getWeatherCondition(code: number): string {
168
+ const conditions: Record<number, string> = {
169
+ 0: "Clear sky",
170
+ 1: "Mainly clear",
171
+ 2: "Partly cloudy",
172
+ 3: "Overcast",
173
+ 45: "Foggy",
174
+ 48: "Depositing rime fog",
175
+ 51: "Light drizzle",
176
+ 53: "Moderate drizzle",
177
+ 55: "Dense drizzle",
178
+ 56: "Light freezing drizzle",
179
+ 57: "Dense freezing drizzle",
180
+ 61: "Slight rain",
181
+ 63: "Moderate rain",
182
+ 65: "Heavy rain",
183
+ 66: "Light freezing rain",
184
+ 67: "Heavy freezing rain",
185
+ 71: "Slight snow fall",
186
+ 73: "Moderate snow fall",
187
+ 75: "Heavy snow fall",
188
+ 77: "Snow grains",
189
+ 80: "Slight rain showers",
190
+ 81: "Moderate rain showers",
191
+ 82: "Violent rain showers",
192
+ 85: "Slight snow showers",
193
+ 86: "Heavy snow showers",
194
+ 95: "Thunderstorm",
195
+ 96: "Thunderstorm with slight hail",
196
+ 99: "Thunderstorm with heavy hail",
197
+ };
198
+ return conditions[code] || "Unknown";
199
+ }
200
+
201
+ ```
@@ -18,8 +18,8 @@
18
18
  "@types/node": "^20.17.57",
19
19
  "@types/react": "^19.1.8",
20
20
  "@types/react-dom": "^19.1.6",
21
- "eslint": "^9.29.0",
22
- "eslint-config-next": "15.3.3",
21
+ "eslint": "^9.30.1",
22
+ "eslint-config-next": "15.3.5",
23
23
  "postcss": "^8.5.3",
24
24
  "tailwindcss": "^3.4.17",
25
25
  "typescript": "^5.8.2"
@@ -23,8 +23,8 @@
23
23
  "@types/node": "^20.17.57",
24
24
  "@types/react": "^18.3.23",
25
25
  "@types/react-dom": "^18.3.7",
26
- "eslint": "^9.29.0",
27
- "eslint-config-next": "15.3.3",
26
+ "eslint": "^9.30.1",
27
+ "eslint-config-next": "15.3.5",
28
28
  "postcss": "^8.5.3",
29
29
  "tailwindcss": "^3.4.17",
30
30
  "typescript": "^5.8.2"
@@ -23,8 +23,8 @@
23
23
  "@types/node": "^20.17.57",
24
24
  "@types/react": "^19.1.8",
25
25
  "@types/react-dom": "^19.1.6",
26
- "eslint": "^9.29.0",
27
- "eslint-config-next": "15.3.3",
26
+ "eslint": "^9.30.1",
27
+ "eslint-config-next": "15.3.5",
28
28
  "postcss": "^8.5.3",
29
29
  "tailwindcss": "^3.4.17",
30
30
  "typescript": "^5.8.2"
@@ -15,7 +15,7 @@
15
15
  "@types/react": "^19.1.8",
16
16
  "@types/react-dom": "^19.1.6",
17
17
  "@vitejs/plugin-react": "^4.3.4",
18
- "eslint": "^9.29.0",
18
+ "eslint": "^9.30.1",
19
19
  "eslint-plugin-react-hooks": "^5.2.0",
20
20
  "eslint-plugin-react-refresh": "^0.4.20",
21
21
  "globals": "^15.15.0",
@@ -71,14 +71,14 @@
71
71
  "@types/react": "^19.1.8",
72
72
  "@types/react-dom": "^19.1.6",
73
73
  "drizzle-kit": "^0.31.0",
74
- "eslint": "^9.29.0",
75
- "eslint-config-next": "15.3.3",
74
+ "eslint": "^9.30.1",
75
+ "eslint-config-next": "15.3.5",
76
76
  "eslint-config-prettier": "^10.1.5",
77
- "eslint-import-resolver-typescript": "^4.4.3",
78
- "eslint-plugin-import": "^2.31.0",
77
+ "eslint-import-resolver-typescript": "^4.4.4",
78
+ "eslint-plugin-import": "^2.32.0",
79
79
  "eslint-plugin-tailwindcss": "^3.18.0",
80
80
  "postcss": "^8.5.3",
81
- "prettier": "^3.5.3",
81
+ "prettier": "^3.6.2",
82
82
  "tailwindcss": "^3.4.17",
83
83
  "tsx": "^4.19.3",
84
84
  "typescript": "^5.8.3"
@@ -33,8 +33,8 @@
33
33
  "@types/react": "^19.1.8",
34
34
  "@types/react-dom": "^19.1.6",
35
35
  "@types/react-syntax-highlighter": "^15.5.13",
36
- "eslint": "^9.29.0",
37
- "eslint-config-next": "15.3.3",
36
+ "eslint": "^9.30.1",
37
+ "eslint-config-next": "15.3.5",
38
38
  "postcss": "^8.5.3",
39
39
  "tailwindcss": "^3.4.17",
40
40
  "typescript": "^5.8.2"
@@ -0,0 +1,181 @@
1
+ ### package.json
2
+ ```json
3
+ {
4
+ "name": "examples-workflow-with-suspend-resume",
5
+ "devDependencies": {
6
+ "@types/node": "^20.17.57",
7
+ "mastra": "latest",
8
+ "tsx": "^4.19.3",
9
+ "typescript": "^5.8.2",
10
+ "zod": "^3.25.67"
11
+ },
12
+ "dependencies": {
13
+ "@mastra/core": "latest",
14
+ "@mastra/libsql": "latest"
15
+ }
16
+ }
17
+ ```
18
+
19
+ ### index.ts
20
+ ```typescript
21
+ import { mastra } from './mastra';
22
+
23
+ async function main() {
24
+ console.log('🚀 Starting workflow with suspend/resume example...\n');
25
+
26
+ const myWorkflow = mastra.getWorkflow('myWorkflow');
27
+ const run = await myWorkflow.createRunAsync();
28
+
29
+ try {
30
+ // Start the workflow - it will suspend at stepTwo
31
+ console.log('📝 Starting workflow with inputValue: 30');
32
+ const result = await run.start({
33
+ inputData: {
34
+ inputValue: 30,
35
+ },
36
+ });
37
+
38
+ console.log('📊 Workflow result:', JSON.stringify(result, null, 2));
39
+
40
+ // Check if the workflow is suspended
41
+ if (result.status === 'suspended') {
42
+ console.log('\n⏸️ Workflow is suspended! Suspended steps:', result.suspended);
43
+
44
+ // Resume the workflow with additional data
45
+ console.log('▶️ Resuming workflow with extraNumber: 5');
46
+ const resumedResult = await run.resume({
47
+ step: result.suspended[0], // Resume the first suspended step
48
+ resumeData: {
49
+ extraNumber: 5,
50
+ },
51
+ });
52
+
53
+ console.log('✅ Resumed workflow result:', JSON.stringify(resumedResult, null, 2));
54
+ } else {
55
+ console.log('✅ Workflow completed without suspension');
56
+ }
57
+ } catch (e) {
58
+ console.error('❌ Error:', e);
59
+ }
60
+ }
61
+
62
+ main();
63
+
64
+ ```
65
+
66
+ ### mastra/index.ts
67
+ ```typescript
68
+ import { Mastra } from '@mastra/core';
69
+ import { LibSQLStore } from '@mastra/libsql';
70
+
71
+ import { myWorkflow } from './workflows';
72
+
73
+ export const mastra = new Mastra({
74
+ workflows: {
75
+ myWorkflow,
76
+ },
77
+ storage: new LibSQLStore({
78
+ url: 'file:./workflow-snapshots.db',
79
+ }),
80
+ });
81
+
82
+ ```
83
+
84
+ ### mastra/workflows/index.ts
85
+ ```typescript
86
+ import { createStep, createWorkflow } from '@mastra/core/workflows';
87
+ import { z } from 'zod';
88
+
89
+ const stepOne = createStep({
90
+ id: 'stepOne',
91
+ inputSchema: z.object({
92
+ inputValue: z.number(),
93
+ }),
94
+ outputSchema: z.object({
95
+ doubledValue: z.number(),
96
+ }),
97
+ execute: async ({ inputData }) => {
98
+ const doubledValue = inputData.inputValue * 2;
99
+ return { doubledValue };
100
+ },
101
+ });
102
+
103
+ const stepTwo = createStep({
104
+ id: 'stepTwo',
105
+ inputSchema: z.object({
106
+ doubledValue: z.number(),
107
+ }),
108
+ outputSchema: z.object({
109
+ incrementedValue: z.number(),
110
+ }),
111
+ suspendSchema: z.object({}),
112
+ resumeSchema: z.object({
113
+ extraNumber: z.number(),
114
+ }),
115
+ execute: async ({ inputData, resumeData, suspend }) => {
116
+ if (!resumeData?.extraNumber) {
117
+ await suspend({});
118
+ return { incrementedValue: 0 };
119
+ }
120
+ const incrementedValue = inputData.doubledValue + 1 + resumeData.extraNumber;
121
+ return { incrementedValue };
122
+ },
123
+ });
124
+
125
+ const stepThree = createStep({
126
+ id: 'stepThree',
127
+ inputSchema: z.object({
128
+ incrementedValue: z.number(),
129
+ }),
130
+ outputSchema: z.object({
131
+ tripledValue: z.number(),
132
+ }),
133
+ execute: async ({ inputData }) => {
134
+ const tripledValue = inputData.incrementedValue * 3;
135
+ return { tripledValue };
136
+ },
137
+ });
138
+
139
+ const stepFour = createStep({
140
+ id: 'stepFour',
141
+ inputSchema: z.object({
142
+ tripledValue: z.number(),
143
+ }),
144
+ outputSchema: z.object({
145
+ isEven: z.boolean(),
146
+ }),
147
+ execute: async ({ inputData }) => {
148
+ const isEven = inputData.tripledValue % 2 === 0;
149
+ return { isEven };
150
+ },
151
+ });
152
+
153
+ // Create a nested workflow
154
+ export const nestedWorkflow = createWorkflow({
155
+ id: 'data-processing',
156
+ inputSchema: z.object({
157
+ inputValue: z.number(),
158
+ }),
159
+ outputSchema: z.object({
160
+ isEven: z.boolean(),
161
+ }),
162
+ })
163
+ .then(stepOne)
164
+ .then(stepTwo)
165
+ .then(stepThree)
166
+ .then(stepFour)
167
+ .commit();
168
+
169
+ export const myWorkflow = createWorkflow({
170
+ id: 'my-workflow',
171
+ inputSchema: z.object({
172
+ inputValue: z.number(),
173
+ }),
174
+ outputSchema: z.object({
175
+ isEven: z.boolean(),
176
+ }),
177
+ })
178
+ .then(nestedWorkflow)
179
+ .commit();
180
+
181
+ ```
@@ -37,6 +37,132 @@ const agent = new Agent({
37
37
 
38
38
  This basic setup uses the default settings. Visit the [Memory documentation](/docs/memory/overview) for more configuration info.
39
39
 
40
+ ## Dynamic Memory Configuration
41
+
42
+ Similar to how you can configure dynamic [instructions, models, and tools](./dynamic-agents.mdx), you can also configure memory dynamically using runtime context. This allows you to:
43
+
44
+ - Use different memory systems based on user tiers or preferences
45
+ - Switch between memory configurations for different environments
46
+ - Enable or disable memory features based on feature flags
47
+ - Customize memory behavior based on user context
48
+
49
+ ### Example: User Tier-Based Memory
50
+
51
+ ```typescript
52
+ import { Agent } from "@mastra/core/agent";
53
+ import { Memory } from "@mastra/memory";
54
+ import { LibSQLStore } from "@mastra/libsql";
55
+ import { PostgresStore } from "@mastra/pg";
56
+ import { openai } from "@ai-sdk/openai";
57
+
58
+ // Create different memory instances for different user tiers
59
+ const premiumMemory = new Memory({
60
+ storage: new LibSQLStore({ url: "file:premium.db" }),
61
+ options: {
62
+ semanticRecall: { topK: 10, messageRange: 5 }, // More context for premium users
63
+ workingMemory: { enabled: true },
64
+ },
65
+ });
66
+
67
+ const standardMemory = new Memory({
68
+ storage: new LibSQLStore({ url: "file:standard.db" }),
69
+ options: {
70
+ semanticRecall: { topK: 3, messageRange: 2 }, // Basic recall for standard users
71
+ workingMemory: { enabled: false },
72
+ },
73
+ });
74
+
75
+ const agent = new Agent({
76
+ name: "TieredMemoryAgent",
77
+ instructions: "You are a helpful assistant with tiered memory capabilities.",
78
+ model: openai("gpt-4o"),
79
+ memory: ({ runtimeContext }) => {
80
+ const userTier = runtimeContext.get("userTier");
81
+ return userTier === "premium" ? premiumMemory : standardMemory;
82
+ },
83
+ });
84
+ ```
85
+
86
+ ### Example: Environment-Based Memory
87
+
88
+ ```typescript
89
+ const agent = new Agent({
90
+ name: "EnvironmentAwareAgent",
91
+ instructions: "You are a helpful assistant.",
92
+ model: openai("gpt-4o"),
93
+ memory: ({ runtimeContext }) => {
94
+ const environment = runtimeContext.get("environment");
95
+
96
+ if (environment === "test") {
97
+ // Use local storage for testing
98
+ return new Memory({
99
+ storage: new LibSQLStore({ url: ":memory:" }),
100
+ options: {
101
+ workingMemory: { enabled: true },
102
+ },
103
+ });
104
+ } else if (environment === "production") {
105
+ // Use production database
106
+ return new Memory({
107
+ storage: new PostgresStore({ connectionString: process.env.PRODUCTION_DB_URL }),
108
+ options: {
109
+ workingMemory: { enabled: true },
110
+ },
111
+ });
112
+ }
113
+
114
+ // Development environment
115
+ return new Memory({
116
+ storage: new LibSQLStore({ url: "file:dev.db" }),
117
+ });
118
+ },
119
+ });
120
+ ```
121
+
122
+ ### Example: Async Memory Configuration
123
+
124
+ ```typescript
125
+ const agent = new Agent({
126
+ name: "AsyncMemoryAgent",
127
+ instructions: "You are a helpful assistant.",
128
+ model: openai("gpt-4o"),
129
+ memory: async ({ runtimeContext }) => {
130
+ const userId = runtimeContext.get("userId");
131
+
132
+ // Simulate async memory setup (e.g., database lookup)
133
+ await new Promise(resolve => setTimeout(resolve, 10));
134
+
135
+ return new Memory({
136
+ storage: new LibSQLStore({
137
+ url: `file:user_${userId}.db`
138
+ }),
139
+ });
140
+ },
141
+ });
142
+ ```
143
+
144
+ ### Using Dynamic Memory
145
+
146
+ When using dynamic memory, pass the runtime context to your agent calls:
147
+
148
+ ```typescript
149
+ import { RuntimeContext } from "@mastra/core/runtime-context";
150
+
151
+ // Create runtime context with user information
152
+ const runtimeContext = new RuntimeContext();
153
+ runtimeContext.set("userTier", "premium");
154
+ runtimeContext.set("environment", "production");
155
+
156
+ // Use the agent with runtime context
157
+ const response = await agent.generate("Remember my favorite color is blue.", {
158
+ memory: {
159
+ resource: "user_alice",
160
+ thread: { id: "preferences_thread" },
161
+ },
162
+ runtimeContext, // Pass the runtime context
163
+ });
164
+ ```
165
+
40
166
  ## Using Memory in Agent Calls
41
167
 
42
168
  To utilize memory during interactions, you **must** provide `resourceId` and `threadId` when calling the agent's `stream()` or `generate()` methods.
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  title: "Dynamic Agents"
3
- description: Dynamically configure your agent's instruction, model and tools using runtime context.
3
+ description: Dynamically configure your agent's instruction, model, tools, and memory using runtime context.
4
4
  ---
5
5
 
6
6
  # Dynamic Agents
7
7
 
8
8
  Dynamic agents use [runtime context](./runtime-variables), like user IDs and other important parameters, to adjust their settings in real-time.
9
9
 
10
- This means they can change the model they use, update their instructions, and select different tools as needed.
10
+ This means they can change the model they use, update their instructions, select different tools, and configure memory as needed.
11
11
 
12
12
  By using this context, agents can better respond to each user's needs. They can also call any API to gather more information, which helps improve what the agents can do.
13
13
 
@@ -55,6 +55,37 @@ const supportAgent = new Agent({
55
55
 
56
56
  return baseTools;
57
57
  },
58
+
59
+ memory: ({ runtimeContext }) => {
60
+ const userTier = runtimeContext.get("user-tier");
61
+
62
+ if (userTier === "enterprise") {
63
+ return new Memory({
64
+ storage: new LibSQLStore({ url: "file:enterprise.db" }),
65
+ options: {
66
+ semanticRecall: { topK: 15, messageRange: 8 },
67
+ workingMemory: { enabled: true },
68
+ },
69
+ });
70
+ } else if (userTier === "pro") {
71
+ return new Memory({
72
+ storage: new LibSQLStore({ url: "file:pro.db" }),
73
+ options: {
74
+ semanticRecall: { topK: 8, messageRange: 4 },
75
+ workingMemory: { enabled: true },
76
+ },
77
+ });
78
+ }
79
+
80
+ // Basic memory for free tier
81
+ return new Memory({
82
+ storage: new LibSQLStore({ url: "file:free.db" }),
83
+ options: {
84
+ semanticRecall: { topK: 3, messageRange: 2 },
85
+ workingMemory: { enabled: false },
86
+ },
87
+ });
88
+ },
58
89
  });
59
90
  ```
60
91
 
@@ -63,6 +94,7 @@ In this example, the agent:
63
94
  - Adjusts its instructions based on the user's subscription tier (free, pro, or enterprise)
64
95
  - Uses a more powerful model (GPT-4) for enterprise users
65
96
  - Provides different sets of tools based on the user's tier
97
+ - Configures memory with different capabilities based on the user's tier
66
98
  - Responds in the user's preferred language
67
99
 
68
100
  This demonstrates how a single agent can handle different types of users and scenarios by leveraging runtime context, making it more flexible and maintainable than creating separate agents for each use case.