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'
2
3// Create a simple sequential workflow
4const 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])
9
10// Execute the workflow
11await 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'
2
3// Tasks run simultaneously
4const 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])
9
10await workflow.execute()

Nested Workflows

Combine sequential and parallel execution for complex pipelines:

workflow-nested.ts
1import { Workflow, Task } from '@mozaik-ai/core'
2
3const workflow = new Workflow("sequential", [
4 // Step 1: Analyze (sequential)
5 new Task("Analyze requirements", "gpt-5"),
6
7 // Step 2: Generate in parallel
8 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 ]),
13
14 // Step 3: Review and finalize
15 new Task("Review and finalize", "gpt-5")
16])
17
18await 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 C

Parallel

Tasks execute simultaneously. All tasks must complete before the workflow continues.

Task A ‖ Task B ‖ Task C

Real-World Example

Here's a workflow for building a feature:

workflow-feature.ts
1import { Workflow, Task } from '@mozaik-ai/core'
2
3const featureWorkflow = new Workflow("sequential", [
4 // 1. Planning phase
5 new Task("Break down the feature into subtasks", "gpt-5"),
6
7 // 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 ]),
13
14 // 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 ]),
19
20 // 4. Documentation
21 new Task("Update documentation", "gpt-5-nano")
22])
23
24await featureWorkflow.execute()

Next Steps