config/ folder. Each agent type has its own configuration file.
| File | Agent Type | Purpose |
|---|---|---|
main.agents.js | Main agents | Core workflow steps |
modules.js | Modules | Agents with loop behavior |
sub.agents.js | Sub-agents | Delegated tasks spawned by main agents |
Controllers are defined in
main.agents.js with role: 'controller'. They’re main agents with special orchestration capabilities.Main Agents
Main agents are the core building blocks of your workflow. Each main agent runs as a step in the workflow sequence.Basic Structure
config/main.agents.js
Agent Fields
| Field | Required | Description |
|---|---|---|
id | Yes | Unique identifier (lowercase, hyphens) |
name | Yes | Display name shown in UI |
description | Yes | Brief description of what the agent does |
promptPath | Yes | Path or array of paths to prompt files |
chainedPromptsPath | No | Array of chained prompt paths (multi-step agents) |
role | No | Set to 'controller' for controller agents only |
engine | No | AI engine to use (defaults to workflow default) |
model | No | AI model to use (defaults to engine default) |
tracks | No | Array of track IDs this agent runs for |
conditions | No | Array of condition IDs (runs when ALL are selected) |
conditionsAny | No | Array of condition IDs (runs when ANY is selected) |
Prompt Path: String vs Array
ThepromptPath field accepts either a single path or an array of paths.
- String (Single File)
- Array (Multiple Files)
One prompt file loaded as the agent’s instructions.
promptPath array = Files merged into one prompt, shown at once.chainedPromptsPath = Separate prompts injected sequentially, one after another with user interaction between each.
When to Use Array promptPath
| Use Case | Example |
|---|---|
| Organizing large prompts | Split persona, instructions, and examples into separate files |
| Reusing prompt components | Share common instructions across agents |
| Maintaining readability | Keep individual files focused and manageable |
Single-Step vs Multi-Step
Agents can be single-step or multi-step based on whether they have chained prompts.- Single-Step
- Multi-Step
One prompt file, injected once. Best for focused tasks.
When to Use Each
| Type | Use When |
|---|---|
| Single-step | Focused tasks, smaller prompts, minimal context needed |
| Multi-step | Q&A flows, progressive context building, conversational agents |
Multi-step agents maintain the same session throughout all steps. The agent remembers everything from previous steps.
Modules
Modules are main agents with loop behavior. They can send the workflow back to earlier steps, creating validation gates and iteration cycles.Module Structure
config/modules.js
Module Fields
In addition to standard agent fields, modules have:| Field | Required | Description |
|---|---|---|
behavior.type | Yes | Must be 'loop' |
behavior.action | Yes | Must be 'stepBack' |
How Modules Control Flow
Modules communicate with the workflow by writing to a directive file when validation fails:Writing Module Prompts
Learn how to write prompts that instruct modules to validate and write directives
Workflow Signals MCP
Configure MCP for directive-based workflow control
Common Module Patterns
Validation Loop
Validation Loop
Check work quality, fix issues, re-check until passing.
Review Cycle
Review Cycle
Review output, request changes, iterate until approved.
Quality Gate
Quality Gate
Block progression until quality threshold is met.
Workflow File Options
When using modules in your workflow file, you can configure loop behavior:Sub-Agents
Sub-agents are helper agents that main agents can spawn during execution. They run as separate sessions and return results to the calling agent.When to Use Sub-Agents
- Delegating specialized subtasks
- Parallel task execution
- Context isolation for specific work
- Reusable agent capabilities
Sub-Agent Types
- Static
- Dynamic
Pre-defined prompt file. You define the prompt at build time.
config/sub.agents.js
Why Sub-Agent Prompts Live in .codemachine/
Unlike main agents whose prompts are in the prompts/ folder, sub-agent prompts live in the runtime .codemachine/agents/ folder. This design enables:
- Dynamic prompt generation - A main agent (like an
agent-builder) can write prompts for sub-agents at runtime - Cross-agent access - Other agents can read and modify sub-agent prompts during workflow execution
- Flexibility - Use static prompts via
mirrorPath, or leave it empty for fully dynamic sub-agents that receive instructions when invoked
codemachine run command for direct execution.
Sub-Agent Fields
| Field | Required | Description |
|---|---|---|
id | Yes | Unique identifier |
name | Yes | Display name |
description | Yes | What the sub-agent does |
mirrorPath | Static only | Path to pre-defined prompt file |
Invoking Sub-Agents
Sub-agents must be invoked via MCP tools or CLI commands. Example orchestrator with agent-coordination MCP:main.agents.js
Writing Sub-Agent Prompts
Learn how to write prompts for agents that orchestrate sub-agents
Agent Coordination MCP
Configure MCP for sub-agents
CLI Reference
Run sub-agents via CLI
Full Example
See complete workflow
Controllers
Controllers are special agents that orchestrate autonomous workflows. They respond on behalf of the user, driving the entire workflow. Controllers requirerole: 'controller' and must be configured with the workflow-signals MCP to approve step transitions.
Example controller and step agent with workflow-signals MCP:
main.agents.js
Built-in MCP Servers
CodeMachine provides built-in MCP servers for agent coordination and workflow control. Configure these on your agents using themcp field.
MCP Configuration Fields
| Field | Description |
|---|---|
server | The MCP server name ('workflow-signals' or 'agent-coordination') |
only | Array of tool names to expose (limits available tools) |
targets | Array of sub-agent IDs that can be invoked (agent-coordination only) |
Workflow Signals
Controllers and step agents communicate through theworkflow-signals MCP. Step agents propose completion, and the controller approves or rejects.
- Controller Agent
- Step Agents
The controller approves or rejects step transitions.
| Tool | Description |
|---|---|
approve_step_transition | Accept or reject a step’s completion proposal |
get_pending_proposal | Read the current pending proposal from a step |
See Autonomous Example
View a complete autonomous workflow with controller and step agents
Agent Coordination
Main agents or controllers that orchestrate sub-agents need theagent-coordination MCP configured.
| Tool | Description |
|---|---|
list_available_agents | Discover available sub-agents |
run_agents | Execute sub-agent scripts |
get_agent_status | Check execution status |
list_active_agents | See currently running agents |
See Sub-Agent Example
View a complete workflow using sub-agents with agent-coordination MCP
Agent Characters
Agent characters give your agents visual personality in the CLI. Each agent can have custom ASCII faces and phrases.Character Configuration
config/agent-characters.json
Pre-built Styles
| Style | Base Face | Best For |
|---|---|---|
swagger | (⌐■_■) | Cool, confident agents |
friendly | (˶ᵔ ᵕ ᵔ˶) | Warm, helpful agents |
analytical | [•_•] | Logical, precise agents |
cheerful | ◕‿◕ | Upbeat, positive agents |
technical | {•_•} | Developer-focused agents |
precise | <•_•> | Validation, QA agents |
Custom Characters
Create custom characters by defining all expressions and phrases:If no character is defined for an agent, it falls back to the
swagger character.Engine & Model
Each agent can use a different AI engine and model. Configureengine and model fields to optimize for your use case.
Model Configuration
See available engines, model options, reasoning effort, and fallback system
Track & Condition Filtering
Filter when agents run based on user-selected tracks and conditions.Agent-Level Filtering
Control when an entire agent runs:Step-Level Filtering
For multi-step agents, filter individual steps:Filtering Rules
- Both track AND conditions must match if both are specified
- Empty arrays = always runs/loads
- Agent-level filtering is checked first, then step-level
Complete Example
Here’s a completemain.agents.js with multiple agent types:
config/main.agents.js