メインコンテンツへ移動

Workflow.createRun()

.createRun() メソッドは新しい Workflow Run インスタンスを作成し、特定の入力データを使用して Workflow を実行できるようにします。これは Run インスタンスを返す現在の API です。

使用例
使用例への直接リンク

await workflow.createRun()

パラメーター
パラメーターへの直接リンク

runId?:

string
Workflow Run の任意のカスタム識別子

resourceId?:

string
Workflow Run を特定のリソース(ユーザー ID、テナント ID など)に関連付けるための任意の識別子。この値は Workflow Run とともに永続化され、Run のフィルタリングやクエリに使用できます。

disableScorers?:

boolean
この Workflow Run の Scorer を無効にする任意のフラグ

戻り値
戻り値への直接リンク

run:

Run
Workflow の実行に使用できる新しい Workflow Run インスタンス

その他の使用例
その他の使用例への直接リンク

const workflow = mastra.getWorkflow('workflow')

const run = await workflow.createRun()

const result = await run.start({
inputData: {
value: 10,
},
})

resourceId を使用する
using-resourceidへの直接リンク

resourceId パラメーターは、Workflow Run をユーザーやテナントなどの特定のリソースに関連付けます。マルチテナントアプリケーションや、どのユーザーが 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"