1.9 KiB
1.9 KiB
创建AI增强工作流
现在您将创建一个新工作流,该工作流包含代理分析以及您现有的内容处理步骤。
创建增强工作流
将此新工作流添加到您的文件中:
export const aiContentWorkflow = createWorkflow({
id: "ai-content-workflow",
description: "AI-enhanced content processing with analysis",
inputSchema: z.object({
content: z.string(),
type: z.enum(["article", "blog", "social"]).default("article"),
}),
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(),
aiAnalysis: z.object({
score: z.number(),
feedback: z.string(),
}),
}),
})
.then(validateContentStep)
.then(enhanceContentStep)
.then(generateSummaryStep)
.then(aiAnalysisStep)
.commit();
注册新工作流
更新您的Mastra配置以包含两个工作流,并确保已添加contentAgent。
// In src/mastra/index.ts
import {
contentWorkflow,
aiContentWorkflow,
} from "./workflows/content-workflow";
import { contentAgent } from "./agents/content-agent";
export const mastra = new Mastra({
workflows: {
contentWorkflow,
aiContentWorkflow, // Add the AI-enhanced version
},
agents: { contentAgent },
// ... rest of configuration
});
测试代理增强工作流
您现在可以在Mastra操练场内访问此新工作流。从工作流选项卡中选择此新的 ai-content-workflow 工作流并运行测试以验证它按预期工作。
完整的AI管道
您的AI增强工作流现在:
- 验证内容并计算字数
- 增强元数据
- 摘要内容
- 分析质量评分和反馈
这创建了一个全面的、AI驱动的内容处理系统!接下来,您将了解并行执行。