| name | stage3-sop-generation |
| description | Generate production-ready SOP documents from Stage 2 extraction results, with a verification loop that tests each SOP against real conversations. **Language:** Auto-detects Korean (ํ๊ตญ์ด) or Japanese (ๆฅๆฌ่ช) from user input. |
Stage 3: SOP Generation with Verification
Overview
Generate SOP documents from Stage 2 results, then verify each SOP by testing it against real conversations to catch gaps and improve quality.
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.
Input: Stage 2 results (patterns.json with sop_topic_map, faq.json, patterns_enriched.json)
Output: SOP files (.sop.md) in results/{company}/03_sop/
Key Change from Previous Version: Instead of spending tokens on elaborate format constraints, this version invests tokens in a verification loop โ generate the SOP, then test it against real conversations to find and fix gaps.
Parameters
Required
- extraction_output_dir: Directory with Stage 2 results (e.g.,
results/{company}/02_extraction)
- company: Company name
- sop_title: Title for the generated SOP set
Optional
- sop_type (default: "customer_support"):
"customer_support", "troubleshooting", or "sales"
Steps
1. Load Extraction Results
Read all Stage 2 outputs:
patterns.json โ patterns + sop_topic_map (authoritative topic plan)
faq.json โ FAQ pairs by SOP topic
patterns_enriched.json โ full conversation transcripts per cluster
Constraints:
- MUST follow
sop_topic_map exactly โ one SOP per topic, no additions or removals
- MUST read templates before generating:
templates/HT_template.md and templates/TS_template.md
- MUST NOT redesign topic structure (already done in Stage 2)
2. Extract Concrete Details from Conversations
Before writing any SOP, mine patterns_enriched.json for actionable details per topic.
Extract from agent messages:
- Internal tool URLs/paths
- Step-by-step instructions agents actually gave (near-verbatim)
- UI navigation paths (e.g., "๋ง์ดํ์ด์ง โ ์์ฝ๋ด์ญ โ ํ๋จ ์ทจ์๋ฒํผ")
- Conditional branches ("~์ธ ๊ฒฝ์ฐ", "~ํ์
จ๋ค๋ฉด")
- Warning messages ("์ฃผ์", "์ค์", "๊ผญ")
Extract from customer messages:
- Common expressions describing the problem (verbatim)
- Frequently asked follow-up questions
Extraction Guardrails:
- Distinguish standard procedures from exception measures (one-time workarounds should not become SOP steps)
- Don't over-generalize FAQ escalation phrases to all cases in the same topic
- Each Case in the SOP should cover ONE customer scenario, not mix multiple issues
3. Generate SOP Documents (per topic)
For each topic in sop_topic_map, generate one SOP file.
File naming: HT_{์ฌ์ ๋จ๊ณ}_{์ฃผ์ }.sop.md or TS_{์ฌ์ ๋จ๊ณ}_{์ฃผ์ }.sop.md
Template: Follow templates/HT_template.md for HT, templates/TS_template.md for TS. Do NOT use Overview/Parameters/Steps/Examples structure.
Each Case under ํด๊ฒฐ์ฑ
์๋ด MUST include:
- Case ํค๋ with ์ ๋์ ๋น๋ (e.g., "์ ์ฒด์ 66.7%")
- ์ฃผ์ ์ํฉ ์์ (customer scenario, not technical cause)
- Step๋ณ ์๋ด ๋ฉํธ in ๋ธ๋ก ์ธ์ฉ(>) โ actual message-level detail, not "ํ์ธํด ์ฃผ์ธ์"
- ๋ด๋ถ ๋๊ตฌ ๊ฒฝ๋ก or
{placeholder} + <!-- TODO --> if not found
- ์กฐ๊ฑด ๋ถ๊ธฐ and ์๋ฃ ํ์ธ ("~๋์
จ๋์?")
For TS SOPs: Follow non-destructive order (least โ most invasive steps), with confirmation checkpoint after each step.
Constraints:
- MUST write SOP using LLM composition, NOT Python auto-generation
- MUST base ์๋ด ๋ฉํธ on actual agent messages from enriched data
- MUST NOT invent URLs, tool paths, or contact info not found in data
- MUST save to
results/{company}/03_sop/ (or 03_sop_v2/ if already exists)
4. Verify Each SOP Against Real Conversations (NEW)
This is the key quality improvement step. After generating each SOP, test it against 3-5 real conversations from that topic's enriched data.
Process per SOP:
- Pick (Case ์ ร 2) conversations from
patterns_enriched.json that belong to this topic (prefer diverse scenarios). E.g., Case 4๊ฐ โ 8๊ฑด, Case 2๊ฐ โ 4๊ฑด.
- Simulate: For each conversation, walk through the SOP as if you were the agent:
- Does the SOP cover this customer's question?
- Can you follow the steps to reach the same resolution the real agent reached?
- Are there steps the real agent took that the SOP doesn't mention?
- Did the real agent give information the SOP lacks?
- Record gaps:
Conversation ID: {id}
Customer issue: "์ทจ์ํ๊ณ ์ถ์๋ฐ ์์๋ฃ๊ฐ ์ผ๋ง์ธ๊ฐ์?"
SOP coverage: โ ๏ธ Partial โ SOP mentions ์ทจ์ ๋ฐฉ๋ฒ but doesn't cover ์์๋ฃ ์๋ด
Missing: ์ง์ญ๋ณ ์ทจ์์์๋ฃ ์ฐจ์ด ์ค๋ช
, ๋ฐ์ฐ์ฒ์์ ํ์ธํ๋ ๋ฐฉ๋ฒ
- Fix the SOP: Add missing Cases, steps, or details found during verification
- Re-save the improved SOP
Constraints:
- MUST verify every generated SOP (not optional)
- MUST use conversations NOT used during initial extraction if possible (to test generalization)
- MUST document verification results in
extraction_summary.md
- If >50% of test conversations expose gaps โ substantially rewrite the SOP before moving on
Expected Output per SOP:
โ
SOP ๊ฒ์ฆ ์๋ฃ: HT_์์ฝ์ _์ฐจ๋๊ฒ์.sop.md
ํ
์คํธ ๋ํ: 5๊ฑด
์์ ์ปค๋ฒ: 3๊ฑด (60%)
๋ถ๋ถ ์ปค๋ฒ: 2๊ฑด (40%) โ Case 3์ ์์๋ฃ ์๋ด ์ถ๊ฐ, Step 2์ ์ฑ ๊ฒฝ๋ก ๋ณด๊ฐ
๋ฏธ์ปค๋ฒ: 0๊ฑด
5. Generate Summary and Metadata
After all SOPs are generated and verified:
- Save
metadata.json with version, source files, statistics, verification results
- Update
extraction_summary.md with SOP list and verification coverage
Output Summary:
โ
Stage 3 ์๋ฃ: {N}๊ฐ SOP ์์ฑ + ๊ฒ์ฆ
์ ์ฅ ์์น: results/{company}/03_sop/
๊ฒ์ฆ ๊ฒฐ๊ณผ:
์ด ํ
์คํธ ๋ํ: {M}๊ฑด
ํ๊ท ์ปค๋ฒ์จ: {X}%
๋ณด๊ฐ๋ SOP: {Y}๊ฐ
Troubleshooting
| Issue | Solution |
|---|
| Cases too generic ("ํ์ธํด ์ฃผ์ธ์") | Re-read enriched conversations, extract actual agent messages near-verbatim |
| Cases describe technical causes, not customer scenarios | Rewrite from customer perspective: "๊ณ ๊ฐ์ด [X]๋ฅผ ํ๋ ค ํ๋ [Y] ์ํ๋ผ ๋ถ๊ฐํ ๊ฒฝ์ฐ" |
| Verification shows >50% gaps | Topic may need more data โ go back to Stage 2 and increase samples for that cluster |
| No internal tool paths in data | Use {placeholder} + <!-- TODO --> โ never invent URLs |
Notes
- Verification loop is where quality comes from โ generation alone produces 70-80% quality; verification + fix reaches 90%+
- Process SOPs sequentially in main agent for stability
- Templates (
HT_template.md, TS_template.md) define structure โ this SKILL focuses on content quality and verification
- Total time: ~10-15 min (generation ~7 min + verification ~5 min), but better quality per token spent