| name | userchat-to-sop-pipeline |
| description | Complete end-to-end pipeline for transforming Excel customer support data into production-ready Agent SOP documents and flowcharts through Clustering, Pattern Extraction, SOP Generation, and Flowchart Generation stages. |
Userchat-to-SOP Complete Pipeline
Overview
This SOP orchestrates the complete end-to-end pipeline for transforming Excel customer support data into production-ready Agent SOP documents with visual flowcharts. It integrates all four stages: Clustering (Python), Pattern Extraction (LLM), SOP Generation (LLM), and Flowchart Generation (LLM + Mermaid).
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.
Pipeline Flow:
Excel Input (๊ณ ๊ฐ ์๋ด ๋ฐ์ดํฐ)
โ
Stage 1: Clustering (Python) [~3 min]
โ clustered_data.xlsx, cluster_tags.xlsx, analysis_report.md
โ
Stage 2: Pattern Extraction (LLM) [5-10 min]
โ patterns.json, faq.json, response_strategies.json, keywords.json
โ
Stage 3: SOP Generation (LLM) [~5 min]
โ TS_*.sop.md, HT_*.sop.md, metadata.json
โ
Stage 4: Flowchart Generation (LLM) [~4 min, (๊ธฐ๋ณธ ํ์ฑํ)]
โ *_FLOWCHART.md (Mermaid markdown, SVG ์ ํ)
โ
Output: Ready-to-deploy Agent SOP + Visual Flowcharts
Total Time: ~20-30 minutes (Stage 1-4 full pipeline)
Parameters
Required Parameters
- language (default: "ko"): Output language for clustering labels and LLM prompts
"ko": Korean (ํ๊ตญ์ด)
"ja": Japanese (ๆฅๆฌ่ช)
Stage 1 Parameters (์๋ ์์ง)
Stage 1์ /stage1-clustering ์คํฌ์ ํธ์ถํ์ฌ ํ๋ผ๋ฏธํฐ๋ฅผ ์๋ ์์งํฉ๋๋ค.
input_file: data/ ๋๋ ํ ๋ฆฌ์์ ์๋ ๊ฐ์ง (ํ์ผ 1๊ฐ๋ฉด ์๋ ์ ํ)
company: ํ์ผ๋ช
์์ ์๋ ์ถ์ถ
output_dir: results/{company}๋ก ์๋ ์ค์
sample_size: ๊ธฐ๋ณธ๊ฐ 3000 (๋ฐ์ดํฐ๊ฐ 3000๊ฑด ๋ฏธ๋ง์ด๋ฉด ์ ์ฒด)
tagging_mode: ๊ธฐ๋ณธ๊ฐ "agent" (๋ณ๊ฒฝ ๋ถํ์)
k: ๊ธฐ๋ณธ๊ฐ "auto"
Note: ํ๋ผ๋ฏธํฐ๋ฅผ ๋ฌป์ง ์๊ณ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์งํํฉ๋๋ค. ํ์ผ์ด ์ฌ๋ฌ ๊ฐ์ผ ๋๋ง ์ ํ์ ์์ฒญํฉ๋๋ค.
Optional Parameters (Stage 4)
- generate_flowcharts (default: true): Generate flowcharts in Stage 4 (๊ธฐ๋ณธ ํ์ฑํ โ ์ต์
์ผ๋ก ๋นํ์ฑํ ๊ฐ๋ฅ)
true: Generate Mermaid flowcharts after SOP generation (recommended)
false: Skip Stage 4 (flowchart generation)
Note: Stage 4 (Flowchart Generation)์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ฑํ๋์ด ์์ผ๋ ์ต์
์ผ๋ก ๋นํ์ฑํํ ์ ์์ต๋๋ค. ํ๋ก์ฐ์ฐจํธ ์์ฑ์ ๊ฑด๋๋ฐ๋ ค๋ฉด generate_flowcharts=false๋ก ์ค์ ํ๊ฑฐ๋ ๊ฒํ ๋จ๊ณ์์ ์์ฑ ์ฌ๋ถ๋ฅผ ๊ฑฐ๋ถํ์ธ์.
-
flowchart_target (default: "all"): Which SOPs to generate flowcharts for
"all": Generate for all SOPs (both TS and HT, recommended)
"ts_only": Only Troubleshooting SOPs
"ht_only": Only How-To SOPs
-
flowchart_format (default: "markdown"): Flowchart output format
"markdown": Mermaid markdown only (recommended, no CLI needed)
"svg": SVG images only (requires Mermaid CLI)
"both": Both markdown and SVG
-
auto_proceed (default: true): Automatic stage progression
true: Auto-proceed through stages without manual review (recommended)
false: Pause after each stage for review
Steps
1. Initialize Pipeline
Validate environment and prepare for execution.
Actions:
- Ask user to select language (Korean / Japanese) using AskUserQuestion if not already specified
- Set
language variable ("ko" or "ja") โ all subsequent Python script executions MUST be prefixed with LANGUAGE={language}
- Validate Python clustering package is installed
- Check .env file with UPSTAGE_API_KEY:
grep -s "UPSTAGE_API_KEY" .env
- If key is missing or is the placeholder
up_YOUR_API_KEY_HERE:
- You MUST run the full
request-api-key skill flow inline (send Channel.io message to groupId "531940", sleep 10, check thread, write key to .env)
- You MUST NOT proceed to Stage 1 until the key is confirmed valid
- Print pipeline configuration
- Inform user that Stage 1 will be interactive
Expected Output:
โ
Pipeline initialized
- Python package validated
- API key confirmed
- Ready for Stage 1 (๋ํํ ํ์ผ ์ ํ)
๐ Stage 1 will prompt you to:
1. Select Excel data file (from data/ directory scan)
2. Choose company name (auto-extracted from filename)
3. Confirm output directory (auto-suggested)
4. (Optional) Adjust clustering parameters
Proceeding to Stage 1...
2. Execute Stage 1: Clustering
Run clustering via /stage1-clustering skill with auto-detected parameters.
Documentation: See stage1-clustering SKILL.md
Execution:
/stage1-clustering
Outputs (Auto-detected for next stages):
results/{company}/01_clustering/{company}_clustered.xlsx - Full dataset with cluster assignments
results/{company}/01_clustering/{company}_tags.xlsx - Cluster summary
results/{company}/01_clustering/analysis_report.md - Comprehensive analysis for Stage 2
After Stage 1 Completion:
Pipeline automatically detects company and output_base_dir from Stage 1 outputs:
output_base_dir="results/{company}"
company="{company}"
โ {output_base_dir}/01_clustering/{company}_clustered.xlsx
โ {output_base_dir}/01_clustering/{company}_tags.xlsx
โ {output_base_dir}/01_clustering/analysis_report.md
Quality Checks:
Stage Transition:
IF auto_proceed=true (๊ธฐ๋ณธ๊ฐ):
- You MUST automatically proceed to Stage 2 WITHOUT asking user
- You MUST display: "โ
Stage 1 complete. Auto-proceeding to Stage 2..."
- You MUST NOT use read -p or AskUserQuestion
- You MUST skip to Step 3 immediately
IF auto_proceed=false:
- You MUST display: "๐ Review analysis report: $output_base_dir/01_clustering/analysis_report.md"
- You MUST ask via AskUserQuestion: "Stage 1 ์๋ฃ. Stage 2 (Pattern Extraction)๋ก ์งํํ ๊น์?"
- You MUST wait for user confirmation before proceeding
3. Execute Stage 2: Pattern Extraction
Use LLM to extract patterns, FAQs, and response strategies from clusters.
Documentation: See stage2-extraction SKILL.md
Execution:
/stage2-extraction
Inputs:
- Stage 1 outputs (in
$output_base_dir/01_clustering/): {company}_clustered.xlsx, {company}_tags.xlsx, analysis_report.md
Outputs:
patterns.json - Extracted patterns per cluster
faq.json - FAQ pairs for common inquiries
response_strategies.json - Response strategies and escalation rules
keywords.json - Keyword taxonomy
extraction_summary.md - Summary and recommendations
Expected Duration: ~5-10 minutes
Quality Checks:
Stage Transition:
IF auto_proceed=true (๊ธฐ๋ณธ๊ฐ):
- You MUST automatically proceed to Stage 3 WITHOUT asking user
- You MUST display: "โ
Stage 2 complete. Auto-proceeding to Stage 3..."
- You MUST NOT use read -p or AskUserQuestion
- You MUST skip to Step 4 immediately
IF auto_proceed=false:
- You MUST display: "๐ Review extraction summary: $output_base_dir/02_extraction/extraction_summary.md"
- You MUST ask via AskUserQuestion: "Stage 2 ์๋ฃ. Stage 3 (SOP Generation)๋ก ์งํํ ๊น์?"
- You MUST wait for user confirmation before proceeding
4. Execute Stage 3: SOP Generation
Use LLM to generate Agent SOP documents from extracted patterns, organized by customer journey stages.
Documentation: See stage3-sop-generation SKILL.md
Execution:
/stage3-sop-generation
Inputs:
- Stage 2 outputs:
patterns_enriched.json, faq.json, response_strategies.json, keywords.json
Outputs:
03_sop/HT_*.sop.md - 10-15๊ฐ SOP ํ์ผ (๊ณ ๊ฐ ์ฌ์ ๊ธฐ๋ฐ)
03_sop/TS_*.sop.md
metadata.json - SOP metadata
Expected Duration: ~5-10 minutes
Quality Checks:
Stage Transition:
IF auto_proceed=true (๊ธฐ๋ณธ๊ฐ):
- You MUST automatically proceed to Stage 4 WITHOUT asking user
- You MUST display: "โ
Stage 3 complete. Auto-proceeding to Stage 4..."
- You MUST NOT use read -p or AskUserQuestion
- You MUST skip to Step 5 immediately
IF auto_proceed=false:
- You MUST display: "๐ Review generated SOPs: $output_base_dir/03_sop/"
- You MUST ask via AskUserQuestion: "Stage 3 ์๋ฃ. Stage 4 (Flowchart Generation)๋ก ์งํํ ๊น์?"
- You MUST wait for user confirmation before proceeding
5. Execute Stage 4: Flowchart Generation (Required)
Generate Mermaid flowcharts from SOP documents.
Documentation: See stage4-flowchart-generation SKILL.md
Execution:
/stage4-flowchart-generation
Inputs:
- Stage 3 outputs:
TS_*.sop.md, HT_*.sop.md
Outputs:
*_FLOWCHART.md - Mermaid flowchart markdown (required)
*_flowchart.svg - SVG images (optional, only if user has Mermaid CLI)
flowchart_generation_summary.md - Summary report
Expected Duration: ~3-5 minutes
Quality Checks:
Skip Conditions (Stage 4 is optional; default: enabled):
generate_flowcharts=false (์ฌ์ฉ์๊ฐ ๋ช
์์ ์ผ๋ก ๋นํ์ฑํ)
- User declines during review pause (๊ฒํ ๋จ๊ณ์์ ์์ฑ ๊ฑฐ๋ถ)
์ค๋ช
: Stage 4์ ๊ธฐ๋ณธ์ ์ผ๋ก ํ์ฑํ๋์ด ์์ผ๋ ํ์์ ๋ฐ๋ผ ๊ฑด๋๋ธ ์ ์์ต๋๋ค. ์ ๋ ์กฐ๊ฑด ์ค ํ๋๊ฐ ์ถฉ์กฑ๋๋ฉด ํ๋ก์ฐ์ฐจํธ ์์ฑ์ ์ํ๋์ง ์์ต๋๋ค.
6. Validate Complete Pipeline
Perform final validation of all outputs.
Actions:
- Verify all output files exist
- Validate file sizes are reasonable (not empty)
- Check JSON files are valid JSON
- Verify markdown files render correctly
- Generate pipeline summary report
Files to Check:
$output_base_dir/
โโโ 01_clustering/
โ โโโ {company}_clustered.xlsx
โ โโโ {company}_tags.xlsx
โ โโโ analysis_report.md
โโโ 02_extraction/
โ โโโ patterns.json
โ โโโ faq.json
โ โโโ response_strategies.json
โ โโโ keywords.json
โ โโโ extraction_summary.md
โโโ 03_sop/
โ โโโ TS_*.sop.md (multiple files)
โ โโโ HT_*.sop.md (multiple files)
โ โโโ *_FLOWCHART.md (if Stage 4 executed)
โ โโโ *_flowchart.svg (if Stage 4 executed with CLI)
โ โโโ metadata.json
โ โโโ generation_summary.md
โโโ pipeline_summary.md (generated in next step)
Expected Output (without Stage 4):
โ
All output files validated
- Stage 1: 3 files
- Stage 2: 5 files
- Stage 3: 10+ files (multiple SOPs)
Total: 18+ files, pipeline complete (Stage 1-3)
Expected Output (with Stage 4):
โ
All output files validated
- Stage 1: 3 files
- Stage 2: 5 files
- Stage 3: 10+ files (multiple SOPs)
- Stage 4: 14+ files (7 FLOWCHART.md + 7 SVG)
Total: 32+ files, full pipeline complete (Stage 1-4)
7. Generate Pipeline Summary
Create comprehensive summary of pipeline execution and results.
Summary Contents:
- Execution information (date, duration, parameters)
- Stage 1 statistics (records, clusters, silhouette score, top category)
- Stage 2 statistics (patterns, FAQs, automation opportunities)
- Stage 3 statistics (SOP files, types, total lines)
- Stage 4 statistics (flowcharts generated, SVG status) - if executed
- Key insights from all stages
- Next steps for deployment
- Quality metrics
Output: {output_base_dir}/pipeline_summary.md
Template:
# Userchat-to-SOP Pipeline Summary
## Execution Information
- Company: {company}
- Execution Date: {timestamp}
- Total Duration: {duration}
- Stages Executed: {stages} (1-3 or 1-4)
## Stage Results
### Stage 1: Clustering
- Records: {N}, Clusters: {K}, Score: {score}
### Stage 2: Pattern Extraction
- Patterns: {P}, FAQs: {F}, Strategies: {S}
### Stage 3: SOP Generation
- TS SOPs: {TS_count} files
- HT SOPs: {HT_count} files
- Total Lines: {total_lines}
### Stage 4: Flowchart Generation (if executed)
- Flowcharts: {flowchart_count} (TS: {ts_fc}, HT: {ht_fc})
- SVG Images: {svg_count} (CLI: {cli_status})
## Key Insights
1. {insight_1}
2. {insight_2}
3. {insight_3}
## Next Steps
1. Review SOPs: {sop_dir}
2. Review flowcharts (if generated): {flowchart_dir}
3. Test with sample inquiries
4. Deploy to Claude Skills
5. Monitor metrics
8. Communicate Results
Present pipeline results to stakeholders.
Communication Template:
โ
Userchat-to-SOP Pipeline Complete: {Company}
๐ Pipeline Results
- Total Records: {N:,}
- Clusters: {K}
- Patterns: {P}
- FAQ Pairs: {F}
- SOP Files: {sop_count} (TS: {ts_count}, HT: {ht_count})
- Flowcharts: {flowchart_count} (if Stage 4 executed)
๐ก Key Insights
1. {insight from analysis report}
2. {insight from extraction}
3. {automation opportunity}
๐ Output Files
- Analysis Report: {path}/01_clustering/analysis_report.md
- Extraction Summary: {path}/02_extraction/extraction_summary.md
- SOP Documents: {path}/03_sop/TS_*.sop.md, HT_*.sop.md
- Flowcharts: {path}/03_sop/*_FLOWCHART.md (if generated)
๐ Next Steps
1. Review analysis report and SOPs
2. Review flowcharts (if generated)
3. Test SOPs with sample inquiries
4. Deploy via Claude Skills
5. Monitor key metrics
Examples
Example 1: Standard Production Run (Full 4-Stage Pipeline)
Scenario: Complete pipeline with flowcharts (default configuration)
Execution:
/userchat-to-sop-pipeline
Stage 1 (๋ํํ ํ๋ผ๋ฏธํฐ ์์ง):
- ๐ File selection:
data/user_chat_channelcorp.xlsx (์ ํ)
- ๐ข Company: "channelcorp" (์๋ ์ถ์ถ)
- ๐ Output:
results/channelcorp (์๋ ์ ์)
- โ๏ธ Clustering: sample_size=all, k=auto, tagging_mode=agent (๊ธฐ๋ณธ๊ฐ)
Optional Parameters (Stage 2-4):
min_total_samples=300
sop_detail_level="standard"
generate_flowcharts=true
flowchart_target="all"
auto_proceed=false
Timeline:
- Stage 1 (Clustering): 3 minutes (๋ํํ ํฌํจ)
- Review & Approve: 2 minutes
- Stage 2 (Extraction): 7 minutes
- Review & Approve: 3 minutes
- Stage 3 (SOP Generation): 5 minutes
- Review & Approve: 2 minutes
- Stage 4 (Flowcharts): 4 minutes
- Validation & Summary: 1 minute
- Total: 27 minutes
Results:
- 10 clusters, 37 patterns, 52 FAQ pairs
- 7 SOP files (TS: 4, HT: 3), ~5,000 total lines
- 7 flowchart markdowns
- Key insight: A/S inquiries dominate (48%)
Example 2: Quick Production Run (Auto-proceed Mode)
Scenario: Fast pipeline execution without manual review pauses
Execution:
/userchat-to-sop-pipeline
Stage 1 (๋ํํ):
- ํ์ผ, ํ์ฌ๋ช
, ์ถ๋ ฅ ๊ฒฝ๋ก ์ ํ (๋ํํ)
- Clustering ํ๋ผ๋ฏธํฐ๋ ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ
Optional Parameters:
auto_proceed=true
Timeline:
- Stage 1: 3 minutes (๋ํํ ํฌํจ)
- Stage 2: 7 minutes (auto-proceed)
- Stage 3: 5 minutes (auto-proceed)
- Stage 4: 4 minutes (auto-proceed)
- Validation: 1 minute
- Total: 20 minutes
Results:
- 10 clusters, 37 patterns, 52 FAQ pairs
- 7 SOP files (TS: 4, HT: 3)
- 7 flowchart markdowns
Example 3: Quick Test Run
Scenario: Quick validation before full run
Execution:
/userchat-to-sop-pipeline
Stage 1 (๋ํํ):
- ๐ File:
data/user_chat_test.xlsx (์ ํ)
- ๐ข Company: "testco" (์๋)
- ๐ Output:
results/testco (์๋)
- โ๏ธ Clustering ์กฐ์ : sample_size=1000, k=15 (๋ํํ์์ ์กฐ์ )
Optional Parameters:
n_samples_per_cluster=10
sop_detail_level="concise"
flowchart_target="ts_only"
auto_proceed=true
Timeline:
- Stage 1: 2 minutes (1000๊ฐ, K=15)
- Stage 2: 4 minutes (10 samples/cluster)
- Stage 3: 3 minutes (concise)
- Stage 4: 2 minutes (TS only)
- Total: 11 minutes
Results:
- 15 clusters, 25 patterns
- 5 SOP files, ~2,500 total lines
- 3 TS flowcharts
Troubleshooting
Issue: Stage 1 Clustering Fails
Solution:
- Verify Python package:
pip install -r requirements.txt
- Check input file format (required sheets present)
- Verify environment variables (UPSTAGE_API_KEY)
- Run Stage 1 independently:
/stage1-clustering
- Check logs for specific error messages
Issue: Stage 2 Takes Too Long
Solution:
- Reduce
n_samples_per_cluster to 10 or 20 (standard)
- Use
focus_clusters="top_10" to analyze only top clusters
- Consider re-running Stage 1 with lower K value
Issue: Generated SOP is Too Generic
Solution:
- Review Stage 2 extraction quality
- Re-run Stage 2 with
n_samples_per_cluster=30
- Manually enhance Stage 3 output with company-specific details
- Include more sample messages in extraction
Issue: Pipeline Paused, Need to Resume
Solution:
Each stage is independent and can be resumed:
/stage2-extraction
/stage3-sop-generation
/stage4-flowchart-generation
Issue: Flowchart Generation Fails (Stage 4)
Solution:
- Check if Mermaid CLI is installed:
mmdc --version
- If not installed and SVG needed:
npm install -g @mermaid-js/mermaid-cli
- If CLI not needed: Use
output_format="markdown" for markdown-only
- Verify SOP files exist and are valid markdown
- Run Stage 4 independently:
/stage4-flowchart-generation
Related Documentation
Notes
Why Hybrid Approach (Python + LLM)?
Python (Stage 1):
- Embedding generation: Computational, benefits from caching
- K-Means clustering: Statistical algorithm, fast and reliable
- Results in 2-3 minutes (vs 30+ min if done by LLM)
LLM (Stage 2, 3):
- Pattern extraction: Requires language understanding
- FAQ generation: Natural language composition
- SOP writing: Structured document creation with domain reasoning
Hybrid = Best of Both Worlds
Stage 2 Execution Strategy
Important Implementation Details:
โ ๏ธ Stage 2 uses sequential processing in main agent
- Do NOT use subagent (Task agent) - causes performance degradation and hanging issues
- Sequential cluster analysis in main agent is faster and more stable
- Parallel processing attempts increase execution time and instability
โ
Enrichment is always generated
patterns_enriched.json file is automatically generated in Stage 2 Step 7
- Includes 10 representative conversation samples + 20 tone-and-manner samples per cluster
- Stage 3 uses this file to generate richer SOPs
See /stage2-extraction skill for detailed execution strategy
Pipeline Defaults
๊ธฐ๋ณธ ์ค์ (ํ๋ผ๋ฏธํฐ ์ง๋ฌธ ์์ด ๋ฐ๋ก ์คํ):
| Stage | ํ๋ผ๋ฏธํฐ | ๊ธฐ๋ณธ๊ฐ |
|---|
| Stage 1 | sample_size | 3000 |
| Stage 1 | umap | true (4096D โ 30D) |
| Stage 1 | k_range | 8,10,12,15,20,25 |
| Stage 1 | tagging_mode | agent |
| Stage 2 | min_total_samples | 300 |
| Stage 2 | n_samples_per_cluster | max(20, ceil(300/K)) |
| Stage 3 | SOP ๊ตฌ์ฑ | ๊ณ ๊ฐ ์ฌ์ ๊ธฐ๋ฐ ~10-15๊ฐ |
| Stage 4 | flowchart_target | all |
| Stage 4 | flowchart_format | markdown |
Stage 4๋ฅผ ๊ฑด๋๋ฐ๋ ค๋ฉด generate_flowcharts=false๋ก ์ค์ .
Cost Estimates (per 1000 records)
Stage 1 (Upstage Solar):
- Embeddings: $0.05
- Tagging: $0.01-0.02
Stage 2 & 3 (Claude Sonnet 4.5):
- Varies by depth
- Typical: $0.50-2.00 per full pipeline run
Total: ~$0.60-2.50 per 1000 records
Monitoring & Iteration
After SOP deployment:
- Week 1-2: Pilot with small team
- Week 3-4: Refine based on feedback
- Month 2: Full rollout, track metrics
- Quarterly: Re-run pipeline with new data
Metrics to Track:
- First-contact resolution rate
- Average response time
- Escalation rate
- Customer satisfaction score
- Agent feedback on SOP usability
This is an orchestration SOP. For detailed implementation of each stage, refer to the stage-specific SOPs linked above.