API Reference

Complete API documentation for MDWR SDKs (TypeScript and Python).

Core APIs

Workflow API

Create and manage workflows.

Workflow.create(id: string, version?: string): Workflow
workflow.step(name: string, handler: StepHandler, decisionRequired?: boolean): Workflow
workflow.execute(input: any): Promise<Execution>
workflow.deploy(): Promise<void>

Execution API

Manage workflow executions.

execution.getId(): string
execution.getState(): Record<string, any>
execution.getStepResults(): Map<string, StepDecision>
execution.pause(reason: string): Promise<void>
execution.resume(resumeData?: Record<string, any>): Promise<void>
execution.replay(options: ReplayOptions): Promise<Execution>
execution.linkOutcome(outcome: Outcome): Promise<void>

Memory API

Query historical decisions and find similar patterns.

ctx.memory.similar(params: {
  situation: string;
  context?: Record<string, any>;
  crossWorkflow?: string[];
}): Promise<MemoryInsight[]>

ctx.memory.query(params: {
  workflowId?: string;
  stepName?: string;
  decision?: string;
  limit?: number;
}): Promise<StoredDecision[]>

Type Definitions

StepDecision

interface StepDecision {
  decision: string;              // Required
  reason: string;                // Required
  confidence?: number;           // Optional (0-1)
  metadata?: Record<string, any>; // Optional
}

StepContext

interface StepContext {
  input: any;                    // Workflow input
  state: Record<string, any>;    // State from previous steps
  memory: MemoryInterface;       // Memory interface
}

MemoryInsight

interface MemoryInsight {
  decision: {
    decision: string;
    reason: string;
    confidence?: number;
  };
  context: {
    input: any;
    state: any;
    metadata?: any;
  };
  outcome?: {
    success: boolean;
    data?: any;
  };
  similarity: number;        // 0-1 similarity score
  timestamp: string;
  workflowId: string;
  stepName: string;
}

ReplayOptions

interface ReplayOptions {
  mode: "exact" | "policy-aware" | "memory-informed";
  overrides?: Record<string, any>;
  fromStep?: string;
  skipSteps?: string[];
}

Quick Examples

Create and Execute Workflow

import { Workflow } from "@mdwr/sdk";

const workflow = Workflow.create("my_workflow_v1")
  .step("step1", async (ctx) => {
    return {
      decision: "proceed",
      reason: "Step completed",
      confidence: 1.0
    };
  }, true);

await workflow.deploy();
const execution = await workflow.execute({ userId: "u123" });

Query Memory

.step("decide", async (ctx) => {
  const insights = await ctx.memory.similar({
    situation: "my_decision",
    context: ctx.input
  });
  
  if (insights.length > 0) {
    const best = insights[0];
    return {
      decision: best.decision.decision,
      reason: best.decision.reason,
      confidence: best.decision.confidence
    };
  }
  
  return {
    decision: "default",
    reason: "No similar decisions found",
    confidence: 0.5
  };
}, true)

Replay Execution

const execution = await workflow.execute({ amount: 1000 });

const replayed = await execution.replay({
  mode: "policy-aware",
  overrides: { policyVersion: "v2" }
});

Language Support

MDWR provides identical APIs for:

Both SDKs produce identical behavior and results.

Next Steps