@mastra/mcp-docs-server 1.0.0-beta.5 → 1.0.0-beta.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.
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +67 -67
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +53 -53
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +29 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +274 -274
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fduckdb.md +42 -0
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Felasticsearch.md +52 -0
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flance.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +84 -84
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Frag.md +43 -43
- package/.docs/organized/changelogs/%40mastra%2Freact.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +56 -56
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +19 -19
- package/.docs/organized/changelogs/create-mastra.md +9 -9
- package/.docs/organized/changelogs/mastra.md +17 -17
- package/.docs/organized/code-examples/agui.md +1 -0
- package/.docs/organized/code-examples/ai-sdk-v5.md +1 -0
- package/.docs/organized/code-examples/mcp-server-adapters.md +721 -0
- package/.docs/organized/code-examples/server-app-access.md +342 -0
- package/.docs/raw/agents/agent-approval.mdx +189 -0
- package/.docs/raw/agents/guardrails.mdx +13 -9
- package/.docs/raw/agents/networks.mdx +1 -0
- package/.docs/raw/agents/overview.mdx +23 -58
- package/.docs/raw/agents/processors.mdx +279 -0
- package/.docs/raw/deployment/cloud-providers/index.mdx +19 -26
- package/.docs/raw/deployment/cloud-providers/netlify-deployer.mdx +44 -13
- package/.docs/raw/evals/running-in-ci.mdx +0 -2
- package/.docs/raw/{guides/getting-started → getting-started}/manual-install.mdx +2 -2
- package/.docs/raw/getting-started/start.mdx +1 -1
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +8 -0
- package/.docs/raw/guides/getting-started/quickstart.mdx +1 -1
- package/.docs/raw/guides/guide/whatsapp-chat-bot.mdx +421 -0
- package/.docs/raw/guides/index.mdx +3 -35
- package/.docs/raw/guides/migrations/upgrade-to-v1/agent.mdx +11 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/workflows.mdx +29 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/memory/memory-processors.mdx +265 -79
- package/.docs/raw/memory/working-memory.mdx +10 -2
- package/.docs/raw/observability/overview.mdx +0 -1
- package/.docs/raw/observability/tracing/bridges/otel.mdx +176 -0
- package/.docs/raw/observability/tracing/exporters/arize.mdx +17 -0
- package/.docs/raw/observability/tracing/exporters/braintrust.mdx +19 -0
- package/.docs/raw/observability/tracing/exporters/langfuse.mdx +20 -0
- package/.docs/raw/observability/tracing/exporters/langsmith.mdx +12 -0
- package/.docs/raw/observability/tracing/exporters/otel.mdx +5 -4
- package/.docs/raw/observability/tracing/overview.mdx +71 -6
- package/.docs/raw/observability/tracing/processors/sensitive-data-filter.mdx +0 -1
- package/.docs/raw/rag/retrieval.mdx +23 -6
- package/.docs/raw/rag/vector-databases.mdx +93 -2
- package/.docs/raw/reference/agents/generate.mdx +55 -6
- package/.docs/raw/reference/agents/network.mdx +44 -0
- package/.docs/raw/reference/client-js/memory.mdx +43 -0
- package/.docs/raw/reference/client-js/workflows.mdx +92 -63
- package/.docs/raw/reference/deployer/netlify.mdx +1 -2
- package/.docs/raw/reference/evals/scorer-utils.mdx +362 -0
- package/.docs/raw/reference/index.mdx +1 -0
- package/.docs/raw/reference/observability/tracing/bridges/otel.mdx +150 -0
- package/.docs/raw/reference/observability/tracing/configuration.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/exporters/arize.mdx +4 -0
- package/.docs/raw/reference/observability/tracing/exporters/langsmith.mdx +17 -1
- package/.docs/raw/reference/observability/tracing/exporters/otel.mdx +6 -0
- package/.docs/raw/reference/observability/tracing/instances.mdx +0 -4
- package/.docs/raw/reference/observability/tracing/interfaces.mdx +29 -4
- package/.docs/raw/reference/observability/tracing/spans.mdx +0 -4
- package/.docs/raw/reference/processors/language-detector.mdx +9 -2
- package/.docs/raw/reference/processors/message-history-processor.mdx +131 -0
- package/.docs/raw/reference/processors/moderation-processor.mdx +10 -3
- package/.docs/raw/reference/processors/pii-detector.mdx +10 -3
- package/.docs/raw/reference/processors/processor-interface.mdx +502 -0
- package/.docs/raw/reference/processors/prompt-injection-detector.mdx +9 -2
- package/.docs/raw/reference/processors/semantic-recall-processor.mdx +197 -0
- package/.docs/raw/reference/processors/system-prompt-scrubber.mdx +2 -2
- package/.docs/raw/reference/processors/tool-call-filter.mdx +125 -0
- package/.docs/raw/reference/processors/working-memory-processor.mdx +221 -0
- package/.docs/raw/reference/storage/cloudflare-d1.mdx +37 -0
- package/.docs/raw/reference/storage/convex.mdx +164 -0
- package/.docs/raw/reference/storage/lance.mdx +33 -0
- package/.docs/raw/reference/storage/libsql.mdx +37 -0
- package/.docs/raw/reference/storage/mongodb.mdx +39 -0
- package/.docs/raw/reference/storage/mssql.mdx +37 -0
- package/.docs/raw/reference/storage/postgresql.mdx +37 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +1 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +56 -1
- package/.docs/raw/reference/streaming/workflows/observeStream.mdx +7 -9
- package/.docs/raw/reference/streaming/workflows/{resumeStreamVNext.mdx → resumeStream.mdx} +51 -11
- package/.docs/raw/reference/streaming/workflows/stream.mdx +83 -24
- package/.docs/raw/reference/tools/mcp-client.mdx +74 -17
- package/.docs/raw/reference/vectors/convex.mdx +429 -0
- package/.docs/raw/reference/vectors/duckdb.mdx +462 -0
- package/.docs/raw/reference/vectors/elasticsearch.mdx +310 -0
- package/.docs/raw/reference/voice/google.mdx +159 -20
- package/.docs/raw/reference/workflows/run-methods/restart.mdx +142 -0
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +44 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +44 -0
- package/.docs/raw/reference/workflows/run.mdx +13 -5
- package/.docs/raw/reference/workflows/step.mdx +13 -0
- package/.docs/raw/reference/workflows/workflow.mdx +19 -0
- package/.docs/raw/server-db/mastra-server.mdx +30 -1
- package/.docs/raw/server-db/request-context.mdx +0 -1
- package/.docs/raw/server-db/storage.mdx +11 -0
- package/.docs/raw/streaming/overview.mdx +6 -6
- package/.docs/raw/streaming/tool-streaming.mdx +2 -2
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -11
- package/.docs/raw/workflows/error-handling.mdx +1 -0
- package/.docs/raw/workflows/human-in-the-loop.mdx +4 -4
- package/.docs/raw/workflows/overview.mdx +56 -44
- package/.docs/raw/workflows/snapshots.mdx +1 -0
- package/.docs/raw/workflows/suspend-and-resume.mdx +85 -16
- package/.docs/raw/workflows/time-travel.mdx +313 -0
- package/.docs/raw/workflows/workflow-state.mdx +191 -0
- package/CHANGELOG.md +8 -0
- package/package.json +4 -4
- package/.docs/raw/agents/human-in-the-loop-with-tools.mdx +0 -91
- package/.docs/raw/reference/streaming/workflows/observeStreamVNext.mdx +0 -47
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +0 -153
|
@@ -87,6 +87,50 @@ if (result.status === "suspended") {
|
|
|
87
87
|
},
|
|
88
88
|
],
|
|
89
89
|
},
|
|
90
|
+
{
|
|
91
|
+
parameters: [
|
|
92
|
+
{
|
|
93
|
+
name: "requestContextKeys",
|
|
94
|
+
type: "string[]",
|
|
95
|
+
isOptional: true,
|
|
96
|
+
description:
|
|
97
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
parameters: [
|
|
103
|
+
{
|
|
104
|
+
name: "traceId",
|
|
105
|
+
type: "string",
|
|
106
|
+
isOptional: true,
|
|
107
|
+
description:
|
|
108
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
parameters: [
|
|
114
|
+
{
|
|
115
|
+
name: "parentSpanId",
|
|
116
|
+
type: "string",
|
|
117
|
+
isOptional: true,
|
|
118
|
+
description:
|
|
119
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
parameters: [
|
|
125
|
+
{
|
|
126
|
+
name: "tags",
|
|
127
|
+
type: "string[]",
|
|
128
|
+
isOptional: true,
|
|
129
|
+
description:
|
|
130
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
90
134
|
],
|
|
91
135
|
},
|
|
92
136
|
{
|
|
@@ -78,6 +78,50 @@ const result = await run.start({
|
|
|
78
78
|
},
|
|
79
79
|
],
|
|
80
80
|
},
|
|
81
|
+
{
|
|
82
|
+
parameters: [
|
|
83
|
+
{
|
|
84
|
+
name: "requestContextKeys",
|
|
85
|
+
type: "string[]",
|
|
86
|
+
isOptional: true,
|
|
87
|
+
description:
|
|
88
|
+
"Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
parameters: [
|
|
94
|
+
{
|
|
95
|
+
name: "traceId",
|
|
96
|
+
type: "string",
|
|
97
|
+
isOptional: true,
|
|
98
|
+
description:
|
|
99
|
+
"Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
parameters: [
|
|
105
|
+
{
|
|
106
|
+
name: "parentSpanId",
|
|
107
|
+
type: "string",
|
|
108
|
+
isOptional: true,
|
|
109
|
+
description:
|
|
110
|
+
"Parent span ID to use for this execution (1-16 hexadecimal characters). If provided, the root span will be created as a child of this span.",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
parameters: [
|
|
116
|
+
{
|
|
117
|
+
name: "tags",
|
|
118
|
+
type: "string[]",
|
|
119
|
+
isOptional: true,
|
|
120
|
+
description:
|
|
121
|
+
"Tags to apply to this trace. String labels for categorizing and filtering traces.",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
81
125
|
],
|
|
82
126
|
},
|
|
83
127
|
{
|
|
@@ -41,14 +41,14 @@ if (result.status === "suspended") {
|
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
name: "stream",
|
|
44
|
-
type: "(options?: StreamOptions) =>
|
|
45
|
-
description: "Monitors workflow execution as a stream of events",
|
|
44
|
+
type: "(options?: StreamOptions) => MastraWorkflowStream",
|
|
45
|
+
description: "Monitors workflow execution as a stream of events with enhanced streaming features",
|
|
46
46
|
required: true,
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
name: "
|
|
50
|
-
type: "(options?:
|
|
51
|
-
description: "
|
|
49
|
+
name: "resumeStream",
|
|
50
|
+
type: "(options?: ResumeStreamOptions) => MastraWorkflowStream",
|
|
51
|
+
description: "Resumes a suspended workflow with streaming support",
|
|
52
52
|
required: true,
|
|
53
53
|
},
|
|
54
54
|
{
|
|
@@ -57,6 +57,12 @@ if (result.status === "suspended") {
|
|
|
57
57
|
description: "Cancels the workflow execution",
|
|
58
58
|
required: true,
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
name: "restart",
|
|
62
|
+
type: "(options?: RestartOptions) => Promise<WorkflowResult>",
|
|
63
|
+
description: "Restarts the workflow execution from last active step",
|
|
64
|
+
required: true,
|
|
65
|
+
},
|
|
60
66
|
]}
|
|
61
67
|
/>
|
|
62
68
|
|
|
@@ -92,3 +98,5 @@ A workflow run's `status` indicates its current execution state. The possible va
|
|
|
92
98
|
- [Run.start()](./run-methods/start)
|
|
93
99
|
- [Run.resume()](./run-methods/resume)
|
|
94
100
|
- [Run.cancel()](./run-methods/cancel)
|
|
101
|
+
- [Run.restart()](./run-methods/restart)
|
|
102
|
+
- [Run.stream()](/docs/v1/streaming/workflow-streaming)
|
|
@@ -103,6 +103,12 @@ const step1 = createStep({
|
|
|
103
103
|
description:
|
|
104
104
|
"The resume data matching the resumeSchema, when resuming the step from a suspended state. Only exists if the step is being resumed.",
|
|
105
105
|
},
|
|
106
|
+
{
|
|
107
|
+
name: "suspendData",
|
|
108
|
+
type: "z.infer<TSuspendSchema>",
|
|
109
|
+
description:
|
|
110
|
+
"The suspend data that was originally passed to suspend() when the step was suspended. Only exists if the step is being resumed and was previously suspended with data.",
|
|
111
|
+
},
|
|
106
112
|
{
|
|
107
113
|
name: "mastra",
|
|
108
114
|
type: "Mastra",
|
|
@@ -124,6 +130,12 @@ const step1 = createStep({
|
|
|
124
130
|
type: "(suspendPayload: any, suspendOptions?: { resumeLabel?: string }) => Promise<void>",
|
|
125
131
|
description: "Function to pause workflow execution",
|
|
126
132
|
},
|
|
133
|
+
{
|
|
134
|
+
name: "state",
|
|
135
|
+
type: "z.infer<TState>",
|
|
136
|
+
description:
|
|
137
|
+
"The current workflow state. Contains shared values that persist across all steps and suspend/resume cycles. The structure is defined by the step's stateSchema.",
|
|
138
|
+
},
|
|
127
139
|
{
|
|
128
140
|
name: "setState",
|
|
129
141
|
type: "(state: z.infer<TState>) => void",
|
|
@@ -154,5 +166,6 @@ const step1 = createStep({
|
|
|
154
166
|
|
|
155
167
|
## Related
|
|
156
168
|
|
|
169
|
+
- [Workflow state](/docs/v1/workflows/workflow-state)
|
|
157
170
|
- [Control flow](/docs/v1/workflows/control-flow)
|
|
158
171
|
- [Using agents and tools](/docs/v1/workflows/agents-and-tools)
|
|
@@ -88,6 +88,24 @@ export const workflow = createWorkflow({
|
|
|
88
88
|
]}
|
|
89
89
|
/>
|
|
90
90
|
|
|
91
|
+
## Running with initial state
|
|
92
|
+
|
|
93
|
+
When starting a workflow run, you can pass `initialState` to set the starting values for the workflow's state:
|
|
94
|
+
|
|
95
|
+
```typescript showLineNumbers copy
|
|
96
|
+
const run = await workflow.createRun();
|
|
97
|
+
|
|
98
|
+
const result = await run.start({
|
|
99
|
+
inputData: { value: "hello" },
|
|
100
|
+
initialState: {
|
|
101
|
+
counter: 0,
|
|
102
|
+
items: [],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The `initialState` object should match the structure defined in the workflow's `stateSchema`. See [Workflow State](/docs/v1/workflows/workflow-state) for more details.
|
|
108
|
+
|
|
91
109
|
## Workflow status
|
|
92
110
|
|
|
93
111
|
A workflow's `status` indicates its current execution state. The possible values are:
|
|
@@ -118,4 +136,5 @@ A workflow's `status` indicates its current execution state. The possible values
|
|
|
118
136
|
## Related
|
|
119
137
|
|
|
120
138
|
- [Step Class](./step)
|
|
139
|
+
- [Workflow State](/docs/v1/workflows/workflow-state)
|
|
121
140
|
- [Control flow](/docs/v1/workflows/control-flow)
|
|
@@ -36,7 +36,7 @@ export const mastra = new Mastra({
|
|
|
36
36
|
// ...
|
|
37
37
|
server: {
|
|
38
38
|
port: 3000, // Defaults to 4111
|
|
39
|
-
timeout: 10000, // Defaults to
|
|
39
|
+
timeout: 10000, // Defaults to 3 * 60 * 1000 (3 minutes)
|
|
40
40
|
},
|
|
41
41
|
});
|
|
42
42
|
```
|
|
@@ -87,3 +87,32 @@ export const mastra = new Mastra({
|
|
|
87
87
|
},
|
|
88
88
|
});
|
|
89
89
|
```
|
|
90
|
+
|
|
91
|
+
## Stream data redaction
|
|
92
|
+
|
|
93
|
+
When streaming agent responses over HTTP, Mastra automatically redacts sensitive information from stream chunks before sending them to clients. This prevents accidental exposure of:
|
|
94
|
+
|
|
95
|
+
- System prompts and agent instructions
|
|
96
|
+
- Tool definitions and their parameters
|
|
97
|
+
- API keys and other credentials in request bodies
|
|
98
|
+
- Internal configuration data
|
|
99
|
+
|
|
100
|
+
This redaction happens at the HTTP boundary, so internal callbacks like `onStepFinish` still have access to the full request data for debugging and observability purposes.
|
|
101
|
+
|
|
102
|
+
### Configuring redaction
|
|
103
|
+
|
|
104
|
+
By default, redaction is enabled. If you're using the server adapters directly (e.g., `@mastra/hono` or `@mastra/express`), you can configure this behavior:
|
|
105
|
+
|
|
106
|
+
```typescript title="Custom server setup" copy
|
|
107
|
+
import { HonoServerAdapter } from "@mastra/hono";
|
|
108
|
+
import { mastra } from "./mastra";
|
|
109
|
+
|
|
110
|
+
const adapter = new HonoServerAdapter({
|
|
111
|
+
mastra,
|
|
112
|
+
streamOptions: {
|
|
113
|
+
redact: true,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Set `redact: false` only for internal services or debugging scenarios where you need access to the full request data in stream responses.
|
|
@@ -187,7 +187,6 @@ export const weatherTool = createTool({
|
|
|
187
187
|
|
|
188
188
|
## Related
|
|
189
189
|
|
|
190
|
-
- [Request Context Example](/examples/v1/agents/request-context)
|
|
191
190
|
- [Agent Request Context](/docs/v1/agents/overview#using-requestcontext)
|
|
192
191
|
- [Workflow Request Context](../workflows/overview#using-requestcontext)
|
|
193
192
|
- [Tool Request Context](../mcp/overview#using-requestcontext)
|
|
@@ -489,12 +489,23 @@ console.log(result.messages); // MastraDBMessage[]
|
|
|
489
489
|
console.log(result.total); // Total count
|
|
490
490
|
console.log(result.hasMore); // Whether more pages exist
|
|
491
491
|
|
|
492
|
+
// Get messages from multiple threads at once
|
|
493
|
+
const multiThreadResult = await mastra
|
|
494
|
+
.getStorage()
|
|
495
|
+
.listMessages({
|
|
496
|
+
threadId: ["thread-1", "thread-2", "thread-3"],
|
|
497
|
+
page: 0,
|
|
498
|
+
perPage: 100
|
|
499
|
+
});
|
|
500
|
+
|
|
492
501
|
// Get messages by their IDs
|
|
493
502
|
const messages = await mastra
|
|
494
503
|
.getStorage()
|
|
495
504
|
.listMessagesById({ messageIds: messageIdArr });
|
|
496
505
|
```
|
|
497
506
|
|
|
507
|
+
The `threadId` parameter accepts either a single thread ID string or an array of thread IDs to query messages from multiple threads in a single request.
|
|
508
|
+
|
|
498
509
|
All message queries return `MastraDBMessage[]` format. If you need to convert messages to AI SDK formats for UI rendering, use the conversion utilities from `@mastra/ai-sdk/ui`:
|
|
499
510
|
|
|
500
511
|
```typescript copy
|
|
@@ -132,14 +132,14 @@ console.log("Token usage:", await networkStream.usage);
|
|
|
132
132
|
|
|
133
133
|
Streaming from a workflow returns a sequence of structured events describing the run lifecycle, rather than incremental text chunks. This event-based format makes it possible to track and respond to workflow progress in real time once a run is created using `.createRun()`.
|
|
134
134
|
|
|
135
|
-
### Using `Run.
|
|
135
|
+
### Using `Run.stream()`
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
The `stream()` method returns a `ReadableStream` of events directly.
|
|
138
138
|
|
|
139
139
|
```typescript {3,9} showLineNumbers copy
|
|
140
140
|
const run = await testWorkflow.createRun();
|
|
141
141
|
|
|
142
|
-
const stream = await run.
|
|
142
|
+
const stream = await run.stream({
|
|
143
143
|
inputData: {
|
|
144
144
|
value: "initial data",
|
|
145
145
|
},
|
|
@@ -150,16 +150,16 @@ for await (const chunk of stream) {
|
|
|
150
150
|
}
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
> See Run.
|
|
153
|
+
> See [Run.stream()](/reference/v1/streaming/workflows/stream) method documentation for more information.
|
|
154
154
|
|
|
155
155
|
### Output from `Run.stream()`
|
|
156
156
|
|
|
157
|
-
The
|
|
157
|
+
The event structure includes `runId` and `from` at the top level, making it easier to identify and track workflow runs without digging into the payload.
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
160
|
// ...
|
|
161
161
|
{
|
|
162
|
-
type: '
|
|
162
|
+
type: 'workflow-start',
|
|
163
163
|
runId: '1eeaf01a-d2bf-4e3f-8d1b-027795ccd3df',
|
|
164
164
|
from: 'WORKFLOW',
|
|
165
165
|
payload: {
|
|
@@ -162,7 +162,7 @@ For detailed documentation on all lifecycle hooks, see the [createTool() referen
|
|
|
162
162
|
|
|
163
163
|
## Tool using an agent
|
|
164
164
|
|
|
165
|
-
Pipe an agent's `
|
|
165
|
+
Pipe an agent's `fullStream` to the tool's `writer`. This streams partial output, and Mastra automatically aggregates the agent's usage into the tool run.
|
|
166
166
|
|
|
167
167
|
```typescript showLineNumbers copy
|
|
168
168
|
import { createTool } from "@mastra/core/tools";
|
|
@@ -176,7 +176,7 @@ export const testTool = createTool({
|
|
|
176
176
|
const testAgent = context?.mastra?.getAgent("testAgent");
|
|
177
177
|
const stream = await testAgent?.stream(`What is the weather in ${city}?`);
|
|
178
178
|
|
|
179
|
-
await stream!.
|
|
179
|
+
await stream!.fullStream.pipeTo(context?.writer!);
|
|
180
180
|
|
|
181
181
|
return {
|
|
182
182
|
value: await stream!.text,
|
|
@@ -16,12 +16,6 @@ By combining writable workflow streams with agent streaming, you gain fine-grain
|
|
|
16
16
|
|
|
17
17
|
### Using the `writer` argument
|
|
18
18
|
|
|
19
|
-
:::warning
|
|
20
|
-
|
|
21
|
-
The writer is only available when using `streamVNext`.
|
|
22
|
-
|
|
23
|
-
:::
|
|
24
|
-
|
|
25
19
|
The `writer` argument is passed to a workflow step's `execute` function and can be used to emit custom events, data, or values into the active stream. This enables workflow steps to provide intermediate results or status updates while execution is still in progress.
|
|
26
20
|
|
|
27
21
|
:::warning
|
|
@@ -66,7 +60,7 @@ const testWorkflow = mastra.getWorkflow("testWorkflow");
|
|
|
66
60
|
|
|
67
61
|
const run = await testWorkflow.createRun();
|
|
68
62
|
|
|
69
|
-
const stream = await run.
|
|
63
|
+
const stream = await run.stream({
|
|
70
64
|
inputData: {
|
|
71
65
|
value: "initial data",
|
|
72
66
|
},
|
|
@@ -77,8 +71,8 @@ for await (const chunk of stream) {
|
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
if (result!.status === "suspended") {
|
|
80
|
-
// if the workflow is suspended, we can resume it with the
|
|
81
|
-
const resumedStream = await run.
|
|
74
|
+
// if the workflow is suspended, we can resume it with the resumeStream method
|
|
75
|
+
const resumedStream = await run.resumeStream({
|
|
82
76
|
resumeData: { value: "resume data" },
|
|
83
77
|
});
|
|
84
78
|
|
|
@@ -90,10 +84,10 @@ if (result!.status === "suspended") {
|
|
|
90
84
|
|
|
91
85
|
### Resuming an interrupted workflow stream
|
|
92
86
|
|
|
93
|
-
If a workflow stream is closed or interrupted for any reason, you can resume it with the `
|
|
87
|
+
If a workflow stream is closed or interrupted for any reason, you can resume it with the `resumeStream` method. This will return a new `ReadableStream` that you can use to observe the workflow events.
|
|
94
88
|
|
|
95
89
|
```typescript showLineNumbers copy
|
|
96
|
-
const newStream = await run.
|
|
90
|
+
const newStream = await run.resumeStream();
|
|
97
91
|
|
|
98
92
|
for await (const chunk of newStream) {
|
|
99
93
|
console.log(chunk);
|
|
@@ -189,4 +189,5 @@ for await (const chunk of stream.stream) {
|
|
|
189
189
|
|
|
190
190
|
- [Control Flow](/docs/v1/workflows/control-flow)
|
|
191
191
|
- [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
|
|
192
|
+
- [Time Travel](/docs/v1/workflows/time-travel)
|
|
192
193
|
- [Human-in-the-loop](/docs/v1/workflows/human-in-the-loop)
|
|
@@ -11,7 +11,7 @@ Some workflows need to pause for human input before continuing. When a workflow
|
|
|
11
11
|
|
|
12
12
|
Human-in-the-loop input works much like [pausing a workflow](/docs/v1/workflows/suspend-and-resume) using `suspend()`. The key difference is that when human input is required, you can return `suspend()` with a payload that provides context or guidance to the user on how to continue.
|
|
13
13
|
|
|
14
|
-
](/img/workflows/workflows-suspend.jpg)
|
|
15
15
|
|
|
16
16
|
```typescript {12-17,22-26} title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
17
17
|
import { createWorkflow, createStep } from "@mastra/core/workflows";
|
|
@@ -66,7 +66,7 @@ When a workflow is suspended, you can access the payload returned by `suspend()`
|
|
|
66
66
|
|
|
67
67
|
```typescript {12} title="src/test-workflow.ts" showLineNumbers copy
|
|
68
68
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
69
|
-
const run = await workflow.
|
|
69
|
+
const run = await workflow.createRun();
|
|
70
70
|
|
|
71
71
|
const result = await run.start({
|
|
72
72
|
inputData: {
|
|
@@ -93,11 +93,11 @@ The data returned by the step can include a reason and help the user understand
|
|
|
93
93
|
|
|
94
94
|
As with [restarting a workflow](/docs/v1/workflows/suspend-and-resume#restarting-a-workflow-with-resume), use `resume()` with `resumeData` to continue a workflow after receiving input from a human. The workflow resumes from the step where it was paused.
|
|
95
95
|
|
|
96
|
-
](/img/workflows/workflows-resume.jpg)
|
|
97
97
|
|
|
98
98
|
```typescript {13} showLineNumbers copy
|
|
99
99
|
const workflow = mastra.getWorkflow("testWorkflow");
|
|
100
|
-
const run = await workflow.
|
|
100
|
+
const run = await workflow.createRun();
|
|
101
101
|
|
|
102
102
|
await run.start({
|
|
103
103
|
inputData: {
|
|
@@ -90,60 +90,28 @@ Workflows can be composed using a number of different methods. The method you ch
|
|
|
90
90
|
|
|
91
91
|
## Workflow state
|
|
92
92
|
|
|
93
|
-
Workflow state lets you share values across steps without passing them through every step
|
|
93
|
+
Workflow state lets you share values across steps without passing them through every step's inputSchema and outputSchema. Use state for tracking progress, accumulating results, or sharing configuration across the entire workflow.
|
|
94
94
|
|
|
95
95
|
```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
|
|
96
96
|
const step1 = createStep({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}),
|
|
97
|
+
id: "step-1",
|
|
98
|
+
inputSchema: z.object({ message: z.string() }),
|
|
99
|
+
outputSchema: z.object({ formatted: z.string() }),
|
|
100
|
+
stateSchema: z.object({ counter: z.number() }),
|
|
101
101
|
execute: async ({ inputData, state, setState }) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
setState({
|
|
106
|
-
...state,
|
|
107
|
-
processedItems: [...processedItems, "item-1", "item-2"],
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
formatted: message.toUpperCase(),
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
});
|
|
102
|
+
// Read from state
|
|
103
|
+
console.log(state.counter);
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
stateSchema: z.object({
|
|
119
|
-
metadata: z.object({
|
|
120
|
-
processedBy: z.string(),
|
|
121
|
-
}),
|
|
122
|
-
}),
|
|
123
|
-
execute: async ({ inputData, state }) => {
|
|
124
|
-
const { formatted } = inputData;
|
|
125
|
-
const { metadata } = state;
|
|
105
|
+
// Update state for subsequent steps
|
|
106
|
+
setState({ ...state, counter: state.counter + 1 });
|
|
126
107
|
|
|
127
|
-
return {
|
|
128
|
-
emphasized: `${formatted}!! ${metadata.processedBy}`,
|
|
129
|
-
};
|
|
108
|
+
return { formatted: inputData.message.toUpperCase() };
|
|
130
109
|
},
|
|
131
110
|
});
|
|
132
|
-
|
|
133
|
-
export const testWorkflow = createWorkflow({
|
|
134
|
-
// ...
|
|
135
|
-
stateSchema: z.object({
|
|
136
|
-
processedItems: z.array(z.string()),
|
|
137
|
-
metadata: z.object({
|
|
138
|
-
processedBy: z.string(),
|
|
139
|
-
}),
|
|
140
|
-
}),
|
|
141
|
-
})
|
|
142
|
-
.then(step1)
|
|
143
|
-
.then(step2)
|
|
144
|
-
.commit();
|
|
145
111
|
```
|
|
146
112
|
|
|
113
|
+
> See [Workflow State](/docs/v1/workflows/workflow-state) for complete documentation on state schemas, initial state, persistence across suspend/resume, and nested workflows.
|
|
114
|
+
|
|
147
115
|
## Workflows as steps
|
|
148
116
|
|
|
149
117
|
Use a workflow as a step to reuse its logic within a larger composition. Input and output follow the same schema rules described in [Core principles](/docs/v1/workflows/control-flow).
|
|
@@ -302,6 +270,49 @@ The workflow output includes the full execution lifecycle, showing the input and
|
|
|
302
270
|
}
|
|
303
271
|
```
|
|
304
272
|
|
|
273
|
+
## Restarting active workflow runs
|
|
274
|
+
|
|
275
|
+
When a workflow run loses connection to the server, it can be restarted from the last active step. This is useful for long-running workflows that might still be running when the server loses connection. Restarting a workflow run will resume execution from the last active step, and the workflow will continue from there.
|
|
276
|
+
|
|
277
|
+
### Restarting all active workflow runs of a workflow with `restartAllActiveWorkflowRuns()`
|
|
278
|
+
|
|
279
|
+
Use `restartAllActiveWorkflowRuns()` to restart all active workflow runs of a workflow. This helps restart all active workflow runs of a workflow, without having to manually loop through each run and restart.
|
|
280
|
+
|
|
281
|
+
```typescript showLineNumbers copy
|
|
282
|
+
workflow.restartAllActiveWorkflowRuns();
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Restarting an active workflow run with `restart()`
|
|
286
|
+
|
|
287
|
+
Use `restart()` to restart an active workflow run from the last active step. This will resume execution from the last active step, and the workflow will continue from there.
|
|
288
|
+
|
|
289
|
+
```typescript showLineNumbers copy
|
|
290
|
+
const run = await workflow.createRun();
|
|
291
|
+
|
|
292
|
+
const result = await run.start({ inputData: { value: "initial data" } });
|
|
293
|
+
|
|
294
|
+
//.. server connection lost,
|
|
295
|
+
|
|
296
|
+
const restartedResult = await run.restart();
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Identifying active workflow runs
|
|
300
|
+
|
|
301
|
+
When a workflow run is active, it will have a `status` of `running` or `waiting`. You can check the workflow's `status` to confirm it's active, and use `active` to identify the active workflow run.
|
|
302
|
+
|
|
303
|
+
```typescript showLineNumbers copy
|
|
304
|
+
const activeRuns = await workflow.listActiveWorkflowRuns();
|
|
305
|
+
if (activeRuns.runs.length > 0) {
|
|
306
|
+
console.log(activeRuns.runs);
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
:::Note
|
|
311
|
+
|
|
312
|
+
When running the local mastra server, all active workflow runs will be restarted automatically when the server starts.
|
|
313
|
+
|
|
314
|
+
:::
|
|
315
|
+
|
|
305
316
|
## Using `RequestContext`
|
|
306
317
|
|
|
307
318
|
Use [RequestContext](/docs/v1/server-db/request-context) to access request-specific values. This lets you conditionally adjust behavior based on the context of the request.
|
|
@@ -335,6 +346,7 @@ Use [Studio](/docs/v1/getting-started/studio) to easily run workflows with diffe
|
|
|
335
346
|
|
|
336
347
|
For a closer look at workflows, see our [Workflow Guide](/guides/v1/guide/ai-recruiter), which walks through the core concepts with a practical example.
|
|
337
348
|
|
|
349
|
+
- [Workflow State](/docs/v1/workflows/workflow-state)
|
|
338
350
|
- [Control Flow](/docs/v1/workflows/control-flow)
|
|
339
351
|
- [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
|
|
340
352
|
- [Error Handling](/docs/v1/workflows/error-handling)
|
|
@@ -268,4 +268,5 @@ if (result.status === "suspended") {
|
|
|
268
268
|
|
|
269
269
|
- [Control Flow](/docs/v1/workflows/control-flow)
|
|
270
270
|
- [Suspend & Resume](/docs/v1/workflows/suspend-and-resume)
|
|
271
|
+
- [Time Travel](/docs/v1/workflows/time-travel)
|
|
271
272
|
- [Human-in-the-loop](/docs/v1/workflows/human-in-the-loop)
|