Skip to main content
This guide covers advanced workflow features: step types, configuration options, tracks, conditions, modules, and controllers.

Workflow Definition

The workflow definition file (.workflow.js) is the core of your package. It defines what happens when someone runs your workflow.

Minimum Workflow

A workflow only needs steps to run:
example.workflow.js

Full Structure

example.workflow.js

Step Functions

Three functions are available globally in workflow files:

resolveStep

Resolves a main agent from config/main.agents.js:

resolveModule

Resolves a module from config/modules.js with loop behavior:

separator

Creates a visual phase separator in the workflow timeline:

controller

Defines a controller agent for autonomous execution:

Step Options

Configure how each step behaves:

Engines

Examples


Module Options

Modules extend step options with loop behavior:
Modules are agents that can loop back to earlier steps. Use them for review cycles or iterative refinement until a condition is met.

Tracks

Tracks let users choose different workflow paths. Only one track can be selected at runtime.
Use tracks when you have mutually exclusive paths that significantly change the workflow.

Track-Filtered Steps


Condition Groups

Conditions are feature toggles that enable or disable specific steps. Unlike tracks, multiple conditions can be selected.

Nested Conditions

Conditions can have children that appear based on parent selection:

Track-Specific Conditions

Condition groups can be limited to specific tracks:

Condition-Filtered Steps

Use conditions when ALL listed conditions must be selected. Use conditionsAny when ANY of the listed conditions enables the step.

Controllers

Controllers are special agents that drive workflows autonomously. They can approve step transitions without user input.
Controllers are in beta. The workflow can still run without a controller in manual mode.

Workflow Signals MCP

Controllers and step agents communicate through the workflow-signals MCP. Both must be configured for autonomous mode to work.
The controller approves or rejects step transitions.
main.agents.js

See Autonomous Example

View a complete autonomous workflow with controller and step agents

Autonomous Mode

Control how the workflow runs:
Use true or false for most workflows - this gives users flexibility to switch modes. Use 'always' or 'never' only when you want to lock the mode.

Sub-Agents

Sub-agents are helper agents that main agents can invoke for specialized tasks. Both the workflow and main agent must be configured.

Workflow Configuration

Declare available sub-agents in your workflow file:
example.workflow.js

Agent Coordination MCP

The main agent that orchestrates sub-agents needs the agent-coordination MCP:
main.agents.js
Both subAgentIds in the workflow and agent-coordination MCP on the main agent must be configured for sub-agent orchestration to work.
Sub-agents are defined in config/sub.agents.js.

See Sub-Agent Example

View a complete workflow using sub-agents

Specification Mode

Enable specification mode to require a spec file before running:
When specification: true, CodeMachine prompts for a specification file path at workflow start.

Next Steps

Workflow Examples

See complete real-world workflow examples