You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.1 KiB

Example: Document Ingestion Workflow

Purpose: Demonstrates a multi-step workflow with parallel processing.

Last Updated: 2026-01-09


Workflow Definition

export const documentIngestionWorkflow = createWorkflow({
  id: 'document-ingestion',
  inputSchema: z.object({ filename: z.string(), fileBuffer: z.any() }),
  outputSchema: z.object({ documentId: z.string(), success: z.boolean() }),
})
  .then(uploadStep)      // Step 1: Upload
  .then(extractionStep)  // Step 2: Extract Text
  .parallel([            // Step 3: Process in parallel
    classificationStep,
    summarizationStep
  ])
  .then(mergeResultsStep) // Step 4: Merge
  .commit();

Step Execution

const uploadStep = createStep({
  id: 'upload-document',
  execute: async ({ inputData, mastra }) => {
    const result = await documentUploadTool.execute(inputData, { mastra });
    return result;
  },
});

Reference: src/mastra/workflows/document-ingestion-with-classification-workflow.ts Related:

  • concepts/workflows.md
  • concepts/agents-tools.md