Examples

Comprehensive examples demonstrating MDWR workflows for various use cases.

Available Examples

Master Application Flow

Best for: Complete system workflows with all subsystems

View on GitHub: implementation/workflow-memory-layer/src/workflows/master-application/

Basic Workflow

Best for: Learning MDWR fundamentals

View on GitHub: examples/basic-workflow.ts

Refund Workflow

Best for: Understanding memory integration

View on GitHub: examples/refund-workflow.ts

Approval Workflow

Best for: Multi-level approvals and branching

View on GitHub: examples/approval-workflow.ts

Order Processing

Best for: E-commerce and fulfillment workflows

View on GitHub: examples/order-processing.ts

Content Moderation

Best for: AI/ML decision workflows

View on GitHub: examples/content-moderation.ts

Replay Examples

Best for: Understanding workflow replay

View on GitHub: examples/replay-examples.ts

Running Examples

Deploy All Workflows

npx ts-node scripts/deploy.ts

Execute Specific Workflow

npx ts-node scripts/execute.ts <workflow_name>

View in Motia Workbench

  1. Start Motia: cd motia-atlas && npm run dev
  2. Open: http://localhost:3000
  3. See workflow diagrams and test endpoints

Integration Patterns

See the examples directory on GitHub for complete code.

Quick Code Snippets

Simple Decision:

const workflow = Workflow.create("simple")
  .step("decide", async (ctx) => {
    return {
      decision: "proceed",
      reason: "Simple decision",
      confidence: 1.0
    };
  }, true);

Memory-Informed:

.step("decide", async (ctx) => {
  const insights = await ctx.memory.similar({
    situation: "my_decision",
    context: ctx.input
  });
  
  return { decision, reason, confidence };
}, true)

Conditional Execution:

.step("next", async (ctx) => {
  if (ctx.state.previous?.decision !== "approve") {
    return { decision: "skip", reason: "...", confidence: 1.0 };
  }
  // Continue execution
}, true)

Next Steps