Mastra.getWorkflow()
The .getWorkflow() method is used to retrieve a workflow by its registration key. The method provides full TypeScript type inference for workflow input and output schemas.
Usage exampleUsage example的直接链接
// Retrieve workflow by its registration key (recommended for type inference)
const workflow = mastra.getWorkflow('testWorkflow')
const run = await workflow.createRun()
// TypeScript will properly infer the input schema type
await run.startAsync({
inputData: {/* properly typed */},
})
Type inferenceType inference的直接链接
For best TypeScript support, use getWorkflow() with the workflow's registration key (the key used when adding the workflow to Mastra). The registration key provides full type inference for:
- Input data schemas
- Output data schemas
- Step results
If you need to retrieve a workflow by its id property instead of its registration key, you can use getWorkflowById(), but note that type inference won't be as precise.
ParametersParameters的直接链接
id:
TWorkflowId extends keyof TWorkflows
The ID of the workflow to retrieve. Must be a valid workflow ID that exists in the Mastra configuration.
options:
{ serialized?: boolean }
Optional configuration object. When
serialized is true, returns only the workflow name instead of the full workflow instance.ReturnsReturns的直接链接
workflow:
TWorkflows[TWorkflowId]
The workflow instance with the specified ID. Throws an error if the workflow is not found.