> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Run.resume() `.resume()` メソッドは新しいデータを使用して中断された Workflow Run を再開し、特定のステップから実行を続行できるようにします。 ## 使用例 ```typescript 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' }, }) } ``` ## パラメーター **resumeData** (`z.infer`): 中断されたステップを再開するためのデータ **step** (`Step | [...Step[], Step] | string | string[]`): 実行を再開するステップ。Step インスタンス、Step の配列、ステップ ID の文字列、またはステップ ID の文字列配列を指定できます **requestContext** (`RequestContext`): 再開時に使用する Request Context データ **retryCount** (`number`): ネストされた Workflow の実行に使用する任意の再試行回数 **forEachIndex** (`number`): 中断された .foreach() ステップの特定の反復を対象にします。再開する反復のゼロベースのインデックスを渡します。それ以外の反復は中断されたままになります。このフィールドを省略すると、そのステップで中断されているすべての反復が同じ resumeData で再開されます。 **tracingContext** (`TracingContext`): 子 span の作成と metadata の追加に使用する Tracing context。Mastra の tracing system を使用すると自動的に挿入されます。 **tracingContext.currentSpan** (`Span`): 子 span の作成と metadata の追加に使用する現在の span。実行中にカスタムの子 span を作成したり、span attribute を更新したりするために使用します。 **tracingOptions** (`TracingOptions`): Tracing 設定のオプション。 **tracingOptions.metadata** (`Record`): ルート trace span に追加する metadata。ユーザー ID、セッション ID、feature flag などのカスタム属性を追加する場合に役立ちます。 **tracingOptions.requestContextKeys** (`string[]`): この trace の metadata として抽出する追加の RequestContext キー。ネストされた値にはドット記法(例: 'user.id')を使用できます。 **tracingOptions.traceId** (`string`): この実行に使用する trace ID(1〜32 文字の 16 進数)。指定すると、この trace は指定した trace の一部になります。 **tracingOptions.parentSpanId** (`string`): この実行に使用する親 span ID(1〜16 文字の 16 進数)。指定すると、ルート span はこの span の子として作成されます。 **tracingOptions.tags** (`string[]`): この trace に適用する tag。trace の分類とフィルタリングに使用する文字列ラベルです。 **outputOptions** (`OutputOptions`): 出力設定のオプション。 **outputOptions.includeState** (`boolean`): 結果に Workflow Run の状態を含めるかどうか。 ## 戻り値 **result** (`Promise>`): ステップの出力とステータスを含む Workflow の実行結果で解決される Promise **traceId** (`string`): Tracing が有効な場合に、この実行に関連付けられる trace ID。ログの関連付けや実行フローのデバッグに使用します。 **spanId** (`string`): Tracing が有効な場合に、この実行に関連付けられるルート span ID。span 単位の検索と関連付けに使用します。 ## その他の使用例 ```typescript if (result.status === 'suspended') { const resumedResults = await run.resume({ step: result.suspended[0], resumeData: { value: 'resume data' }, }) } ``` > **注記:** 中断されているステップが 1 つだけの場合は、`step` パラメーターを省略すると、Workflow がそのステップを自動的に再開します。複数のステップが中断されている Workflow では、再開するステップを明示的に指定する必要があります。 ### [`.foreach()`](https://mastra.zisheng.pro/ja/reference/workflows/workflow-methods/foreach) の単一の反復を再開する [`.foreach()`](https://mastra.zisheng.pro/ja/reference/workflows/workflow-methods/foreach) ステップが複数の反復にわたって中断されている場合は、`forEachIndex`(ゼロベース)を使用し、反復ごとに異なる `resumeData` で 1 つずつ再開します。`forEachIndex` の対象でない反復は、再開されるまで中断されたままになります。 ```typescript // Resume only the second iteration (index 1) with its own data await run.resume({ step: 'approve', resumeData: { ok: true }, forEachIndex: 1, }) // Later, resume the first iteration with different data await run.resume({ step: 'approve', resumeData: { ok: false }, forEachIndex: 0, }) ``` `forEachIndex` を省略すると、そのステップで中断されているすべての反復が同じ `resumeData` で再開されます。 ## 関連項目 - [Workflow の概要](https://mastra.zisheng.pro/ja/docs/workflows/overview) - [Workflow.createRun()](https://mastra.zisheng.pro/ja/reference/workflows/workflow-methods/create-run) - [中断と再開](https://mastra.zisheng.pro/ja/docs/workflows/suspend-and-resume) - [Human-in-the-loop](https://mastra.zisheng.pro/ja/docs/workflows/human-in-the-loop)