UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

63 lines (42 loc) 1.76 kB
# Workflow\.createRun() 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. ## Usage example ```typescript await workflow.createRun() ``` ## 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 ## Returns **run** (`Run`): A new workflow run instance that can be used to execute the workflow ## Extended usage example ```typescript const workflow = mastra.getWorkflow('workflow') const run = await workflow.createRun() const result = await run.start({ inputData: { value: 10, }, }) ``` ## Using `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. ```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" ``` ## Related - [Run Class](https://mastra.ai/reference/workflows/run) - [Workflows overview](https://mastra.ai/docs/workflows/overview)