Quick Start
Build your first memory-driven workflow in 5 minutes.
Create Your First Workflow
Create a workflow in workflows/refund.ts:
import { Workflow } from "@mdwr/sdk";
const refundWorkflow = Workflow.create("refund_v1")
.step("evaluate_risk", async (ctx) => {
// Query memory for similar decisions
const insights = await ctx.memory.similar({
situation: "refund_decision",
context: {
amount: ctx.input.amount,
userTier: ctx.input.userTier || "standard"
}
});
let decision = "approve";
let reason = "Standard approval";
let confidence = 0.8;
// Use historical insights
if (insights.length > 0) {
const best = insights[0];
if (best.outcome?.success) {
decision = best.decision.decision;
reason = `Based on similar decision: ${best.decision.reason}`;
confidence = Math.min(0.95, (best.decision.confidence || 0.8) + 0.1);
}
}
// Business logic
if (ctx.input.amount > 1000) {
decision = "manual_review";
reason = "High amount requires review";
confidence = 0.9;
}
return {
decision,
reason,
confidence,
metadata: {
similarDecisions: insights.length
}
};
}, true) // decision_required = true
.step("issue_refund", async (ctx) => {
if (ctx.state.evaluate_risk?.decision !== "approve") {
return {
decision: "skip",
reason: "Not approved in risk evaluation",
confidence: 1.0
};
}
console.log(`Refunding $${ctx.input.amount} to user ${ctx.input.userId}`);
return {
decision: "completed",
reason: "Refund issued successfully",
confidence: 1.0
};
}, true);
export default refundWorkflow;
Deploy the Workflow
npx ts-node scripts/deploy.ts
This generates Motia steps in motia-atlas/src/refund_v1/ directory.
Execute the Workflow
npx ts-node scripts/execute.ts refund_v1
Or test via Motia Workbench at http://localhost:3000:
- See workflow diagram
- Test API endpoints
- View logs and state in real-time
What Happened?
- Workflow Created: Two steps that execute in sequence
- Memory Integration: First step queries historical decisions
- Decision Making: Each step returns a decision with reason
- Conditional Execution: Second step only runs if first approves
- Deployed to Motia: Workflow converted to Motia steps
- Executed: Workflow ran and decisions were stored in memory
Next Steps
- Creating Workflows - Learn workflow patterns
- Memory Integration - Use memory effectively
- Examples - See more examples