docs/src/course/04-workflows/20-building-conditional-workflow.md
Now you'll create a workflow that uses conditional branching to route content through two different processing paths.
Add this workflow to your file:
export const conditionalWorkflow = createWorkflow({
id: 'conditional-workflow',
description: 'Content processing with conditional branching',
inputSchema: z.object({
content: z.string(),
type: z.enum(['article', 'blog', 'social']).default('article'),
}),
outputSchema: z.object({
processedContent: z.string(),
processingType: z.string(),
recommendations: z.array(z.string()),
}),
})
.then(assessContentStep)
.branch([
// Branch 1: Short and simple content
[async ({ inputData }) => inputData.category === 'short' && inputData.complexity === 'simple', quickProcessingStep],
// Branch 2: Everything else
[
async ({ inputData }) => !(inputData.category === 'short' && inputData.complexity === 'simple'),
generalProcessingStep,
],
])
.commit()
You can combine conditions using logical operators:
&&: AND - both conditions must be true||: OR - either condition can be true!: NOT - condition must be falseNext, you'll test this conditional workflow with different types of content!