docs/src/course/04-workflows/16-building-parallel-workflow.md
Now you'll create a workflow that runs your analysis steps in parallel for maximum performance.
Add this workflow to your file:
export const parallelAnalysisWorkflow = createWorkflow({
id: 'parallel-analysis-workflow',
description: 'Run multiple content analyses in parallel',
inputSchema: z.object({
content: z.string(),
type: z.enum(['article', 'blog', 'social']).default('article'),
}),
outputSchema: z.object({
results: z.object({
seo: z.object({
seoScore: z.number(),
keywords: z.array(z.string()),
}),
readability: z.object({
readabilityScore: z.number(),
gradeLevel: z.string(),
}),
sentiment: z.object({
sentiment: z.enum(['positive', 'neutral', 'negative']),
confidence: z.number(),
}),
}),
}),
})
.parallel([seoAnalysisStep, readabilityStep, sentimentStep])
.then(
createStep({
id: 'combine-results',
description: 'Combines parallel analysis results',
inputSchema: z.object({
'seo-analysis': z.object({
seoScore: z.number(),
keywords: z.array(z.string()),
}),
'readability-analysis': z.object({
readabilityScore: z.number(),
gradeLevel: z.string(),
}),
'sentiment-analysis': z.object({
sentiment: z.enum(['positive', 'neutral', 'negative']),
confidence: z.number(),
}),
}),
outputSchema: z.object({
results: z.object({
seo: z.object({
seoScore: z.number(),
keywords: z.array(z.string()),
}),
readability: z.object({
readabilityScore: z.number(),
gradeLevel: z.string(),
}),
sentiment: z.object({
sentiment: z.enum(['positive', 'neutral', 'negative']),
confidence: z.number(),
}),
}),
}),
execute: async ({ inputData }) => {
console.log('🔄 Combining parallel results...')
return {
results: {
seo: inputData['seo-analysis'],
readability: inputData['readability-analysis'],
sentiment: inputData['sentiment-analysis'],
},
}
},
}),
)
.commit()
When steps run in parallel:
.parallel([step1, step2, step3]): Runs all steps simultaneouslyNext, you'll test this parallel workflow and see the performance improvement!