KRIT.JUNSREE PERSONAL WEBSITE
MEDIUM

Claude Code + Subagent: สร้าง Multi-Agent Workflow ตัวแรกของคุณ

Hari Prakash Natarajan สอน tutorial hands-on สร้าง pipeline วิเคราะห์ sales data ด้วย 5 subagent — DataLoader → Analysis (Z-score) → Visualization (matplotlib) → Reporting → Orchestration. โครง prompt แต่ละ agent พร้อม rule ห้ามทำอะไรบ้าง. Mental model: agent = specialist, pipeline = manager

By krit.junsree@gmail.com ◆ Jul 10, 2026 ◆ 9 MIN READ Beginner

☰ ON THIS PAGE

Hari Prakash Natarajan สอน tutorial สร้าง multi-agent workflow ตัวแรกด้วย Claude Code — pipeline วิเคราะห์ sales data ด้วย 5 specialist agent (DataLoader, Analysis, Visualization, Reporting, Orchestration)

คุณจะได้รู้:

  • Claude Code คืออะไร ต่างจาก chat-based AI ยังไง
  • Subagent คืออะไร ทำไมสำคัญ
  • Tutorial แบบ hands-on step-by-step สร้าง real data analysis pipeline ด้วย subagent

Claude Code คืออะไร

Claude Code = AI coding environment ที่ Claude เข้าใจ context ของ project ทั้งหมด: folder structure, ไฟล์เดิม, coding convention, dependency

ต่างจาก chat ปกติ — Claude Code เขียนไฟล์จริง เคารพขอบเขต project และถูก guide ด้วย role (agent) ได้. คิดว่า Claude Code = “AI teammate ที่ทำงานอยู่ใน repo คุณ” ไม่ใช่ chatbot ที่เดาจากที่ไกล

Subagent คืออะไร

Subagent ไม่ใช่ background process หรือ service. Subagent = role ที่ Claude adopt ชั่วคราวเพื่อทำงานเฉพาะ ภายใต้กติกาเข้ม

ไม่ “รัน” agent เหมือน program. คุณ invoke ด้วยการ assign task

ทำไมใช้ Subagent แทน Prompt เดียว

Prompt monolithic ตัวเดียว: debug ยาก, reuse ยาก, แก้จุดเดียวพังทั้งหมด, Claude อาจปนหน้าที่

Subagent-based workflow: แต่ละ agent ทำ 1 งาน, test ง่าย, replace ง่าย, reason ง่าย

Mental model: Agent = specialist. Pipeline = manager.

Scenario

สร้าง pipeline เล็ก ๆ แต่ realistic จาก sales data

เป้าหมาย — ให้ CSV มา: load + validate → detect anomaly ด้วย Z-score → plot sales trend + highlight anomaly → gen readable report

Sample: sales_data.csv column date, region, sales, units, revenue 30 rows มี anomaly ชัด ๆ (spike 95000/85000, dip 1500/2000)

Step 1: DataLoader Agent

Role: load + validate data

text
You are a DataLoader agent.

Task:
- Load sales_data.csv
- Validate required columns: date, region, sales
- Parse date column
- Output a Python file named data_loader.py

Rules:
- Do not write analysis code
- Do not write visualization code
- Output code only

Step 2: Data Analysis Agent

Role: detect anomaly ด้วย Z-score

text
You are a Data Analysis agent.

Task:
- Detect anomalies using Z-score > 3
- Add z_score and is_anomaly columns
- Assume data is already loaded
- Output a Python file named analysis.py

Rules:
- Do not load CSV
- Do not plot charts
- Output code only

Step 3: Visualization Agent

Role: สร้าง chart + highlight anomaly

python
You are a Visualization agent.

Task:
- Plot sales over time using matplotlib
- Highlight anomalies
- Save chart as sales_trend.png
- Output a Python file named visualization.py

Rules:
- Do not analyze data
- Do not modify DataFrame structure
- Output code only

Step 4: Reporting Agent

Role: เขียนสรุป human-readable

text
You are a Reporting agent.

Task:
- Generate a plain-text report summarizing anomalies
- Mention the generated chart
- Output a Python file named report.py

Rules:
- No data analysis
- No plotting
- Output code only

Step 5: Orchestration Agent

Role: มัดทุกอย่างเข้าด้วยกัน โดยไม่ implement ซ้ำ

text
You are an Orchestration agent.

Task:
- Create a Python script that runs:
  - data_loader
  - analysis
  - visualization
  - report generation
- Output a file named run_pipeline.py

Rules:
- Do not reimplement logic
- Only call existing functions

Run Pipeline

เมื่อสร้าง agent เสร็จ กลับไปที่ main prompt แล้วรัน pipeline. Output รวม analysis_report.txt (summary stat, detected anomaly + z-score, reference to visualization) และ sales_trend_with_anomalies.png

ทำไมวิธีนี้เวิร์กดี

  • Agent แต่ละตัวมี 1 งาน
  • การเปลี่ยนแปลง localize อยู่ตรงจุดนั้น
  • Code อ่านง่ายขึ้น maintain ง่ายขึ้น
  • ระบบสะท้อนทีม engineering จริง

Final Thoughts

Claude Code subagent ไม่ใช่เรื่องเขียน code เพิ่ม. มันคือ “better design decision”. ถ้ากำหนด ownership + boundary ได้ = คุณกำลังออกแบบ multi-agent system อยู่แล้ว — โดยไม่รู้ตัว


แหล่งที่มา: “Claude Code and Subagents: How to Build Your First Multi-Agent Workflow” โดย Hari Prakash Natarajan ตีพิมพ์ 14 ธ.ค. 2025 บน Medium · อ่านต้นฉบับ

Leave a Reply

Your email address will not be published. Required fields are marked *