Magpai

Building Workflows

Learn how to design effective workflows with the right step structure and patterns.

Anatomy of a Workflow

A workflow is a sequence of steps that Maggie executes in order. Each step has a specific purpose, and the output of one step becomes available to the next.

Workflow execution flow showing steps from input to output

Name & Description

Human-readable title and purpose

Prompt

Main context and instructions

Steps

Ordered sequence of operations

Step Order

Deterministic execution sequence

Output Schema

Optional structured result format

Variants

Different context versions

Step Types

Workflows are built from five types of steps. Each type serves a different purpose in the automation pipeline.

The five workflow step types: Prompt, Form, Approval, Code, and Todo-List
Step TypePurposePauses Workflow?
PromptAI-powered tasks with tool accessOnly with guardrails
FormCollect user inputsYes
ApprovalHuman review of AI contentYes
CodeExecute custom code logicNo
Todo-ListCreate task checklistsYes

Execution Flow

Understanding how workflows execute helps you design better automations.

1

Initialize

Workflow starts with initial inputs and loads variant context if specified.

2

Execute Steps

Steps run in order. Each step receives outputs from previous steps as inputs.

3

Handle Pauses

Some steps (Form, Approval, Todo-List) pause for human interaction. Workflow resumes when completed.

4

Accumulate Results

Outputs from each step are collected. Output schema validates final structured data.

5

Complete

Workflow finishes with final outputs and analytics. Notifications sent if configured.

Common Workflow Patterns

These patterns help you structure workflows for common use cases.

📝

Input → Process → Review

Collect information, have Maggie process it, then review before sending.

Form → Prompt → Approval → Prompt (send)
🔄

Research → Analyze → Report

Gather data, analyze findings, produce structured results.

Prompt (research) → Prompt (analyze) → Approval

Generate → Choose → Execute

Generate options, let user pick, then act on selection.

Prompt → Approval (pick-one) → Prompt (execute)
📋

Plan → Tasks → Complete

Create a plan, break into tasks, track completion.

Prompt (plan) → Todo-List → Prompt (summarize)

Data Flow Between Steps

Each step can access outputs from previous steps. This allows you to chain operations together.

Step 1 (Form)
  └→ inputs: { topic: "AI Trends", length: "short" }

Step 2 (Prompt)
  └→ receives: { topic, length }
  └→ outputs: { research: "..." }

Step 3 (Approval)
  └→ receives: { topic, length, research }
  └→ outputs: { approved_content: "..." }

Step 4 (Prompt)
  └→ receives: all accumulated outputs
  └→ executes: final actions (e.g., send email)

Best Practices

1. Start with clear objectives

Define what the workflow should accomplish before adding steps. A clear goal helps you choose the right step types and order.

2. Use approval steps for critical actions

Always add approval steps before sending emails, posting content, or making irreversible changes. You can also enable guardrails on prompt steps.

3. Keep prompts focused

Each prompt step should do one thing well. Split complex tasks into multiple steps rather than cramming everything into one prompt.

4. Provide context in the workflow prompt

The main workflow prompt sets context for all steps. Include background information, style preferences, and any constraints here.

5. Use output schemas for structured data

If you need specific data extracted (like numbers, lists, or objects), define an output schema. This ensures consistent results.

6. Test with different inputs

Run your workflow with various inputs to catch edge cases. Check that prompts handle unexpected data gracefully.

Choosing the Right Step Type

Use this guide to pick the right step for your needs:

  • Need AI to think, research, or write? → Prompt Step
  • Need user input at runtime? → Form Step
  • Need human review before continuing? → Approval Step
  • Need complex logic or calculations? → Code Step
  • Need to track task completion? → Todo-List Step

Next Steps

Now that you understand workflow structure, dive deeper into each step type: