Overview
Stepkit supports checkpoint-based workflows that can pause at any step, store their state, and resume later. This is perfect for human-in-the-loop workflows like approval systems, review queues, or multi-stage processes.How Checkpoints Work
Checkpoints capture the complete state of a pipeline at a specific step, including:- All context data accumulated so far
- The pipeline structure and remaining steps
- The exact position in the execution
Basic Checkpoint Usage
Checkpoints are emitted via theonStepComplete callback during pipeline execution.
Checkpoints are Base64-encoded strings containing the serialized pipeline state. Store them in a database, cache, or queue system.
Human Approval Flow
This example shows a complete approval workflow where an AI generates a draft email, pauses for human approval, then sends it when approved.Implementation Details
Pause for Approval
When
generate completes, onStepComplete saves the checkpoint and calls e.stopPipeline() to halt execution.Store Checkpoint
The checkpoint is stored in a key-value store (database, Redis, etc.) with a unique approval ID.
Key Methods
onStepComplete
onStepComplete
Callback fired after each step completes. Receives an event object with:
stepName: The name of the completed stepcheckpoint: Base64 checkpoint stringstopPipeline(): Method to halt execution immediatelycontext: Current context data
runCheckpoint
runCheckpoint
Resumes a pipeline from a checkpoint. Accepts:
checkpoint: The checkpoint string to resume fromoverrideData(optional): Shallow merge additional data into the context
stopPipeline
stopPipeline
Call this in
onStepComplete to stop execution after the current step. The pipeline returns the current context without running remaining steps.Real-World Use Cases
Content Review
Generate blog posts or social media content, pause for editorial review, publish when approved
Payment Approval
Process orders up to a threshold automatically, require manager approval for large amounts
Customer Support
AI drafts responses, human agents review and approve before sending to customers
Data Changes
Stage database migrations or configuration changes, require approval before applying
Best Practices
Checkpoint Storage
Choose a storage backend based on your requirements:- Redis: Fast, in-memory, with TTL support
- Database: Persistent, queryable, with audit trails
- S3/Object Storage: For long-term retention or large contexts
- Job Queue: Built-in checkpoint support in systems like BullMQ
Error Handling
Always handle missing or invalid checkpoints:Override Data
When resuming, you can override context data. This is useful for:- Adding human review comments
- Updating timestamps
- Modifying generated content before continuing
Related
AI Workflows
Combine approvals with AI generation workflows
Content Moderation
Use branching logic before requesting approval