| name | stage1-clustering |
| description | This sop executes automated clustering and tagging of customer support chat data through a Python pipeline, producing clustered data, cluster tags, and a comprehensive analysis report for Stage 2 (Pattern Extraction). The agent orchestrates the Python clustering script, monitors execution, validates outputs, and generates an analysis report to guide subsequent extraction work. **Language:** Auto-detects Korean (ํ๊ตญ์ด) or Japanese (ๆฅๆฌ่ช) from user input. |
Stage 1: Customer Support Chat Clustering
Overview
This sop executes automated clustering and tagging of customer support chat data through a Python pipeline, producing clustered data, cluster tags, and a comprehensive analysis report for Stage 2 (Pattern Extraction). The agent orchestrates the Python clustering script, monitors execution, validates outputs, and generates an analysis report to guide subsequent extraction work.
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.
Parameters
- input_file (required): Path to Excel file containing UserChat data with "UserChat data" and "Message data" sheets
- output_dir (required): Output directory path where results will be saved
- company (required): Company name for analysis context and file naming
- sample_size (optional, default: 3000): Number of records to process - use up to 3000 by default, or "all" for complete dataset
- tagging_mode (optional, default: "agent"): Cluster tagging method:
- "agent": Solar-pro unified tagging (5-15 sec, industry-adaptive, recommended)
- "api": Solar-mini independent tagging (30 sec, basic quality)
- "skip": Skip tagging for manual Claude tagging later
- k (optional, default: "auto"): Number of clusters - use "auto" for optimal selection or integer for fixed count
- k_range (optional, default: "8,10,12,15,20,25"): K values to test when k="auto"
- umap (optional, default: true): UMAP ์ฐจ์ ์ถ์ ์ ์ฉ (4096D โ 30D, silhouette ๋ํญ ๊ฐ์ )
- umap_components (optional, default: 30): UMAP ๋ชฉํ ์ฐจ์ ์
- cache_dir (optional, default: "cache"): Embedding cache directory
Constraints for parameter acquisition:
- You MUST scan data/ directory for Excel files and auto-select if only one exists
- You MUST extract company name from filename (e.g., "user_chat_assacom.xlsx" โ "assacom")
- You MUST auto-set output_dir to
results/{company} unless user specifies otherwise
- You MUST use tagging_mode="agent" always (Solar-pro unified tagging)
- You MUST validate that selected input_file exists and has correct Excel format
- You MUST create output_dir if it doesn't exist
- You MUST NOT ask the user about mode, tagging_mode, or other optional parameters โ use defaults
- You SHOULD only ask the user to confirm input_file and company name if ambiguous (multiple files)
Steps
1. Gather Parameters and Setup
Scan available files and gather parameters through interactive selection.
Constraints:
- You MUST scan data/ directory for Excel files:
find data -name "*.xlsx" -type f
- You MUST use AskUserQuestion tool to present file options
- You MUST extract company name from selected filename (e.g., "user_chat_assacom.xlsx" โ "assacom")
- You MUST suggest output_dir based on company name (e.g., "results/assacom")
- You MUST verify .env file exists:
test -f .env
- You MUST create output subdirectory:
mkdir -p {output_dir}/01_clustering
- You MUST NOT proceed if input validation fails
- Note: Python dependencies are validated automatically when script runs
- You SHOULD display file size for selected file
- You MAY provide custom path option in addition to scanned files
Parameter Selection Example:
๋ฐ์ดํฐ ํ์ผ์ ์ ํํด์ฃผ์ธ์:
[ ] data/user_chat_assacom.xlsx (2.3 MB)
[ ] data/user_chat_usimsa.xlsx (1.8 MB)
[ ] data/raw data_meliens.xlsx (3.1 MB)
[ ] ๊ธฐํ (์ง์ ์
๋ ฅ)
์ถ๋ ฅ ๋๋ ํ ๋ฆฌ:
[ ] results/assacom (์ถ์ฒ)
[ ] results/assacom_test
[ ] ๊ธฐํ (์ง์ ์
๋ ฅ)
ํ์ฌ๋ช
:
[ ] assacom (ํ์ผ๋ช
์์ ์ถ์ถ, ์ถ์ฒ)
[ ] ๊ธฐํ (์ง์ ์
๋ ฅ)
Expected Outputs:
โ
ํ๋ผ๋ฏธํฐ ์์ง ์๋ฃ:
- ์
๋ ฅ ํ์ผ: data/user_chat_assacom.xlsx (2.3 MB)
- ์ถ๋ ฅ ๊ฒฝ๋ก: results/assacom
- ํ์ฌ๋ช
: assacom
- ์ํ ํฌ๊ธฐ: 1000
- ํ๊น
๋ฐฉ์: agent (Solar-pro)
โ
ํ๊ฒฝ ๊ฒ์ฆ:
- API ํค ์ค์ ๋จ
- Python ์์กด์ฑ ์ค์น๋จ
- ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ ์์ฑ๋จ
2. Execute Clustering and Tagging Pipeline
Run the Python clustering script with Solar-pro agent tagging and monitor execution.
Constraints:
Phone consultation exclusion:
- Records with
mediumType โ {phone, meet} are filtered out automatically before sampling (default behavior in load_data()).
- The script logs the excluded count (e.g.,
์ ํ ์๋ด ์ ์ธ: 1,556๊ฑด โ ...). Treat the post-exclusion count as the working dataset size.
- To include phone consultations exceptionally, pass
--include-phone to scripts/pipeline.py.
Expected Outputs:
Customer Support Chat Clustering Pipeline
=====================================================
[1/6] Loading data...
์๋ณธ: UserChat 4,823๊ฑด, Message 38,705๊ฑด
์ ํ ์๋ด ์ ์ธ: 1,556๊ฑด โ UserChat 3,267๊ฑด, Message 15,517๊ฑด
โ Loaded 1,000 records
[2/6] Enhancing text...
โ Text enhancement complete (93.0% summary, 3.2% first_message, 3.0% combined)
[3/6] Generating embeddings...
โ Generated 1,000 embeddings in 60 seconds (or: Loaded from cache in 2 seconds)
[4/6] Performing clustering...
K=8: Silhouette=0.051
K=10: Silhouette=0.056
K=15: Silhouette=0.060
K=20: Silhouette=0.064
โ Optimal K=20, Silhouette=0.064
[5/6] Tagging clusters (Solar-pro agent mode)...
โ Tagging complete in 8 seconds
[6/6] Saving results...
โ Results saved:
- results/company/01_clustering/company_clustered.xlsx (with tags)
- results/company/01_clustering/company_tags.xlsx
๐ Category Distribution:
- ๊ตฌ๋งค ์๋ด: 214๊ฑด (21.4%)
- ๋ฐฐ์ก/์กฐ๋ฆฝ: 211๊ฑด (21.1%)
- AS/๋ฐฐ์ก: 200๊ฑด (20.0%)
- ๊ธฐ์ ์ง์: 192๊ฑด (19.2%)
...
"๊ธฐํ" rate: 7%
3. Verify Results
Validate output files with tags and check data quality.
Constraints:
- You MUST verify both output files exist:
test -f {output_dir}/01_clustering/{company}_clustered.xlsx
test -f {output_dir}/01_clustering/{company}_tags.xlsx
- You MUST check file sizes are non-zero:
ls -lh {output_dir}/01_clustering/{company}_*.xlsx
- You MUST read and display cluster distribution from tags file
- You MUST check for data quality issues:
- Empty cluster labels
- High "๊ธฐํ" (Other) category rate (>20%)
- Severely imbalanced clusters (one cluster >50%)
- You SHOULD display top 5 clusters with labels and sizes
- You SHOULD flag any quality concerns
- You MAY suggest re-running with different parameters if quality is poor
Quality Checklist:
Expected Outputs:
โ
Output files validated:
- 01_clustering/company_clustered.xlsx (1.2 MB, 1,645 rows)
- 01_clustering/company_tags.xlsx (12 KB, 10 rows)
๐ Cluster Distribution:
1. AS_์ ์ (A/S): 120๊ฑด (7.3%)
2. ๋ฐฐ์ก_์กฐํ (๋ฐฐ์ก): 96๊ฑด (5.8%)
3. ์ ํ_๋ฌธ์ (์ผ๋ฐ_์๋ด): 92๊ฑด (5.6%)
...
โ Quality checks passed
โ ๏ธ Note: Detected 117 empty records in Cluster 3
4. Generate Analysis Report
Create comprehensive analysis report for Stage 2 guidance.
Constraints:
- You MUST read both output Excel files to gather statistics
- You MUST create analysis report at:
{output_dir}/01_clustering/analysis_report.md
- You MUST include the following sections:
- Executive Summary (3-5 sentences in the detected language)
- Cluster Distribution (category breakdown, size statistics)
- Top 10 Customer Issues (with keywords and response strategies)
- Quality Metrics (silhouette score, text enhancement rate)
- Insights & Recommendations (operational insights, automation opportunities)
- Next Steps for Stage 2 (focus areas, priorities)
- You MUST extract 3-5 sample messages per top cluster
- You MUST write all analysis content in the detected language (except section titles)
- You SHOULD calculate useful metrics (average cluster size, category concentration)
- You SHOULD identify patterns and trends in the data
- You MAY include visualization suggestions
Report Structure:
# Customer Support Clustering Analysis Report: {Company}
## Executive Summary
[3-5 sentences in the detected language summarizing key findings]
## 1. Cluster Distribution
### 1.1 Category Breakdown
[Table with categories, counts, percentages]
### 1.2 Cluster Size Distribution
- Largest: {max_size}๊ฑด
- Smallest: {min_size}๊ฑด
- Average: {avg_size}๊ฑด
- Median: {median_size}๊ฑด
## 2. Top Customer Issues (Top 10)
[For each cluster: label, count, keywords, typical question, response strategy]
## 3. Quality Metrics
- Silhouette Score: {score}
- Text Enhancement Success: {rate}%
- Cluster Balance: {metric}
## 4. Insights & Recommendations
### 4.1 Operational Insights
- High-Priority Issues
- Automation Opportunities
- Training Needs
### 4.2 Customer Support Strategy
- Response Templates needed
- Escalation Rules
- Self-Service opportunities
## 5. Next Steps for Stage 2
[Focus areas, extraction priorities, data quality checks]
## Appendix
### A. Cluster Summary Table
[Complete cluster listing]
### B. Sample Messages
[Representative examples per cluster]
## Metadata
- Generated: {timestamp}
- Total Records: {N}
- Clusters (K): {K}
- Silhouette Score: {score}
Expected Outputs:
โ
Analysis report generated:
results/company/01_clustering/analysis_report.md (15 KB)
๐ Report highlights:
- 10 clusters identified
- Top issue: A/S ์ ์ (7.3%)
- 3 automation opportunities identified
- Stage 2 focus: Top 8 clusters (covers 85% of data)
5. Review and Communicate Results
Present results and confirm readiness for Stage 2.
Constraints:
- You MUST display summary of key findings
- You MUST provide file paths for all outputs
- You MUST highlight any quality concerns or special cases
- You MUST confirm whether to proceed to Stage 2
- You SHOULD suggest next actions based on results
- You MAY offer to re-run clustering with adjusted parameters if quality is suboptimal
Communication Template:
โ
Stage 1 Clustering Complete: {Company}
๐ Results Summary:
- Total Records: {N:,}
- Clusters: {K}
- Silhouette Score: {score:.3f}
- Top Category: {category} ({percentage}%)
๐ Output Files:
1. Clustered Data: {output_dir}/01_clustering/{company}_clustered.xlsx
2. Cluster Tags: {output_dir}/01_clustering/{company}_tags.xlsx
3. Analysis Report: {output_dir}/01_clustering/analysis_report.md
๐ก Key Findings:
- {finding_1}
- {finding_2}
- {finding_3}
๐ Next Steps:
- Review analysis report for detailed insights
- Proceed to Stage 2: /stage2-extraction
- Or re-run with adjusted parameters if needed
Examples
Example 1: Default Run (1000 records)
Input Parameters:
input_file: data/raw/user_chat_assacom.xlsx
output_dir: results/assacom
company: assacom
sample_size: 1000
tagging_mode: agent
k: auto
Results:
- 20 clusters identified
- Silhouette: 0.064
- Top issue: AS๋ฌธ์ (33.8%)
- Time: ~2-3 minutes
Example 2: Full Dataset Run
Input Parameters:
input_file: data/raw/raw data_meliens.xlsx
output_dir: results/meliens
company: meliens
sample_size: all
tagging_mode: agent
k: auto
Results:
- 10 clusters, 1,645 records
- Silhouette: 0.132
- A/S inquiries dominate (48%)
- Time: ~10-15 minutes
Troubleshooting
Issue: Missing API Key
Symptom: Script fails with "UPSTAGE_API_KEY not found"
Solution:
- You MUST check if .env file exists:
test -f .env
- You MUST verify API key is set:
grep UPSTAGE_API_KEY .env
- If missing, instruct the user to add
UPSTAGE_API_KEY to .env directly. Issue the key at https://console.upstage.ai
- You MUST wait for the user to update
.env before retrying clustering
Issue: Python Dependencies Missing
Symptom: ImportError or ModuleNotFoundError
Solution:
- You MUST check requirements:
pip3 show pandas numpy scikit-learn
- You MUST install missing packages:
pip3 install -r requirements.txt --user
- You MUST verify installation succeeded
- You MUST retry clustering after installation
Issue: Low Clustering Quality
Symptom: High "๊ธฐํ" rate (>20%) or poor silhouette score (<0.03)
Solution:
- You SHOULD suggest trying different tagging_mode (api โ agent โ skip+manual)
- You MAY suggest adjusting k parameter (try k_range values)
- You MAY recommend using
/tag-clusters-manual for production quality
- You SHOULD document quality concerns in analysis report
Issue: Clustering Takes Too Long
Symptom: Script runs >10 minutes on sample data
Solution:
- You MUST check if embeddings are cached (should be fast on re-runs)
- You SHOULD suggest reducing sample_size for initial testing
- You MAY check system resources (memory, CPU)
- You SHOULD display progress to reassure user
Related Documentation
- Detailed Clustering Guide:
../docs/clustering-guide.md - Algorithm details, troubleshooting, and optimization
- Next Stage:
/stage2-extraction - Pattern extraction workflow
- Full Pipeline:
/userchat-to-sop-pipeline - End-to-end orchestration
Notes
Execution Environment
This SOP requires:
- Python 3.9+ with dependencies (pandas, numpy, scikit-learn, openpyxl, openai, tqdm, python-dotenv)
- Upstage Solar API key (for embeddings and optional tagging)
- Excel input file with specific sheet structure
- File system access for reading/writing
Data Filtering
Phone consultations (mediumType โ {phone, meet}) are excluded by default at data load time. Stage 2~7 inherit the filtered dataset since they consume Stage 1 outputs. Use --include-phone to opt out.
Output for Stage 2
The analysis report (analysis_report.md) is critical for Stage 2:
- Provides context about industry and customer needs
- Prioritizes clusters for pattern extraction
- Identifies automation opportunities
- Flags data quality issues
Performance Expectations
- 1,000 records: ~2-3 minutes (< 1 min embedding, 1 min clustering, 1 min report)
- 10,000 records: ~10-15 minutes
- Embedding cache makes re-runs much faster (< 1 min)
Cost Estimates
- Upstage Solar embeddings: $0.05 per 1000 records
- Agent tagging: $0.02 per 1000 records
- Total: ~$0.07 per 1000 records