translation/translated/documents/course/04-workflows/01-introduction-to-workflow...

45 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 工作流简介
欢迎来到Mastra课程的第四课在本课中您将学习Mastra工作流——这是一种编排复杂操作序列的强大方式。
## 什么是工作流?
Mastra中的工作流让您能够以可预测的、类型安全的方式将多个操作链接在一起。将它们视为将复杂任务分解为更小、可管理步骤的食谱。
工作流让您无需编写一个处理所有逻辑的庞大函数,而是能够:
- 将复杂操作分解为更小、可复用的步骤
- 为每个步骤定义清晰的输入和输出
- 通过自动数据验证将步骤链接在一起
- 在每个步骤中优雅地处理错误
## 简单示例
没有工作流时,您可能会这样写:
```typescript
async function processContent(text: string) {
// 所有逻辑都在一个函数中 - 难以测试和复用
const validated = validateText(text);
const enhanced = enhanceText(validated);
const summarized = summarizeText(enhanced);
return summarized;
}
```
使用工作流时,相同的逻辑变得模块化且可复用,并且在每个步骤中都内置了追踪功能。
```typescript
export const contentWorkflow = createWorkflow({...})
.then(validateStep)
.then(enhanceStep)
.then(summarizeStep)
.commit();
```
## 您将构建什么
在本课中,您将创建一个内容处理工作流,该工作流使用多个连接的步骤来验证、增强和总结文本内容。
让我们从了解基本的构建块开始吧!