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 fromconfig/main.agents.js:
resolveModule
Resolves a module fromconfig/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.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.Workflow Signals MCP
Controllers and step agents communicate through theworkflow-signals MCP. Both must be configured for autonomous mode to work.
- Controller Agent
- Step Agents
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: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 theagent-coordination MCP:
main.agents.js
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:specification: true, CodeMachine prompts for a specification file path at workflow start.
Next Steps
Workflow Examples
See complete real-world workflow examples