Overview
createWorld() creates a workflow runtime instance that handles state management, event sourcing, and infrastructure integration. The world abstraction allows workflows to run on different backends (Vercel, local development, or custom implementations).
Usage
getWorld() to access the current world instance instead.
Signature
World - A world instance configured for the current environment
Environment Detection
The world type is automatically determined by:WORKFLOW_TARGET_WORLDenvironment variable (explicit override)VERCEL_DEPLOYMENT_IDpresence (automatic Vercel detection)- Default: Local development mode
Vercel World
Automatically used when deployed to Vercel or whenWORKFLOW_TARGET_WORLD=vercel.
Environment Variables:
string
Vercel API authentication token
string
Vercel project ID (e.g.,
prj_xxx)string
Vercel project slug (e.g.,
my-app)string
Target environment:
production, preview, or developmentstring
Vercel team ID (optional, for team projects)
Local World
Used for local development whenWORKFLOW_TARGET_WORLD=local or when no Vercel environment is detected.
Environment Variables:
string
Directory for storing workflow state (defaults to
.workflow-data)Custom World
You can implement a custom world by settingWORKFLOW_TARGET_WORLD to a module path:
- Default function returning a
Worldinstance - Named
createWorldfunction
World Interface
TheWorld interface provides access to workflow infrastructure:
Related Functions
getWorld()
Retrieves the singleton world instance, creating it if necessary.setWorld()
Replaces the cached world instance. Useful for testing.World | undefined
The world instance to use, or
undefined to clear the cachegetWorldHandlers()
Retrieves world handlers needed at build time without full initialization.Examples
Basic Usage
Testing with Custom World
Vercel Deployment
Custom World Implementation
Type Definitions
WorkflowRun
Event
Best Practices
- Use getWorld() instead of createWorld(): The singleton pattern ensures consistency
- Environment-specific configuration: Use environment variables for different deployments
-
Don’t cache world references: Always call
getWorld()to get the current instance - Test with local world: Use local world for development and testing
- Custom worlds for special cases: Implement custom worlds for unique infrastructure needs