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.
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)
results/{company}/03_sop.sop.md filesoutput_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 casestarget_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["TS_001", "HT_002"] - Specific SOP IDsoutput_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 codingVerify Stage 3 SOP files and Mermaid CLI installation.
Actions:
sop_dir exists and contains .sop.md filesoutput_dir if not provided: {sop_dir}/../04_flowcharts (e.g., results/{company}/04_flowcharts)mkdir -p {output_dir}mmdc --versionExpected 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
For each target SOP, analyze structure to extract flowchart components.
Actions:
Expected Duration: 1-2 minutes per SOP
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:
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
class NodeA,NodeB successClass at the end of the diagram([...]) start/end, {...} decision, [...] process, [[...]] API call nodes[[API Name<br>Return field check]] and apply apiClass (dashed yellow border)<br/> for line breaksMode-Specific Behavior:
Expected Duration:
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
...
| 단계 | 확인 사항 | 도구/방법 |
|---|---|---|
| 1️⃣ ... | ... | ... |
| ... |
| 조건 | 전달 대상 | 필수 정보 |
|---|---|---|
| ... |
생성 정보:
**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
Expected Duration: 10-20 seconds per SOP (if CLI installed)
Troubleshooting:
Create summary of flowchart generation results.
Actions:
flowchart_generation_summary.mdUpdate metadata.json with flowchart references.
Actions:
Input:
sop_dir: results/{company}/03_sop
target_sops: all
output_format: both
Output:
04_flowcharts/ (TS_00104_flowcharts/Time: ~4-5 minutes
Input:
sop_dir: results/{company}/03_sop
target_sops: ts_only
output_format: both
Output:
Time: ~3-4 minutes
Input:
sop_dir: results/{company}/03_sop
target_sops: ["TS_001", "HT_001"]
Output:
Time: ~2 minutes
Input:
sop_dir: results/{company}/03_sop
target_sops: all
Detected: Mermaid CLI not installed
Output:
Time: ~3-4 minutes (SVG 변환 시간 제외)
Note: Markdown 파일은 VSCode Mermaid 확장 또는 GitHub에서 바로 렌더링됨
Cmd + Shift + VRecommended situations:
Can be skipped when:
TS vs HT flowchart characteristics:
Good Flowchart:
Bad Flowchart:
This is an optional Stage 4. Use when visual process documentation adds value beyond text-based SOP.