@mastra/mcp-docs-server 0.13.1-alpha.0 → 0.13.1-alpha.2
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/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +54 -54
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +63 -63
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +40 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +12 -12
- package/.docs/organized/changelogs/create-mastra.md +15 -15
- package/.docs/organized/changelogs/mastra.md +86 -86
- package/.docs/organized/code-examples/agent.md +1 -1
- package/.docs/organized/code-examples/agui.md +4 -1
- package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
- package/.docs/organized/code-examples/fireworks-r1.md +1 -1
- package/.docs/organized/code-examples/memory-with-processors.md +2 -2
- package/.docs/organized/code-examples/openapi-spec-writer.md +1 -1
- package/.docs/organized/code-examples/quick-start.md +1 -1
- package/.docs/organized/code-examples/weather-agent.md +7 -1
- package/.docs/raw/course/01-first-agent/03-verifying-installation.md +4 -2
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/15-updating-mcp-config-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/20-updating-mcp-config-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/26-updating-mcp-config-filesystem.md +1 -1
- package/.docs/raw/course/03-agent-memory/03-installing-memory.md +4 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -1
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +3 -3
- package/.docs/raw/course/03-agent-memory/13-vector-store-configuration.md +27 -0
- package/.docs/raw/course/03-agent-memory/{13-what-is-semantic-recall.md → 14-what-is-semantic-recall.md} +1 -1
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +41 -0
- package/.docs/raw/course/03-agent-memory/18-advanced-configuration-semantic-recall.md +28 -0
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +9 -9
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +10 -2
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +8 -1
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +8 -1
- package/.docs/raw/deployment/deployment.mdx +26 -97
- package/.docs/raw/deployment/overview.mdx +18 -3
- package/.docs/raw/deployment/web-framework.mdx +63 -0
- package/.docs/raw/frameworks/web-frameworks/astro.mdx +7 -1
- package/.docs/raw/frameworks/web-frameworks/next-js.mdx +1 -1
- package/.docs/raw/getting-started/installation.mdx +98 -558
- package/.docs/raw/getting-started/project-structure.mdx +3 -16
- package/.docs/raw/rag/vector-databases.mdx +4 -7
- package/.docs/raw/reference/agents/generate.mdx +35 -3
- package/.docs/raw/reference/agents/stream.mdx +35 -3
- package/.docs/raw/reference/client-js/memory.mdx +14 -0
- package/.docs/raw/reference/client-js/workflows.mdx +28 -0
- package/.docs/raw/reference/deployer/cloudflare.mdx +9 -3
- package/.docs/raw/reference/deployer/deployer.mdx +1 -1
- package/.docs/raw/reference/deployer/netlify.mdx +25 -4
- package/.docs/raw/reference/deployer/vercel.mdx +10 -4
- package/.docs/raw/workflows/control-flow.mdx +45 -171
- package/.docs/raw/workflows/input-data-mapping.mdx +21 -88
- package/.docs/raw/workflows/overview.mdx +23 -46
- package/.docs/raw/workflows/suspend-and-resume.mdx +46 -34
- package/.docs/raw/workflows/using-with-agents-and-tools.mdx +55 -191
- package/dist/_tsup-dts-rollup.d.ts +14 -0
- package/dist/{chunk-QWIXFGFR.js → chunk-P5AHYMUI.js} +126 -20
- package/dist/prepare-docs/prepare.js +1 -1
- package/dist/stdio.js +42 -12
- package/package.json +3 -3
- package/.docs/raw/course/03-agent-memory/15-configuring-semantic-recall.md +0 -46
- package/.docs/raw/course/03-agent-memory/16-vector-store-configuration.md +0 -37
- package/.docs/raw/course/03-agent-memory/18-disabling-semantic-recall.md +0 -24
- /package/.docs/raw/{deployment/client.mdx → client-js/overview.mdx} +0 -0
- /package/.docs/raw/course/03-agent-memory/{14-how-semantic-recall-works.md → 15-how-semantic-recall-works.md} +0 -0
|
@@ -14,27 +14,16 @@ When you build a workflow, you typically break down operations into smaller task
|
|
|
14
14
|
|
|
15
15
|
Chain steps to execute in sequence using `.then()`:
|
|
16
16
|
|
|
17
|
-
```typescript {
|
|
17
|
+
```typescript {8-9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
18
18
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
19
19
|
import { z } from "zod";
|
|
20
20
|
|
|
21
21
|
const step1 = createStep({...});
|
|
22
22
|
const step2 = createStep({...});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export const testWorkflow = createWorkflow({
|
|
26
|
-
id: "test-workflow",
|
|
27
|
-
description: 'Test workflow',
|
|
28
|
-
inputSchema: z.object({
|
|
29
|
-
number: z.number()
|
|
30
|
-
}),
|
|
31
|
-
outputSchema: z.object({
|
|
32
|
-
number: z.number()
|
|
33
|
-
})
|
|
34
|
-
})
|
|
23
|
+
|
|
24
|
+
export const testWorkflow = createWorkflow({...})
|
|
35
25
|
.then(step1)
|
|
36
26
|
.then(step2)
|
|
37
|
-
.then(step3)
|
|
38
27
|
.commit();
|
|
39
28
|
```
|
|
40
29
|
|
|
@@ -42,55 +31,34 @@ export const testWorkflow = createWorkflow({
|
|
|
42
31
|
|
|
43
32
|
Execute steps in parallel using `.parallel()`:
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
```typescript {18} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
34
|
+
```typescript {8} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
47
35
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
48
36
|
import { z } from "zod";
|
|
49
37
|
|
|
50
38
|
const step1 = createStep({...});
|
|
51
39
|
const step2 = createStep({...});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export const testWorkflow = createWorkflow({
|
|
55
|
-
id: "test-workflow",
|
|
56
|
-
description: 'Test workflow',
|
|
57
|
-
inputSchema: z.object({
|
|
58
|
-
number: z.number()
|
|
59
|
-
}),
|
|
60
|
-
outputSchema: z.object({
|
|
61
|
-
number: z.number()
|
|
62
|
-
})
|
|
63
|
-
})
|
|
40
|
+
|
|
41
|
+
export const testWorkflow = createWorkflow({...})
|
|
64
42
|
.parallel([step1, step2])
|
|
65
|
-
.then(step3)
|
|
66
43
|
.commit();
|
|
67
44
|
```
|
|
68
45
|
|
|
69
46
|
This executes all steps in the array concurrently, then continues to the next step after all parallel steps complete.
|
|
70
47
|
|
|
48
|
+
> See [Parallel Execution with Steps](/examples/workflows/parallel-steps) for more information.
|
|
49
|
+
|
|
71
50
|
## Branch
|
|
72
51
|
|
|
73
52
|
Create conditional branches using `.branch()`:
|
|
74
53
|
|
|
75
|
-
```typescript {
|
|
54
|
+
```typescript {8-11} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
76
55
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
77
56
|
import { z } from "zod";
|
|
78
57
|
|
|
79
|
-
const step1 = createStep({...});
|
|
80
58
|
const lessThanStep = createStep({...});
|
|
81
59
|
const greaterThanStep = createStep({...});
|
|
82
60
|
|
|
83
|
-
export const testWorkflow = createWorkflow({
|
|
84
|
-
id: "test-workflow",
|
|
85
|
-
description: 'Test workflow',
|
|
86
|
-
inputSchema: z.object({
|
|
87
|
-
number: z.number()
|
|
88
|
-
}),
|
|
89
|
-
outputSchema: z.object({
|
|
90
|
-
number: z.number()
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
.then(step1)
|
|
61
|
+
export const testWorkflow = createWorkflow({...})
|
|
94
62
|
.branch([
|
|
95
63
|
[async ({ inputData: { some_value } }) => some_value <= 9, lessThanStep],
|
|
96
64
|
[async ({ inputData: { some_value } }) => some_value >= 10, greaterThanStep]
|
|
@@ -100,6 +68,8 @@ export const testWorkflow = createWorkflow({
|
|
|
100
68
|
|
|
101
69
|
Branch conditions are evaluated sequentially, but steps with matching conditions are executed in parallel.
|
|
102
70
|
|
|
71
|
+
> See [Workflow with Conditional Branching](/examples/workflows/conditional-branching) for more information.
|
|
72
|
+
|
|
103
73
|
## Loops
|
|
104
74
|
|
|
105
75
|
Workflows support two types of loops. When looping a step, or any step-compatible construct like a nested workflow, the initial `inputData` is sourced from the output of the previous step.
|
|
@@ -114,27 +84,14 @@ To ensure compatibility, the loop’s initial input must either:
|
|
|
114
84
|
|
|
115
85
|
Executes a step repeatedly while a condition is true.
|
|
116
86
|
|
|
117
|
-
```typescript {
|
|
87
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
118
88
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
119
89
|
import { z } from "zod";
|
|
120
90
|
|
|
121
|
-
const step1 = createStep({...});
|
|
122
91
|
const counterStep = createStep({...});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export const testWorkflow = createWorkflow({
|
|
126
|
-
id: "test-workflow",
|
|
127
|
-
description: 'Test workflow',
|
|
128
|
-
inputSchema: z.object({
|
|
129
|
-
number: z.number()
|
|
130
|
-
}),
|
|
131
|
-
outputSchema: z.object({
|
|
132
|
-
number: z.number()
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
.then(step1)
|
|
92
|
+
|
|
93
|
+
export const testWorkflow = createWorkflow({...})
|
|
136
94
|
.dowhile(counterStep, async ({ inputData: { number } }) => number < 10)
|
|
137
|
-
.then(finalStep)
|
|
138
95
|
.commit();
|
|
139
96
|
```
|
|
140
97
|
|
|
@@ -142,62 +99,29 @@ export const testWorkflow = createWorkflow({
|
|
|
142
99
|
|
|
143
100
|
Executes a step repeatedly until a condition becomes true.
|
|
144
101
|
|
|
145
|
-
```typescript {
|
|
102
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
146
103
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
147
104
|
import { z } from "zod";
|
|
148
105
|
|
|
149
|
-
const step1 = createStep({...});
|
|
150
106
|
const counterStep = createStep({...});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
export const testWorkflow = createWorkflow({
|
|
154
|
-
id: "test-workflow",
|
|
155
|
-
description: 'Test workflow',
|
|
156
|
-
inputSchema: z.object({
|
|
157
|
-
number: z.number()
|
|
158
|
-
}),
|
|
159
|
-
outputSchema: z.object({
|
|
160
|
-
number: z.number()
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
.then(step1)
|
|
107
|
+
|
|
108
|
+
export const testWorkflow = createWorkflow({...})
|
|
164
109
|
.dountil(counterStep, async ({ inputData: { number } }) => number > 10)
|
|
165
|
-
.then(finalStep)
|
|
166
110
|
.commit();
|
|
167
111
|
```
|
|
168
112
|
|
|
169
113
|
|
|
170
114
|
### Foreach
|
|
171
115
|
|
|
172
|
-
Sequentially executes the same step for each item
|
|
173
|
-
|
|
174
|
-
```typescript {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
description: "Adds 100 on the input number",
|
|
178
|
-
inputSchema: z.object({
|
|
179
|
-
number: z.number()
|
|
180
|
-
}),
|
|
181
|
-
outputSchema: z.object({
|
|
182
|
-
number: z.number()
|
|
183
|
-
}),
|
|
184
|
-
execute: async ({ inputData }) => {
|
|
185
|
-
const { number } = inputData;
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
number: number + 100
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
});
|
|
116
|
+
Sequentially executes the same step for each item from the `inputSchema`.
|
|
117
|
+
|
|
118
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
119
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
120
|
+
import { z } from "zod";
|
|
192
121
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
inputSchema: z.array(z.object({ number: z.number() })),
|
|
197
|
-
outputSchema: z.object({
|
|
198
|
-
number: z.number()
|
|
199
|
-
})
|
|
200
|
-
})
|
|
122
|
+
const mapStep = createStep({...});
|
|
123
|
+
|
|
124
|
+
export const testWorkflow = createWorkflow({...})
|
|
201
125
|
.foreach(mapStep)
|
|
202
126
|
.commit();
|
|
203
127
|
```
|
|
@@ -226,17 +150,13 @@ npx tsx src/test-workflow.ts
|
|
|
226
150
|
|
|
227
151
|
Optionally, using `concurrency` allows you to execute steps in parallel with a limit on the number of concurrent executions.
|
|
228
152
|
|
|
229
|
-
```typescript {
|
|
153
|
+
```typescript {7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
154
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
155
|
+
import { z } from "zod";
|
|
156
|
+
|
|
230
157
|
const mapStep = createStep({...})
|
|
231
158
|
|
|
232
|
-
export const testWorkflow = createWorkflow({
|
|
233
|
-
id: "test-workflow",
|
|
234
|
-
description: 'Test workflow',
|
|
235
|
-
inputSchema: z.array(z.object({ number: z.number() })),
|
|
236
|
-
outputSchema: z.object({
|
|
237
|
-
number: z.number()
|
|
238
|
-
})
|
|
239
|
-
})
|
|
159
|
+
export const testWorkflow = createWorkflow({...})
|
|
240
160
|
.foreach(mapStep, { concurrency: 2 })
|
|
241
161
|
.commit();
|
|
242
162
|
```
|
|
@@ -245,26 +165,15 @@ export const testWorkflow = createWorkflow({
|
|
|
245
165
|
|
|
246
166
|
Workflows themselves can also be executed in parallel.
|
|
247
167
|
|
|
248
|
-
```typescript {4
|
|
168
|
+
```typescript {4-5,8} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
249
169
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
250
170
|
import { z } from "zod";
|
|
251
171
|
|
|
252
172
|
const workflow1 = createWorkflow({...});
|
|
253
173
|
const workflow2 = createWorkflow({...});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
export const testWorkflow = createWorkflow({
|
|
257
|
-
id: "test-workflow",
|
|
258
|
-
description: 'Test workflow',
|
|
259
|
-
inputSchema: z.object({
|
|
260
|
-
number: z.number()
|
|
261
|
-
}),
|
|
262
|
-
outputSchema: z.object({
|
|
263
|
-
number: z.number()
|
|
264
|
-
})
|
|
265
|
-
})
|
|
174
|
+
|
|
175
|
+
export const testWorkflow = createWorkflow({...})
|
|
266
176
|
.parallel([workflow1, workflow2])
|
|
267
|
-
.then(finalStep)
|
|
268
177
|
.commit();
|
|
269
178
|
```
|
|
270
179
|
|
|
@@ -275,35 +184,13 @@ Parallel steps receive previous step results as input. Their outputs are passed
|
|
|
275
184
|
In the example below, `nestedWorkflow` is used as a step within `testWorkflow`. The `testWorkflow` uses `step1` whilst the `nestedWorkflow` composes `step2` and `step3`
|
|
276
185
|
|
|
277
186
|
|
|
278
|
-
```typescript {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const step3 = createStep({...});
|
|
282
|
-
|
|
283
|
-
export const nestedWorkflow = createWorkflow({
|
|
284
|
-
id: "nested-workflow",
|
|
285
|
-
inputSchema: z.object({
|
|
286
|
-
number: z.number()
|
|
287
|
-
}),
|
|
288
|
-
outputSchema: z.object({
|
|
289
|
-
number: z.number()
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
.then(step2)
|
|
293
|
-
.then(step3)
|
|
294
|
-
.commit();
|
|
187
|
+
```typescript {4,7} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
188
|
+
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
189
|
+
import { z } from "zod";
|
|
295
190
|
|
|
296
|
-
export const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
inputSchema: z.object({
|
|
300
|
-
number: z.number()
|
|
301
|
-
}),
|
|
302
|
-
outputSchema: z.object({
|
|
303
|
-
number: z.number()
|
|
304
|
-
})
|
|
305
|
-
})
|
|
306
|
-
.then(step1)
|
|
191
|
+
export const nestedWorkflow = createWorkflow({...})
|
|
192
|
+
|
|
193
|
+
export const testWorkflow = createWorkflow({...})
|
|
307
194
|
.then(nestedWorkflow)
|
|
308
195
|
.commit();
|
|
309
196
|
```
|
|
@@ -315,28 +202,15 @@ When using `.branch()` or `.parallel()` to build more complex control flows, exe
|
|
|
315
202
|
|
|
316
203
|
In the example below, `clonedWorkflow` is a clone of `workflow1` and is used as a step within `testWorkflow`. The `clonedWorkflow` is run sequentially after `step1`.
|
|
317
204
|
|
|
318
|
-
```typescript {
|
|
319
|
-
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
205
|
+
```typescript {5,9} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
206
|
+
import { createWorkflow, createStep, cloneWorkflow } from "@mastra/core/workflows";
|
|
320
207
|
import { z } from "zod";
|
|
321
208
|
|
|
322
209
|
const step1 = createStep({...});
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
export const testWorkflow = createWorkflow({
|
|
328
|
-
id: "test-workflow",
|
|
329
|
-
description: 'Test workflow',
|
|
330
|
-
inputSchema: z.object({
|
|
331
|
-
number: z.number()
|
|
332
|
-
}),
|
|
333
|
-
outputSchema: z.object({
|
|
334
|
-
number: z.number()
|
|
335
|
-
})
|
|
336
|
-
})
|
|
210
|
+
const clonedWorkflow = cloneWorkflow(step1, { id: "cloned-workflow" });
|
|
211
|
+
|
|
212
|
+
export const testWorkflow = createWorkflow({...})
|
|
337
213
|
.then(step1)
|
|
338
214
|
.then(clonedWorkflow)
|
|
339
|
-
.then(finalStep)
|
|
340
215
|
.commit();
|
|
341
216
|
```
|
|
342
|
-
|
|
@@ -14,70 +14,30 @@ Input data mapping allows explicit mapping of values for the inputs of the next
|
|
|
14
14
|
|
|
15
15
|
## Map
|
|
16
16
|
|
|
17
|
-
In this example the `output` from `
|
|
17
|
+
In this example the `output` from `step1` is transformed to match the `inputSchema` required for the `step2`. The value from `step1` is available using the `inputData` parameter of the `.map` function.
|
|
18
18
|
|
|
19
|
-
```typescript {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
description: "Gets details about a city",
|
|
23
|
-
inputSchema: z.object({
|
|
24
|
-
city: z.string()
|
|
25
|
-
}),
|
|
26
|
-
outputSchema: z.object({
|
|
27
|
-
city_name: z.string(),
|
|
28
|
-
country_name: z.string(),
|
|
29
|
-
country_timezone: z.string()
|
|
30
|
-
}),
|
|
31
|
-
execute: async ({ inputData }) => {
|
|
32
|
-
const { city } = inputData;
|
|
33
|
-
const geocodingResponse = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}`);
|
|
34
|
-
const geocodingData = await geocodingResponse.json();
|
|
35
|
-
|
|
36
|
-
const { name, country, timezone } = geocodingData.results[0];
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
city_name: name,
|
|
40
|
-
country_name: country,
|
|
41
|
-
country_timezone: timezone
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const locationDetailsStep = createStep({
|
|
47
|
-
id: "location-step",
|
|
48
|
-
description: "Display location details",
|
|
49
|
-
inputSchema: z.object({
|
|
50
|
-
details: z.string()
|
|
51
|
-
}),
|
|
52
|
-
outputSchema: z.object({
|
|
53
|
-
outcome: z.string()
|
|
54
|
-
}),
|
|
55
|
-
execute: async ({ inputData }) => {
|
|
56
|
-
const { details } = inputData;
|
|
57
|
-
return {
|
|
58
|
-
outcome: details
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
19
|
+
```typescript {18} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
20
|
+
const step1 = createStep({...});
|
|
21
|
+
const step2 = createStep({...});
|
|
62
22
|
|
|
63
23
|
export const testWorkflow = createWorkflow({
|
|
64
24
|
id: "test-workflow",
|
|
65
25
|
description: 'Test workflow',
|
|
66
26
|
inputSchema: z.object({
|
|
67
|
-
|
|
27
|
+
input: z.number()
|
|
68
28
|
}),
|
|
69
29
|
outputSchema: z.object({
|
|
70
|
-
|
|
30
|
+
output: z.string()
|
|
71
31
|
})
|
|
72
32
|
})
|
|
73
|
-
.then(
|
|
33
|
+
.then(step1)
|
|
74
34
|
.map(({ inputData }) => {
|
|
75
|
-
const {
|
|
35
|
+
const { value } = inputData;
|
|
76
36
|
return {
|
|
77
|
-
|
|
37
|
+
output: `${value}`
|
|
78
38
|
};
|
|
79
39
|
})
|
|
80
|
-
.then(
|
|
40
|
+
.then(step2)
|
|
81
41
|
.commit();
|
|
82
42
|
```
|
|
83
43
|
|
|
@@ -87,7 +47,7 @@ Use `inputData` to access the full output of the previous step:
|
|
|
87
47
|
|
|
88
48
|
```typescript {2} showLineNumbers
|
|
89
49
|
.map(({ inputData }) => {
|
|
90
|
-
const {
|
|
50
|
+
const { value} = inputData;
|
|
91
51
|
...
|
|
92
52
|
})
|
|
93
53
|
```
|
|
@@ -97,62 +57,41 @@ Use `inputData` to access the full output of the previous step:
|
|
|
97
57
|
Use `getStepResult` to access the full output of a specific step by referencing the step's instance:
|
|
98
58
|
|
|
99
59
|
```typescript {3} showLineNumbers
|
|
100
|
-
.then(
|
|
60
|
+
.then(step1)
|
|
101
61
|
.map(({ getStepResult }) => {
|
|
102
|
-
console.log(getStepResult(
|
|
62
|
+
console.log(getStepResult(step1));
|
|
103
63
|
...
|
|
104
64
|
})
|
|
105
65
|
```
|
|
106
66
|
|
|
107
|
-
The above log would produce an output similar to the below:
|
|
108
|
-
|
|
109
|
-
```typescript showLineNumbers
|
|
110
|
-
{
|
|
111
|
-
city_name: 'London',
|
|
112
|
-
country_name: 'United Kingdom',
|
|
113
|
-
country_timezone: 'Europe/London'
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
67
|
### getInitData
|
|
118
68
|
|
|
119
69
|
Use `getInitData` to access the initial input data provided to the workflow:
|
|
120
70
|
|
|
121
71
|
```typescript {3} showLineNumbers
|
|
122
|
-
.then(
|
|
72
|
+
.then(step1)
|
|
123
73
|
.map(({ getInitData }) => {
|
|
124
74
|
console.log(getInitData());
|
|
125
75
|
...
|
|
126
76
|
})
|
|
127
77
|
```
|
|
128
78
|
|
|
129
|
-
The above log would produce an output similar to the below:
|
|
130
|
-
|
|
131
|
-
```typescript showLineNumbers
|
|
132
|
-
{ city: 'London' }
|
|
133
|
-
```
|
|
134
79
|
## Renaming Outputs
|
|
135
80
|
|
|
136
81
|
### Step Outputs
|
|
137
82
|
|
|
138
|
-
You can rename step outputs using the object syntax in `.map()`. In the example below, the `
|
|
83
|
+
You can rename step outputs using the object syntax in `.map()`. In the example below, the `value` output from `step1` is renamed to `details`:
|
|
139
84
|
|
|
140
85
|
```typescript {3} showLineNumbers
|
|
141
|
-
.then(
|
|
86
|
+
.then(step)
|
|
142
87
|
.map({
|
|
143
88
|
details: {
|
|
144
|
-
step:
|
|
145
|
-
path: "
|
|
89
|
+
step: step,
|
|
90
|
+
path: "value"
|
|
146
91
|
}
|
|
147
92
|
})
|
|
148
93
|
```
|
|
149
94
|
|
|
150
|
-
The output would be similar to the below:
|
|
151
|
-
|
|
152
|
-
```typescript showLineNumbers
|
|
153
|
-
{ details: 'London' }
|
|
154
|
-
```
|
|
155
|
-
|
|
156
95
|
### Workflow Outputs
|
|
157
96
|
|
|
158
97
|
You can rename workflow outputs by using **referential composition**. This involves passing the workflow instance as the `initData`.
|
|
@@ -162,10 +101,10 @@ export const testWorkflow = createWorkflow({
|
|
|
162
101
|
id: "test-workflow",
|
|
163
102
|
description: 'Test workflow',
|
|
164
103
|
inputSchema: z.object({
|
|
165
|
-
|
|
104
|
+
input: z.string()
|
|
166
105
|
}),
|
|
167
106
|
outputSchema: z.object({
|
|
168
|
-
|
|
107
|
+
output: z.string()
|
|
169
108
|
})
|
|
170
109
|
});
|
|
171
110
|
|
|
@@ -174,13 +113,7 @@ testWorkflow
|
|
|
174
113
|
.map({
|
|
175
114
|
details: {
|
|
176
115
|
initData: testWorkflow,
|
|
177
|
-
path: "
|
|
116
|
+
path: "value"
|
|
178
117
|
}
|
|
179
118
|
})
|
|
180
119
|
```
|
|
181
|
-
|
|
182
|
-
The output would be similar to the below:
|
|
183
|
-
|
|
184
|
-
```typescript showLineNumbers
|
|
185
|
-
{ details: 'London' }
|
|
186
|
-
```
|
|
@@ -33,60 +33,38 @@ import { z } from "zod";
|
|
|
33
33
|
|
|
34
34
|
Steps are the building blocks of workflows. Create a step using `createStep`:
|
|
35
35
|
|
|
36
|
-
```typescript
|
|
37
|
-
const
|
|
38
|
-
id: "city-step",
|
|
39
|
-
description: "Gets coordinates for city",
|
|
40
|
-
inputSchema: z.object({
|
|
41
|
-
city: z.string()
|
|
42
|
-
}),
|
|
43
|
-
outputSchema: z.object({
|
|
44
|
-
city_name: z.string(),
|
|
45
|
-
city_latitude: z.number(),
|
|
46
|
-
city_longitude: z.number()
|
|
47
|
-
}),
|
|
48
|
-
execute: async ({ inputData }) => {
|
|
49
|
-
const { city } = inputData;
|
|
50
|
-
const geocodingResponse = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}`);
|
|
51
|
-
const geocodingData = await geocodingResponse.json();
|
|
52
|
-
|
|
53
|
-
const { name, latitude, longitude } = geocodingData.results[0];
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
city_name: name,
|
|
57
|
-
city_latitude: latitude,
|
|
58
|
-
city_longitude: longitude
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
});
|
|
36
|
+
```typescript filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
37
|
+
const step1 = createStep({...});
|
|
62
38
|
```
|
|
63
39
|
|
|
64
40
|
> See [createStep](/reference/workflows/step) for more information.
|
|
65
41
|
|
|
66
42
|
### Create Workflow
|
|
67
43
|
|
|
68
|
-
Create a workflow using `createWorkflow
|
|
44
|
+
Create a workflow using `createWorkflow` and complete it with `.commit()`.
|
|
69
45
|
|
|
70
46
|
```typescript {6,17} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
71
47
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
72
48
|
import { z } from "zod";
|
|
73
49
|
|
|
74
|
-
const
|
|
50
|
+
const step1 = createStep({...});
|
|
75
51
|
|
|
76
52
|
export const testWorkflow = createWorkflow({
|
|
77
53
|
id: "test-workflow",
|
|
78
54
|
description: 'Test workflow',
|
|
79
55
|
inputSchema: z.object({
|
|
80
|
-
|
|
56
|
+
input: z.string()
|
|
81
57
|
}),
|
|
82
58
|
outputSchema: z.object({
|
|
83
|
-
|
|
59
|
+
output: z.string()
|
|
84
60
|
})
|
|
85
61
|
})
|
|
86
|
-
.then(
|
|
62
|
+
.then(step1)
|
|
87
63
|
.commit();
|
|
88
64
|
```
|
|
89
65
|
|
|
66
|
+
> See [workflow](/reference/workflows/workflow) for more information.
|
|
67
|
+
|
|
90
68
|
#### Composing Steps
|
|
91
69
|
|
|
92
70
|
Workflow steps can be composed and executed sequentially using `.then()`.
|
|
@@ -95,21 +73,21 @@ Workflow steps can be composed and executed sequentially using `.then()`.
|
|
|
95
73
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
96
74
|
import { z } from "zod";
|
|
97
75
|
|
|
98
|
-
const
|
|
99
|
-
const
|
|
76
|
+
const step1 = createStep({...});
|
|
77
|
+
const step2 = createStep({...});
|
|
100
78
|
|
|
101
79
|
export const testWorkflow = createWorkflow({
|
|
102
80
|
id: "test-workflow",
|
|
103
81
|
description: 'Test workflow',
|
|
104
82
|
inputSchema: z.object({
|
|
105
|
-
|
|
83
|
+
input: z.string()
|
|
106
84
|
}),
|
|
107
85
|
outputSchema: z.object({
|
|
108
|
-
|
|
86
|
+
output: z.string()
|
|
109
87
|
})
|
|
110
88
|
})
|
|
111
|
-
.then(
|
|
112
|
-
.then(
|
|
89
|
+
.then(step1)
|
|
90
|
+
.then(step2)
|
|
113
91
|
.commit();
|
|
114
92
|
```
|
|
115
93
|
|
|
@@ -121,26 +99,26 @@ export const testWorkflow = createWorkflow({
|
|
|
121
99
|
Workflow steps can be cloned using `cloneStep()`, and used with any workflow method.
|
|
122
100
|
|
|
123
101
|
```typescript {5,19} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
124
|
-
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
102
|
+
import { createWorkflow, createStep, cloneStep } from "@mastra/core/workflows";
|
|
125
103
|
import { z } from "zod";
|
|
126
104
|
|
|
127
|
-
const
|
|
128
|
-
const clonedStep = cloneStep(
|
|
129
|
-
const
|
|
105
|
+
const step1 = createStep({...});
|
|
106
|
+
const clonedStep = cloneStep(step1, { id: "cloned-step" });
|
|
107
|
+
const step2 = createStep({...});
|
|
130
108
|
|
|
131
109
|
export const testWorkflow = createWorkflow({
|
|
132
110
|
id: "test-workflow",
|
|
133
111
|
description: 'Test workflow',
|
|
134
112
|
inputSchema: z.object({
|
|
135
|
-
|
|
113
|
+
input: z.string()
|
|
136
114
|
}),
|
|
137
115
|
outputSchema: z.object({
|
|
138
|
-
|
|
116
|
+
output: z.string()
|
|
139
117
|
})
|
|
140
118
|
})
|
|
141
|
-
.then(
|
|
119
|
+
.then(step1)
|
|
142
120
|
.then(clonedStep)
|
|
143
|
-
.then(
|
|
121
|
+
.then(step2)
|
|
144
122
|
.commit();
|
|
145
123
|
```
|
|
146
124
|
|
|
@@ -258,4 +236,3 @@ const result = await run.start({
|
|
|
258
236
|
|
|
259
237
|
|
|
260
238
|
|
|
261
|
-
|