Skip to main content

Run.resume()

.resume() 方法使用新的数据恢复暂停的工作流运行,使你可以从特定步骤继续执行。

🌐 The .resume() method resumes a suspended workflow run with new data, allowing you to continue execution from a specific step.

使用示例
Direct link to 使用示例

🌐 Usage example

const run = await workflow.createRun();

const result = await run.start({ inputData: { value: "initial data" } });

if (result.status === "suspended") {
const resumedResults = await run.resume({
resumeData: { value: "resume data" },
});
}

参数
Direct link to 参数

🌐 Parameters

resumeData?:

z.infer<TResumeSchema>
Data for resuming the suspended step

step?:

Step<string, any, any, TResumeSchema, any, TEngineType> | [...Step<string, any, any, any, any, TEngineType>[], Step<string, any, any, TResumeSchema, any, TEngineType>] | string | string[]
The step(s) to resume execution from. Can be a Step instance, array of Steps, step ID string, or array of step ID strings

requestContext?:

RequestContext
Request Context data to use when resuming

retryCount?:

number
Optional retry count for nested workflow execution

tracingContext?:

TracingContext
Tracing context for creating child spans and adding metadata. Automatically injected when using Mastra's tracing system.

currentSpan?:

Span
Current span for creating child spans and adding metadata. Use this to create custom child spans or update span attributes during execution.

tracingOptions?:

TracingOptions
Options for Tracing configuration.

metadata?:

Record<string, any>
Metadata to add to the root trace span. Useful for adding custom attributes like user IDs, session IDs, or feature flags.

requestContextKeys?:

string[]
Additional RequestContext keys to extract as metadata for this trace. Supports dot notation for nested values (e.g., 'user.id').

traceId?:

string
Trace ID to use for this execution (1-32 hexadecimal characters). If provided, this trace will be part of the specified trace.

parentSpanId?:

string
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.

tags?:

string[]
Tags to apply to this trace. String labels for categorizing and filtering traces.

outputOptions?:

OutputOptions
Options for output configuration.

includeState?:

boolean
Whether to include the workflow run state in the result.

返回
Direct link to 返回

🌐 Returns

result:

Promise<WorkflowResult<TState, TOutput, TSteps>>
A promise that resolves to the workflow execution result containing step outputs and status

traceId?:

string
The trace ID associated with this execution when Tracing is enabled. Use this to correlate logs and debug execution flow.

扩展使用示例
Direct link to 扩展使用示例

🌐 Extended usage example

if (result.status === "suspended") {
const resumedResults = await run.resume({
step: result.suspended[0],
resumeData: { value: "resume data" },
});
}

注意:当正好有一个步骤被暂停时,你可以省略 step 参数,工作流将自动恢复该步骤。对于有多个暂停步骤的工作流,你必须明确指定要恢复的步骤。

🌐 Related