Workflow Execution Skill
This skill provides detailed guidance for executing Mermaid-based multi-agent workflows.
When to Use
Use this skill when you need to:
- Execute a workflow defined in a Markdown file
- Understand how to parse workflow structure
- Handle complex control flows (parallel, conditional, loops)
- Manage workflow state
Workflow File Structure
A workflow file contains three sections:
1. YAML Frontmatter
---
id: "workflow-id"
name: "Workflow Name"
entrypoint: "start_node"
state:
input: ""
result: null
config:
timeout: 300000
maxIterations: 50
---
2. Mermaid Flowchart
flowchart TD
start[Start] --> process[Process]
process -->|success| end_node[End]
process -->|retry| start
3. Node Definitions
### node_id
---
description: "What this node does"
mode: subagent
model: anthropic/claude-sonnet-4-20250514
tools:
read: true
input:
data: "{{state.input}}"
output:
key: "result_key"
---
Agent prompt content here...
Use {{state.variable}} for template variables.
Execution Steps
Step 1: Load and Parse
- Read the workflow Markdown file
- Extract YAML frontmatter
- Identify the Mermaid flowchart section
- Parse each
### node_idsection
Step 2: Build Graph Understanding
From the Mermaid flowchart, understand:
- All node IDs and their shapes (Agent
[]vs Human{{}}) - Edge connections and their labels
- Parallel branches (multiple edges from one node)
- Merge points (multiple edges to one node)
- Loops (edges pointing backwards)
Step 3: Initialize State
state = {
// Copy from frontmatter.state
...initialState,
// Internal tracking
_workflow_id: id,
_current_node: entrypoint,
_completed_nodes: [],
_pending_parallel: [],
_iteration_count: 0
}
Step 4: Execute Nodes
For each node:
Agent Node ([name]):
- Get node config and prompt
- Replace template variables in prompt
- Call Task tool with prepared prompt
- Store output:
state[output.key] = result - Add to
_completed_nodes
Human Node ({{name}}):
- Get node config and options
- Replace template variables in display content
- Call Question tool with options
- Store choice:
state[output.key] = user_choice - Add to
_completed_nodes
Step 5: Determine Next Node
| Scenario | Detection | Action |
|---|---|---|
| Sequential | One unlabeled outgoing edge | Execute target |
| Parallel | Multiple unlabeled outgoing edges | Execute ALL targets together |
| Conditional | Labeled outgoing edges | Match output to label |
| Merge | Multiple incoming edges | Wait for all upstream |
| Loop | Edge to earlier node | Check iteration count |
| End | No outgoing edges | Complete workflow |
Step 6: Handle Parallel Execution
When parallel:
- Launch all target nodes using multiple Task calls in one response
- Track in
_pending_parallel - As each completes, move to
_completed_nodes - Proceed to merge only when all complete
Step 7: Handle Conditionals
- Get the output from previous node
- Match against edge labels
- If match found, follow that edge
- If no match, use
defaultlabel if exists - If no default, report error
Step 8: Handle Loops
- Detect loop by edge pointing to earlier node
- Increment
_iteration_count - Check against
maxIterations - If exceeded, exit loop with warning
Template Variables
| Syntax | Meaning |
|---|---|
{{state.key}} |
Value from state |
{{state.a.b}} |
Nested state value |
{{output}} |
Previous node output |
{{nodes.id.output}} |
Specific node output |
Error Handling
- Node Failure: Check for retry config, apply backoff
- Missing Node: Report error, check for
onErrorhandler - Infinite Loop: Stop at
maxIterations - Timeout: Respect workflow and node timeouts
Best Practices
- Use TodoWrite to track execution progress
- Log which branch is taken at conditionals
- Clearly report parallel execution status
- Summarize results when workflow completes
- Handle errors gracefully with clear messages
Converted and distributed by TomeVault — claim your Tome and manage your conversions.