Mastra Workflow — 단계별 파이프라인 오케스트레이션
Mastra Workflow — 단계별 파이프라인 오케스트레이션
Mastra Workflow 는 정해진 단계(step)들을 순서와 조건에 따라 실행하는 파이프라인이에요. 에이전트의 자유로운 대화 흐름과 달리, 워크플로는 예측 가능한 절차를 코딩으로 명확히 표현해요.
기본 워크플로
import { Workflow } from '@mastra/core/workflows';
const workflow = new Workflow({
name: 'research-pipeline',
}).step('research', async ({ context, mastra }) => {
const result = await searchWeb(context.triggerData.query);
return { findings: result };
}).step('summarize', async ({ context, mastra }) => {
const summary = await summarize(context.research.findings);
return { summary };
}).commit();
triggerData: 워크플로 시작 시 넘긴 입력값이에요.- 각 step 은 이전 step 의
context결과를 받아와요. commit()으로 워크플로 정의를 마무리해요.
조건부 분기 / 재시도
- step 내부에서 조건을 검사해 다른 분기를 타거나 결과를 바꿀 수 있어요.
- 실패한 step 은 재시도 정책을 지정할 수 있어요.
- 환율 조회 → 환산 → 저장 같은 다단계 작업에 어울려요.
실행과 결과
const result = await workflow.run({ triggerData: { query: 'LLM 성능 비교' } });