Workflows
Define how tasks execute together, either sequentially or in parallel. Compose and nest workflows for complex pipelines.
Overview
Workflows provide a declarative way to orchestrate multiple AI tasks. They handle execution order, data passing between tasks, and error handling automatically.
Creating a Workflow
Create workflows using the Workflow and Task classes:
workflow-basic.ts
1import { Workflow, Task } from '@mozaik-ai/core'23// Create a simple sequential workflow4const workflow = new Workflow("sequential", [5 new Task("Analyze the requirements", "gpt-5"),6 new Task("Generate the code", "claude-sonnet-4.5"),7 new Task("Write documentation", "gpt-5-mini")8])910// Execute the workflow11await workflow.execute()
Parallel Execution
Run tasks in parallel when they don't depend on each other:
workflow-parallel.ts
1import { Workflow, Task } from '@mozaik-ai/core'23// Tasks run simultaneously4const workflow = new Workflow("parallel", [5 new Task("Generate frontend code", "gpt-5"),6 new Task("Generate backend code", "claude-sonnet-4.5"),7 new Task("Generate database schema", "gpt-5-mini")8])910await workflow.execute()
Nested Workflows
Combine sequential and parallel execution for complex pipelines:
workflow-nested.ts
1import { Workflow, Task } from '@mozaik-ai/core'23const workflow = new Workflow("sequential", [4 // Step 1: Analyze (sequential)5 new Task("Analyze requirements", "gpt-5"),67 // Step 2: Generate in parallel8 new Workflow("parallel", [9 new Task("Generate API schema", "gpt-5-mini"),10 new Task("Draft documentation", "gpt-5-nano"),11 new Task("Create test cases", "claude-haiku-4.5")12 ]),1314 // Step 3: Review and finalize15 new Task("Review and finalize", "gpt-5")16])1718await workflow.execute()
Tip
Nest workflows to create sophisticated execution patterns. Each nested workflow completes before the parent continues.
Workflow Types
Sequential
Tasks execute one after another. Output from one task can be used as input for the next.
Task A → Task B → Task CParallel
Tasks execute simultaneously. All tasks must complete before the workflow continues.
Task A ‖ Task B ‖ Task CReal-World Example
Here's a workflow for building a feature:
workflow-feature.ts
1import { Workflow, Task } from '@mozaik-ai/core'23const featureWorkflow = new Workflow("sequential", [4 // 1. Planning phase5 new Task("Break down the feature into subtasks", "gpt-5"),67 // 2. Implementation phase (parallel)8 new Workflow("parallel", [9 new Task("Implement UI components", "claude-sonnet-4.5"),10 new Task("Implement API endpoints", "gpt-5"),11 new Task("Write database migrations", "gpt-5-mini")12 ]),1314 // 3. Quality phase (parallel)15 new Workflow("parallel", [16 new Task("Write unit tests", "gpt-5-mini"),17 new Task("Write integration tests", "claude-haiku-4.5")18 ]),1920 // 4. Documentation21 new Task("Update documentation", "gpt-5-nano")22])2324await featureWorkflow.execute()