@mastra/core
Version:
40 lines (25 loc) • 2.29 kB
Markdown
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
> **Beta:** Stored workflows are in beta. Breaking changes may occur without a major version bump until the API is stable.
The `.addStoredWorkflows()` method adds a bundle of stored workflow definitions that may reference each other. The typical case is a root workflow plus helper workflows it nests, where none of the definitions exist yet.
The whole bundle is validated up front. Members are then registered in dependency order, so a helper is always in place before the workflow that nests it.
[`addStoredWorkflow()`](https://mastra.ai/reference/core/addStoredWorkflow) is the single-member case.
```typescript
await mastra.addStoredWorkflows([
helperDefinition, // nested by the root — order in the array doesn't matter
rootDefinition, // graph contains { type: 'workflow', workflowId: helperDefinition.id }
])
```
**defs** (`readonly StoredWorkflowGraph[]`): The workflow definitions to add. Nested-workflow references may resolve against the live registries or against other members of the same bundle.
A promise that resolves once every member is validated, registered, and persisted.
- References resolve against the instance's registries union the bundle's own IDs, so a root may nest a helper introduced in the same call. Registration order is derived from the dependency graph, not the array order.
- A rejected bundle registers nothing. Duplicate IDs, invalid members, and dependency cycles are detected before anything is mutated, and if registration or persistence fails partway, the in-memory registry is restored to its prior state.
- Storage writes happen last. A storage-level failure mid-bundle can leave some rows written, but the registry is still rolled back and the orphaned rows are inert until the next boot.
- [Mastra.addStoredWorkflow()](https://mastra.ai/reference/core/addStoredWorkflow): Add a single definition
- [Stored workflows](https://mastra.ai/docs/workflows/stored-workflows): Set up and use stored workflows
- [Stored workflow definition](https://mastra.ai/reference/workflows/stored-workflow-definition): Definition fields and graph entries