| name | stage4-flowchart-generation |
| description | Generate Mermaid flowcharts from Stage 3 SOP documents and convert to SVG images. Visualizes customer support processes with color-coded decision trees. **Language:** Auto-detects Korean (ํ๊ตญ์ด) or Japanese (ๆฅๆฌ่ช) from user input. |
| type | anthropic-skill |
| version | 1.0 |
Stage 4: Flowchart Generation
Overview
This SOP guides the automatic generation of Mermaid flowcharts from SOP documents created in Stage 3. This is Stage 4 (optional enhancement stage) of the Userchat-to-SOP pipeline, performed by the AI agent using natural language analysis and Mermaid diagram generation.
Language: Detect the language from the user's first message and respond in that language throughout. Support Korean (ํ๊ตญ์ด) and Japanese (ๆฅๆฌ่ช). Default to Korean if language is unclear.
Stage Flow:
Input: Stage 3 SOP documents (03_sop/*.sop.md)
โ
Process: AI analysis of SOP structure
โ
Generate: Mermaid flowchart syntax
โ
Convert: SVG image generation (mmdc CLI)
โ
Output: Flowchart Markdown + SVG files
Total Time: ~4 minutes (typical, depends on number of SOPs)
Parameters
Required
- sop_dir: Directory containing Stage 3 SOP files
- Example:
results/{company}/03_sop
- Must contain
.sop.md files
Optional
-
output_dir (default: derived from sop_dir as {sop_dir}/../04_flowcharts): Directory to save flowchart files. Defaults to a sibling 04_flowcharts/ directory next to 03_sop/.
-
mode (default: "standard"): Flowchart generation depth mode
"quick": Simple flowcharts (5-10 nodes), basic decision tree only
"standard": Balanced flowcharts (15-30 nodes), main process flows (default)
"deep": Detailed flowcharts (30+ nodes), full process with all edge cases
-
target_sops (default: "all"): Which SOPs to generate flowcharts for
"all": Generate for all SOPs (both TS and HT)
"ts_only": Only Troubleshooting SOPs (recommended for complex processes)
"ht_only": Only How-To SOPs
- List:
["TS_001", "HT_002"] - Specific SOP IDs
-
output_format (default: "both"): Output file format
"markdown": Mermaid markdown only
"svg": SVG image only
"both": Both markdown and SVG (recommended)
-
color_scheme (default: "status"): Color coding strategy
"status": Success (green), Warning (yellow), Error (red), Info (blue)
"priority": High/Medium/Low priority
"none": No color coding
Steps
1. Validate Inputs
Verify Stage 3 SOP files and Mermaid CLI installation.
Actions:
- Check
sop_dir exists and contains .sop.md files
- Derive
output_dir if not provided: {sop_dir}/../04_flowcharts (e.g., results/{company}/04_flowcharts)
- Create output directory:
mkdir -p {output_dir}
- Verify Mermaid CLI is installed:
mmdc --version
- If CLI not installed:
- โ ๏ธ Warn user that SVG generation will be skipped
- Automatically adjust output_format to "markdown" only
- Continue with Mermaid markdown generation
- Count number of SOPs to process
- Filter by target_sops parameter
Expected Output (CLI installed):
โ
Stage 4 ์ค๋น ์๋ฃ
- SOP ๋๋ ํ ๋ฆฌ: results/{company}/03_sop
- ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ: results/{company}/04_flowcharts (์์ฑ๋จ)
- ๋ฐ๊ฒฌ๋ SOP: 7๊ฐ (TS: 4๊ฐ, HT: 3๊ฐ)
- ์ฒ๋ฆฌ ๋์: 7๊ฐ (์ ์ฒด) ๋๋ 4๊ฐ (TS๋ง) ๋๋ 3๊ฐ (HT๋ง)
- Mermaid CLI: ์ค์น๋จ (v11.12.0)
- ์ถ๋ ฅ ํ์: Markdown + SVG
Expected Output (CLI not installed):
โ
Stage 4 ์ค๋น ์๋ฃ
- SOP ๋๋ ํ ๋ฆฌ: results/{company}/03_sop
- ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ: results/{company}/04_flowcharts (์์ฑ๋จ)
- ๋ฐ๊ฒฌ๋ SOP: 7๊ฐ (TS: 4๊ฐ, HT: 3๊ฐ)
- ์ฒ๋ฆฌ ๋์: 7๊ฐ (์ ์ฒด) ๋๋ 4๊ฐ (TS๋ง) ๋๋ 3๊ฐ (HT๋ง)
- Mermaid CLI: โ ๋ฏธ์ค์น
- ์ถ๋ ฅ ํ์: Markdown๋ง (SVG ์์ฑ ๊ฑด๋๋)
โ ๏ธ SVG ์ด๋ฏธ์ง๊ฐ ํ์ํ๋ฉด ๋์ค์ ์ค์น ํ ๋ณํ ๊ฐ๋ฅ:
npm install -g @mermaid-js/mermaid-cli
mmdc -i TS_001_FLOWCHART.md -o TS_001_flowchart.svg -b transparent
2. Analyze SOP Structure
For each target SOP, analyze structure to extract flowchart components.
Actions:
- Read SOP file
- Identify SOP type (TS or HT)
- TS (Troubleshooting): Focus on decision trees and problem resolution paths
- HT (How-To): Focus on sequential steps and process flows
- Extract "์ผ์ด์ค 1, 2, 3..." sections or step sequences
- Parse decision logic and branches
- Identify escalation criteria
Expected Duration: 1-2 minutes per SOP
3. Generate Mermaid Flowchart
Convert analyzed structure into Mermaid flowchart syntax.
You MUST read templates/FLOWCHART_template.md before generating any flowchart.
This template defines the official color scheme (classDef), node shapes, naming conventions, and quality checklist.
Key rules from the template:
- Use
classDef for color coding (NOT inline style per node):
classDef successClass fill:#d4edda,stroke:#28a745,stroke-width:2px
classDef warningClass fill:#fff3cd,stroke:#ffc107,stroke-width:2px
classDef dangerClass fill:#f8d7da,stroke:#dc3545,stroke-width:2px
classDef infoClass fill:#d1ecf1,stroke:#17a2b8,stroke-width:2px
classDef processClass fill:#e7f3ff,stroke:#0056b3,stroke-width:2px
classDef apiClass fill:#fff0c0,stroke:#e6a817,stroke-width:2px,stroke-dasharray:5 5
- Apply classes with
class NodeA,NodeB successClass at the end of the diagram
- Node shapes:
([...]) start/end, {...} decision, [...] process, [[...]] API call nodes
- API call nodes: Represent steps that actually call an external API as
[[API Name<br>Return field check]] and apply apiClass (dashed yellow border)
- No double-quotes inside node labels โ use
<br/> for line breaks
- Keep node text โค 15 characters per line
Mode-Specific Behavior:
- Quick Mode: Simple (5-10 nodes), main paths only
- Standard Mode: Balanced (15-30 nodes), all standard cases (default)
- Deep Mode: Comprehensive (30+ nodes), all edge cases and escalation paths
Expected Duration:
- Quick: 1-2 minutes per SOP
- Standard: 2-3 minutes per SOP
- Deep: 3-5 minutes per SOP
4. Create Flowchart Markdown File
Write complete flowchart documentation following templates/FLOWCHART_template.md structure exactly.
Save each flowchart file to {output_dir}/{SOP_ID}_FLOWCHART.md (NOT inside the sop_dir).
You MUST use this section order:
# [{SOP ํ์ผ๋ช
}] Flowchart
## ์๋ด ํ๋ฆ๋
```mermaid
flowchart TD
...
classDef successClass ...
classDef warningClass ...
classDef dangerClass ...
classDef infoClass ...
classDef processClass ...
class ... successClass
class ... warningClass
...
์ผ์ด์ค๋ณ ์ค๋ช
๐ข ์ ์ ์ฒ๋ฆฌ (์ด๋ก์)
- ์ผ์ด์ค N: {์ค๋ช
} โ ์๋ํ ๊ฐ๋ฅ: {X}% ({ํด๊ฒฐ ๊ธฐ์ : RAG/Action/Rules})
๐ก ์ฃผ์ ํ์ / ์กฐ๊ฑด๋ถ ์ฒ๋ฆฌ (๋
ธ๋์)
๐ด ๋ด๋นํ ์ ๋ฌ / ์์ค์ปฌ๋ ์ด์
(๋นจ๊ฐ์)
๐ต ์์ฌ๊ฒฐ์ ํฌ์ธํธ (ํ๋์)
โ๏ธ ์ ๋ณด ํ์ธ ๋จ๊ณ (์ฐํ ํ๋์)
์ฃผ์ ์ฒดํฌํฌ์ธํธ
| ๋จ๊ณ | ํ์ธ ์ฌํญ | ๋๊ตฌ/๋ฐฉ๋ฒ |
|---|
| 1๏ธโฃ ... | ... | ... |
| ... | | |
๋ด๋นํ ์ ๋ฌ ๊ธฐ์ค โ TS SOP์๋ง ํฌํจ
| ์กฐ๊ฑด | ์ ๋ฌ ๋์ | ํ์ ์ ๋ณด |
|---|
| ... | | |
์์ฑ ์ ๋ณด:
- ์๋ณธ SOP: {ํ์ผ๋ช
}.sop.md
- ์์ฑ์ผ: {YYYY-MM-DD}
- ํ๋ก์ฐ์ฐจํธ ๋ฒ์ : v1.0
- ๋ฐ์ดํฐ: {N}๊ฑด ({%}%)
**Automation info MUST be included in each case description:**
- Each case MUST include **Automatable**: X% and the technique used (RAG/Action/Rules)
- This data is used as the basis for ALF participation/resolution rate calculation in Stage 5
**Expected Duration:** 1-2 minutes per SOP
### 5. Convert to SVG Image (CLI Required)
Use Mermaid CLI to generate SVG images if installed.
**Actions:**
- Check if Mermaid CLI is installed
- **If installed:**
```bash
mmdc -i {output_dir}/{SOP_ID}_FLOWCHART.md -o {output_dir}/{SOP_ID}_flowchart.svg -b transparent
- If not installed:
- Skip SVG generation
- Note in summary that markdown files can be viewed in VSCode or GitHub
Expected Duration: 10-20 seconds per SOP (if CLI installed)
Troubleshooting:
- Parse error: Remove quotes and emoticons from node text
- Retry: Re-run mmdc command
- CLI not found: Skip SVG, continue with markdown only
6. Generate Summary Report
Create summary of flowchart generation results.
Actions:
- Count generated files
- List all flowcharts with file sizes
- Provide viewing instructions
- Save to
flowchart_generation_summary.md
7. Update Metadata
Update metadata.json with flowchart references.
Actions:
- Add flowchart info to each SOP entry
- Save updated metadata
Examples
Example 1: Full Run (All SOPs)
Input:
sop_dir: results/{company}/03_sop
target_sops: all
output_format: both
Output:
- 7 Markdown files in
04_flowcharts/ (TS_001004_FLOWCHART.md, HT_001003_FLOWCHART.md)
- 7 SVG images (~170KB each) in
04_flowcharts/
- 1 Summary report
- Updated metadata.json
Time: ~4-5 minutes
Example 2: TS Only Run
Input:
sop_dir: results/{company}/03_sop
target_sops: ts_only
output_format: both
Output:
- 4 Markdown files (TS_001~004_FLOWCHART.md)
- 4 SVG images (~170KB each)
- 1 Summary report
- Updated metadata.json
Time: ~3-4 minutes
Example 3: Specific SOPs
Input:
sop_dir: results/{company}/03_sop
target_sops: ["TS_001", "HT_001"]
Output:
- 2 Flowcharts (1 TS, 1 HT)
- 2 SVG images
Time: ~2 minutes
Example 4: Markdown Only (CLI ์์)
Input:
sop_dir: results/{company}/03_sop
target_sops: all
Detected: Mermaid CLI not installed
Output:
- 7 Markdown files only (TS_001
004_FLOWCHART.md, HT_001003_FLOWCHART.md)
- โ ๏ธ SVG ์์ฑ ๊ฑด๋๋
- 1 Summary report
Time: ~3-4 minutes (SVG ๋ณํ ์๊ฐ ์ ์ธ)
Note: Markdown ํ์ผ์ VSCode Mermaid ํ์ฅ ๋๋ GitHub์์ ๋ฐ๋ก ๋ ๋๋ง๋จ
Viewing Flowcharts
VSCode์์ SVG ๋ณด๊ธฐ
- SVG ํ์ผ ํด๋ฆญ โ ์๋ ๋ ๋๋ง
Markdown ํ๋ฆฌ๋ทฐ (ํ์ฅ ํ์)
- ํ์ฅ ์ค์น: "Markdown Preview Mermaid Support"
Cmd + Shift + V
๋ธ๋ผ์ฐ์
- SVG ํ์ผ์ ๋ธ๋ผ์ฐ์ ๋ก ๋๋๊ทธ
Related Documentation
Notes
When to Use Stage 4
Recommended situations:
- Complex Troubleshooting SOPs (5+ cases, many decision branches)
- Multi-step How-To SOPs (need to visualize sequential processes)
- Onboarding materials for new staff
- Process review and optimization
- Customer presentations
Can be skipped when:
- Very simple SOPs (3 steps or fewer)
- Text-based SOP is sufficient
- Time constraints
TS vs HT flowchart characteristics:
- TS: Emphasizes decision trees, conditional branches, escalation paths
- HT: Emphasizes sequential steps, checkpoints, parallel task flows
Flowchart Quality Criteria
Good Flowchart:
- โ
Entire process visible on one screen
- โ
Cases clearly distinguished by color
- โ
Decision points are clear
- โ
Escalation paths are shown
Bad Flowchart:
- โ Too many nodes (50+)
- โ Too many crossing arrows
- โ Node text too long
- โ Monochrome with no color coding
This is an optional Stage 4. Use when visual process documentation adds value beyond text-based SOP.