运行类
🌐 Run Class
Run 类表示一个工作流执行实例,提供启动、恢复、流式处理和监控工作流执行的方法。
🌐 The Run class represents a workflow execution instance, providing methods to start, resume, stream, and monitor workflow execution.
使用示例Direct link to 使用示例
🌐 Usage example
const run = await workflow.createRun();
const result = await run.start({
inputData: { value: "initial data" },
});
if (result.status === "suspended") {
const resumedResult = await run.resume({
resumeData: { value: "resume data" },
});
}
运行方法Direct link to 运行方法
🌐 Run Methods
start:
(options?: StartOptions) => Promise<WorkflowResult>
Starts workflow execution with input data
resume:
(options?: ResumeOptions) => Promise<WorkflowResult>
Resumes a suspended workflow from a specific step
stream:
(options?: StreamOptions) => MastraWorkflowStream
Monitors workflow execution as a stream of events with enhanced streaming features
resumeStream:
(options?: ResumeStreamOptions) => MastraWorkflowStream
Resumes a suspended workflow with streaming support
cancel:
() => Promise<{ message: string }>
Cancels the workflow execution, stopping any running steps and preventing subsequent steps from executing
restart:
(options?: RestartOptions) => Promise<WorkflowResult>
Restarts the workflow execution from last active step
timeTravel:
(options?: TimeTravelOptions) => Promise<WorkflowResult>
Re-executes a workflow starting from any specific step, using either stored snapshot data or custom context you provide.
timeTravelStream:
(options?: TimeTravelOptions) => MastraWorkflowStream
Time travels a workflow execution with streaming support
运行状态Direct link to 运行状态
🌐 Run Status
工作流运行的 status 表示其当前的执行状态。可能的值有:
🌐 A workflow run's status indicates its current execution state. The possible values are:
success:
string
All steps finished executing successfully, with a valid result output
failed:
string
Workflow execution encountered an error during execution, with error details available
suspended:
string
Workflow execution is paused waiting for resume, with suspended step information
canceled:
string
Workflow execution was canceled via the cancel() method, stopping any running steps and preventing subsequent steps from executing
相关Direct link to 相关
🌐 Related