Workflow.createRun()
.createRun() 方法会创建一个新的工作流运行实例,允许你使用特定的输入数据执行工作流。这是当前返回 Run 实例的 API。
🌐 The .createRun() method creates a new workflow run instance, allowing you to execute the workflow with specific input data. This is the current API that returns a Run instance.
使用示例Direct link to 使用示例
🌐 Usage example
await workflow.createRun();
参数Direct link to 参数
🌐 Parameters
runId?:
string
Optional custom identifier for the workflow run
resourceId?:
string
Optional identifier to associate the workflow run with a specific resource (e.g., user ID, tenant ID). This value is persisted with the workflow run and can be used for filtering and querying runs.
disableScorers?:
boolean
Optional flag to disable scorers for this workflow run
返回Direct link to 返回
🌐 Returns
run:
Run
A new workflow run instance that can be used to execute the workflow
扩展使用示例Direct link to 扩展使用示例
🌐 Extended usage example
const workflow = mastra.getWorkflow("workflow");
const run = await workflow.createRun();
const result = await run.start({
inputData: {
value: 10,
},
});
使用 resourceIdDirect link to 使用 resourceId
🌐 Using resourceId
resourceId 参数将工作流运行与特定资源(例如用户或租户)关联。这对于多租户应用或需要跟踪哪个用户启动了工作流时非常有用。
🌐 The resourceId parameter associates a workflow run with a specific resource, such as a user or tenant. This is useful for multi-tenant applications or when you need to track which user initiated a workflow.
const workflow = mastra.getWorkflow("workflow");
// Create a run associated with a specific user
const run = await workflow.createRun({
resourceId: "user-123",
});
const result = await run.start({
inputData: {
value: 10,
},
});
// Later, retrieve the run and access the resourceId
const storedRun = await workflow.getWorkflowRunById(run.runId);
console.log(storedRun.resourceId); // "user-123"
相关Direct link to 相关
🌐 Related