Skip to main content

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

The world is automatically created based on environment variables and typically doesn’t need to be manually instantiated in application code. Use getWorld() to access the current world instance instead.

Signature

Returns: World - A world instance configured for the current environment

Environment Detection

The world type is automatically determined by:
  1. WORKFLOW_TARGET_WORLD environment variable (explicit override)
  2. VERCEL_DEPLOYMENT_ID presence (automatic Vercel detection)
  3. Default: Local development mode

Vercel World

Automatically used when deployed to Vercel or when WORKFLOW_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 development
string
Vercel team ID (optional, for team projects)

Local World

Used for local development when WORKFLOW_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 setting WORKFLOW_TARGET_WORLD to a module path:
The module must export one of:
  • Default function returning a World instance
  • Named createWorld function

World Interface

The World interface provides access to workflow infrastructure:

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 cache

getWorldHandlers()

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

  1. Use getWorld() instead of createWorld(): The singleton pattern ensures consistency
  2. Environment-specific configuration: Use environment variables for different deployments
  3. Don’t cache world references: Always call getWorld() to get the current instance
  4. Test with local world: Use local world for development and testing
  5. Custom worlds for special cases: Implement custom worlds for unique infrastructure needs

See Also