Skip to main content
WorkflowKit selects the workflow engine and exposes a unified lifecycle. The default engine is legacy (the in-memory engine); world runs on the Vercel Workflow SDK with a durable Postgres/MongoDB backend (requires the optional @ai_kit/workflow-world package).

WorkflowKitOptions

WorldConfig

Construction

The constructor validates the config:
  • engine: "world" without a world config throws.
  • An unknown world.type throws.
  • engine: "legacy" with a world config is allowed (lets you toggle engines via an env var without rewriting config).

Properties

Methods

start()

Starts the durable world worker (lazily loading @ai_kit/workflow-world and creating the adapter). No-op when engine === "legacy", so the same lifecycle code works for both engines. Throws a clear error if @ai_kit/workflow-world is not installed.

stop()

Gracefully stops the world worker. No-op when engine === "legacy" or when the world was never started.

run(workflow, input, dispatch?)

Dispatches to the configured engine (overridable per call via dispatch.engine).
  • legacy → delegates to Workflow.run(options) and returns a WorkflowRunResult.
  • world → delegates to the SDK’s start(fn, args) and returns a WorldRunHandle (durable; the output is not returned directly — see runAndWait / returnValue).

runAndWait(workflow, input, dispatch?)

Runs a workflow and resolves with its output, synchronous-style, regardless of engine — the closest match to the legacy await workflow.run() then .result.
Throws on failure (so wrap it where legacy code read result.status):
  • legacy → throws when the result status is not "success" (with the run error);
  • world → rejects via the SDK (WorkflowRunFailedError / WorkflowRunCancelledError).

WorldRunHandle<TResult>

The handle returned by a world run (pass-through of the SDK Run). Use it when you want to start now and consume later: Reconstitute a handle later from a stored id with getRun(runId) from workflow/api.

Example

See the World engine guide for installation, authoring rules, and migration.