docs/src/course/04-workflows/09-adding-a-third-step.md
Let's extend your workflow by adding a third step that generates a summary of the content.
Add this new step to your workflow file:
const generateSummaryStep = createStep({
id: 'generate-summary',
description: 'Creates a summary of the content',
inputSchema: z.object({
content: z.string(),
type: z.string(),
wordCount: z.number(),
metadata: z.object({
readingTime: z.number(),
difficulty: z.enum(['easy', 'medium', 'hard']),
processedAt: z.string(),
}),
}),
outputSchema: z.object({
content: z.string(),
type: z.string(),
wordCount: z.number(),
metadata: z.object({
readingTime: z.number(),
difficulty: z.enum(['easy', 'medium', 'hard']),
processedAt: z.string(),
}),
summary: z.string(),
}),
execute: async ({ inputData }) => {
const { content, type, wordCount, metadata } = inputData
// Create a simple summary from first sentence
const sentences = content.split(/[.!?]+/).filter(s => s.trim().length > 0)
const firstSentence = sentences[0]?.trim() + '.'
// Generate summary based on content length
let summary = firstSentence
if (wordCount > 50) {
summary += ` This ${type} contains ${wordCount} words and takes approximately ${metadata.readingTime} minute(s) to read.`
}
console.log(`📝 Generated summary: ${summary.length} characters`)
return {
content,
type,
wordCount,
metadata,
summary,
}
},
})
Notice how this step:
summary) while preserving existing dataYour third step is ready! Next, you'll update the workflow to include all three steps.