Overview
The Workflow module provides a declarative workflow engine that orchestrates multi-step agent processes. It supports sequential, parallel (fanout), conditional, and loop execution modes with automatic error handling and retry logic.Core Functions
workflow::create
Register a workflow definition with steps and execution modes.The created workflow’s unique identifier
workflow.ts:42
HTTP Endpoint: POST /api/workflows (requires authentication)
workflow::run
Execute a workflow with input data.The workflow identifier to execute
Initial input data for the workflow
Optional agent ID for capability enforcement
agentId is provided, validates agent has capabilities for all workflow steps before execution.
Location: workflow.ts:61
HTTP Endpoint: POST /api/workflows/run (requires authentication)
workflow::list
List all registered workflow definitions.Array of workflow definitions
workflow.ts:302
HTTP Endpoint: GET /api/workflows (requires authentication)
workflow::runs
List execution history for a specific workflow with pagination.The workflow to query runs for
Maximum results to return (default from safePagination)
Offset for pagination (default: 0)
workflow.ts:314
Workflow Step Modes
Workflow steps support different execution modes for complex orchestration patterns.Sequential Mode
Executes steps one at a time, passing output to the next step as input.- Executes function with current
vars.input - If
outputVaris set, stores result invars[outputVar] - Sets
vars.inputto the output for next step
Fanout Mode
Executes multiple steps in parallel for concurrent processing.- Collects consecutive
fanoutsteps into a batch - Executes all fanout steps in parallel using
Promise.all() - Stores array of results in
vars.__fanout - Individual results stored in their respective
outputVarfields
Collect Mode
Collects and processes results from a previous fanout operation.- Receives
vars.__fanoutarray from previous fanout steps - Passes fanout results to function via
fanoutResultsparameter - Typically used to aggregate/merge parallel results
Conditional Mode
Executes step only if a condition is met (simple substring matching).- Checks if previous step’s output contains
conditionstring (case-insensitive) - If condition not met, step is skipped (result marked as “skipped”)
- If condition met, executes normally
Loop Mode
Repeats a step until a condition is met or max iterations reached.- Executes function repeatedly up to
maxIterations(default: 10) - Passes current
iterationnumber to function - Updates
vars.inputandoutputVaron each iteration - Stops early if output contains
untilstring (case-insensitive)
Error Handling Modes
Each step can specify how to handle errors:Fail Mode (default)
- Stops workflow execution immediately on error
- Marks workflow run as “failed”
- Throws the error
Skip Mode
- Logs error in step result but continues workflow
- Sets step output to
null - Useful for optional steps or graceful degradation
Retry Mode
- Retries step up to
maxRetriestimes (default: 3) - If all retries fail, marks workflow as failed
- Useful for transient failures (network errors, rate limits)
WorkflowStep Interface
StepResult Interface
Template Interpolation
Workflow steps support variable interpolation inpromptTemplate using {{variable}} syntax:
{{input}}- Current input value{{__fanout}}- Array of fanout results{{variableName}}- Any variable stored viaoutputVar- Non-existent variables remain as
{{name}}
workflow.ts:355
Complete Workflow Example
HTTP Endpoints
POST /api/workflows→workflow::create(requires auth)GET /api/workflows→workflow::list(requires auth)POST /api/workflows/run→workflow::run(requires auth)
requireAuth() middleware for security.