Execution API
execution.getId()
Gets the execution ID.
execution.getId(): string
Returns: string - Execution ID
execution.getState()
Gets the current workflow state.
execution.getState(): Record<string, any>
Returns: Record<string, any> - State from all steps
Example:
const state = execution.getState();
console.log(state.evaluate_risk?.decision);
execution.getStepResults()
Gets results from all steps.
execution.getStepResults(): Map<string, StepDecision>
Returns: Map<string, StepDecision> - Step results
Example:
const results = execution.getStepResults();
const riskDecision = results.get("evaluate_risk");
console.log(riskDecision?.decision);
execution.getMetadata()
Gets execution metadata.
execution.getMetadata(): ExecutionMetadata
Returns: ExecutionMetadata - Execution metadata
Example:
const metadata = execution.getMetadata();
console.log(metadata.status);
console.log(metadata.startedAt);
execution.pause()
Pauses the execution.
execution.pause(reason: string): Promise<void>
Parameters:
reason(string) - Reason for pausing
Returns: Promise<void>
Example:
await execution.pause("Manual review required");
execution.resume()
Resumes a paused execution.
execution.resume(resumeData?: Record<string, any>): Promise<void>
Parameters:
resumeData(Record<string, any>, optional) - Data to resume with
Returns: Promise<void>
Example:
await execution.resume({ approved: true });
execution.replay()
Replays the execution with different options.
execution.replay(options: ReplayOptions): Promise<Execution>
Parameters:
options(ReplayOptions) - Replay options
Returns: Promise<Execution> - New execution instance
ReplayOptions:
interface ReplayOptions {
mode: "exact" | "policy-aware" | "memory-informed";
overrides?: Record<string, any>;
fromStep?: string;
skipSteps?: string[];
}
Example:
// Exact replay
const replayed = await execution.replay({ mode: "exact" });
// Policy-aware replay
const replayed = await execution.replay({
mode: "policy-aware",
overrides: { policyVersion: "v2" }
});
// Memory-informed replay
const replayed = await execution.replay({ mode: "memory-informed" });
execution.linkOutcome()
Links an outcome to the execution.
execution.linkOutcome(outcome: Outcome): Promise<void>
Parameters:
outcome(Outcome) - Outcome data
Outcome:
interface Outcome {
success: boolean;
data?: any;
timestamp?: string;
}
Returns: Promise<void>
Example:
await execution.linkOutcome({
success: true,
data: { refundId: "ref_123" }
});
ExecutionMetadata
interface ExecutionMetadata {
id: string;
workflowId: string;
status: "running" | "completed" | "paused" | "failed";
startedAt: string;
completedAt?: string;
pausedAt?: string;
pausedReason?: string;
}
Complete Example
// Execute workflow
const execution = await workflow.execute({ userId: "u123", amount: 100 });
// Get execution ID
const id = execution.getId();
// Get state
const state = execution.getState();
console.log("State:", state);
// Get step results
const results = execution.getStepResults();
results.forEach((decision, stepName) => {
console.log(`${stepName}: ${decision.decision}`);
});
// Pause execution
await execution.pause("Manual review");
// Resume execution
await execution.resume({ approved: true });
// Replay with different policy
const replayed = await execution.replay({
mode: "policy-aware",
overrides: { policyVersion: "v2" }
});
// Link outcome
await execution.linkOutcome({
success: true,
data: { result: "success" }
});
Next Steps
- Workflow API - Workflow methods
- Memory API - Memory interface
- Replay Modes - Learn about replay