> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Workflow\.createRun() `.createRun()` 方法會建立新的 Workflow 執行個體,讓你能以指定的輸入資料執行 Workflow。這是目前會傳回 `Run` 個體的 API。 ## 使用範例 ```typescript await workflow.createRun() ``` ## 參數 **runId** (`string`): Workflow 執行的選填自訂識別碼 **resourceId** (`string`): 將 Workflow 執行與特定資源(例如使用者 ID、租戶 ID)關聯的選填識別碼。此值會隨 Workflow 執行一併持久保存,並可用於篩選及查詢執行記錄。 **disableScorers** (`boolean`): 停用此 Workflow 執行的 scorers 的選填旗標 ## 傳回值 **run** (`Run`): 可用來執行 Workflow 的新 Workflow 執行個體 ## 延伸使用範例 ```typescript const workflow = mastra.getWorkflow('workflow') const run = await workflow.createRun() const result = await run.start({ inputData: { value: 10, }, }) ``` ## 使用 `resourceId` `resourceId` 參數會將 Workflow 執行與特定資源(例如使用者或租戶)關聯。這對多租戶應用程式,或需要追蹤是哪位使用者啟動 Workflow 的情況十分有用。 ```typescript 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" ``` ## 相關內容 - [Run 類別](https://mastra.zisheng.pro/zh-HK/reference/workflows/run) - [Workflows 概覽](https://mastra.zisheng.pro/zh-HK/docs/workflows/overview)