Skip to main content

Import

import {
  workflow,
  step,
  parallel,
  branch,
  waitForApproval,
  createWorkflowClient,
} from "veryfront/workflow";

Examples

Simple sequential workflow

import { workflow, step } from "veryfront/workflow";

const pipeline = workflow({
  id: "summarize",
  steps: () => [
    step("fetch", { tool: "webScraper" }),
    step("summarize", { agent: "writer" }),
  ],
});

Parallel steps and human-in-the-loop

import { workflow, step, parallel, branch, waitForApproval } from "veryfront/workflow";

const contentPipeline = workflow({
  id: "content-pipeline",
  steps: ({ input }) => [
    step("research", { agent: "researcher" }),
    parallel("generate", [
      step("write", { agent: "writer" }),
      step("images", { tool: "imageGenerator" }),
    ]),
    branch("review", {
      condition: () => input.requiresApproval,
      then: [waitForApproval("human-review", { timeout: "24h" })],
    }),
    step("publish", { agent: "publisher" }),
  ],
});

API

workflow(options)

Define workflow with step DAG
PropertyTypeDescription
idstringUnique workflow identifier
description?stringHuman-readable description
version?stringSemantic version string
inputSchema?z.ZodSchema<TInput>Zod schema for workflow input validation
outputSchema?z.ZodSchema<TOutput>Zod schema for workflow output validation
retry?RetryConfigRetry configuration for failed steps
timeout?`string \number`Max execution time (ms)
introspect?booleanEnable runtime introspection for debugging
stepsWorkflowNode[] | ((context: StepBuilderContext<TInput>) => WorkflowNode[])Workflow step definitions
onError?(error: Error, context: WorkflowContext) => void | Promise<void>Error handler called when a step fails
onComplete?(result: TOutput, context: WorkflowContext) => void | Promise<void>Callback fired after workflow completes
Returns: Workflow<TInput, TOutput>

Type Reference

StepOptions

step() options
PropertyTypeDescription
agent?`string \Agent`Agent to run (by ID or instance)
tool?`string \Tool`Tool to execute (by ID or instance)
input?string | Record<string, unknown> | ((context: WorkflowContext) => unknown)Step input: static value or function of workflow context
checkpoint?booleanPersist state after this step
retry?RetryConfigRetry configuration for this step
timeout?`string \number`Step timeout (ms)
skip?(context: WorkflowContext) => boolean | Promise<boolean>Predicate that skips this step if it returns true

BranchOptions

branch() options
PropertyTypeDescription
condition(context: WorkflowContext) => boolean | Promise<boolean>Branch predicate function
thenWorkflowNode[]Steps when condition is true
else?WorkflowNode[]Steps when condition is false
checkpoint?booleanPersist state after this node
retry?RetryConfigRetry configuration
timeout?`string \number`Node timeout (ms or duration string)
skip?(context: WorkflowContext) => boolean | Promise<boolean>Predicate that skips if it returns true

ParallelOptions

parallel() options
PropertyTypeDescription
strategy?`“all” \“race” \“allSettled”`Completion strategy ("all", "race", "allSettled")
checkpoint?booleanPersist state after this node
retry?RetryConfigRetry configuration
timeout?`string \number`Node timeout (ms or duration string)
skip?(context: WorkflowContext) => boolean | Promise<boolean>Predicate that skips if it returns true

Exports

Functions

NameDescription
agentStepStep that runs an agent
branchCreate a conditional branch node.
createWorkflowClientHTTP client for workflow management
dagDefine step dependency graph
delayCreate a simple delay/sleep node.
dependsOnDeclare step dependencies
doWhileExecute once, then repeat while true
generateIdGenerate a unique workflow ID
getWorkflowTenantGet the current workflow tenant context.
hasWorkerSupportCheck worker support
loopRepeat while condition holds
mapMap array items in parallel
parallelCreate a parallel node for concurrent execution of multiple steps.
parseDurationParse duration string to milliseconds
sequenceRun steps sequentially
stepCreate workflow step
subWorkflowCreate a sub-workflow node for nested execution.
timesRepeat N times
toolStepStep that executes a tool
unlessCreate a branch that only executes if condition is false.
useApprovalHandle workflow approval interactions.
useWorkflowTrack workflow status and steps
useWorkflowListList and filter workflow runs.
useWorkflowStartStart workflow from React
waitForApprovalCreate a wait-for-approval node. Pauses until human approves/rejects.
waitForEventCreate a wait-for-event node. Pauses until external event is received.
whenCreate a branch that only executes if condition is true (no else).
workflowDefine workflow with step DAG

Classes

NameDescription
MemoryBackendIn-memory backend (dev)
RedisBackendRedis backend (production)
WorkflowClientWorkflow HTTP client
WorkflowExecutorWorkflow Executor class

Types

NameDescription
BackendConfigBackend base config
BranchOptionsbranch() options
CapturedTenantContextCaptured tenant context for multi-tenant workflow execution.
LoopOptionsloop() / doWhile() options
MapOptionsmap() options
ParallelOptionsparallel() options
RedisAdapterStandardized Redis Adapter Interface
RedisBackendConfigRedis backend configuration
StepOptionsstep() options
SubWorkflowOptionssubWorkflow() options
UseApprovalOptionsuseApproval options
UseApprovalResultuseApproval result
UseWorkflowListOptionsuseWorkflowList options
UseWorkflowListResultuseWorkflowList result
UseWorkflowOptionsuseWorkflow options
UseWorkflowResultuseWorkflow result
UseWorkflowStartOptionsuseWorkflowStart options
UseWorkflowStartResultuseWorkflowStart result
WaitForApprovalOptionswaitForApproval() options
WaitForEventOptionswaitForEvent() options
WorkflowWorkflow instance
WorkflowBackendState storage backend interface
WorkflowClientConfigcreateWorkflowClient() config
WorkflowContextWorkflow context - accumulates node outputs during execution
WorkflowDefinitionWorkflow definition
WorkflowExecutorConfigWorkflow executor configuration
WorkflowHandleHandle for a running workflow
WorkflowNodeWorkflow node
WorkflowNodeConfigUnion of all workflow node configurations
WorkflowOptionsworkflow() options
WorkflowRunWorkflow run state
WorkflowStatusStatus (pending, running, completed, failed)

Constants

NameDescription
apiContext-aware API that automatically uses the current tenant.