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
engine: "world"without aworldconfig throws.- An unknown
world.typethrows. engine: "legacy"with aworldconfig is allowed (lets you toggle engines via an env var without rewriting config).
Properties
Methods
start()
@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()
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 toWorkflow.run(options)and returns aWorkflowRunResult.world→ delegates to the SDK’sstart(fn, args)and returns aWorldRunHandle(durable; the output is not returned directly — seerunAndWait/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.
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.