Subagent Tool
สร้าง child agents สำหรับ tasks เฉพาะ
เมื่อจบ block นี้ คุณจะสามารถ:
Agentic Workflows คือระบบที่ AI agents ทำงานร่วมกันอย่างอัตโนมัติเพื่อบรรลุเป้าหมาย
Plan-Implement-Validate คือ core pattern:
┌─────────────┐│ PLAN │ วิเคราะห์งาน แบ่งเป็น steps└──────┬──────┘ │ ▼┌─────────────┐│ IMPLEMENT │ สร้างโค้ดตาม plan└──────┬──────┘ │ ▼┌─────────────┐│ VALIDATE │ Test, ตรวจสอบคุณภาพ└──────┬──────┘ │ ▼ Pass? ──Yes──► เสร็จ │ No │ └──────► กลับไป PLANGenerate Code → AI Review → Fix Issues → Repeat until qualityWrite Test → Generate Code → Run Test → Fix → RepeatPlanner → Coder → Reviewer → Tester → DeployLoops ควรหยุดเมื่อ:
Subagents คือ AI agents ที่ทำงานภายใต้ main agent — เหมือนทีมที่แบ่งหน้าที่กัน
ใน Pi:
Subagent Tool
สร้าง child agents สำหรับ tasks เฉพาะ
Workflow Engine
จัดการ parallel/sequential tasks
Loop Until Done
ทำงานต่อเนื่องจนกว่าจะเสร็จ
Team Agents
ประสานทีม agents ที่ทำงานร่วมกัน
Loop Engineering คือการออกแบบระบบที่ AI iterate จนกว่าจะบรรลุเป้าหมาย
# Pi ทำงานคนเดียว iterate จนกว่าจะเสร็จpi --loop "Create a REST API with auth, tests, and docs"สิ่งที่ Pi ทำ:
# Pi สร้าง subagents สำหรับทำงานแบบ parallelpi "Build frontend, backend, and docs in parallel"สิ่งที่ Pi ทำ:
User Request │ ▼┌─────────┐ ┌─────────┐ ┌─────────┐│ Planner │────▶│ Coder │────▶│ Reviewer │└─────────┘ └─────────┘ └────┬────┘ │ ┌─────────┘ ▼ ┌─────────┐ │ Tester │ └─────────┘ใน Pi:
/workflow — สร้าง pipeline กับหลาย agentsparallel() — ทำงานแบบ parallelpipeline() — ทำงานทีละ step| Feature | Pi | Claude Code | Cursor |
|---|---|---|---|
| Subagents | ✅ Built-in | ❌ Manual | ❌ Manual |
| Parallel work | ✅ parallel() | ❌ | ❌ |
| Loop until done | ✅ /until-done | ❌ | ❌ |
| Workflow engine | ✅ /workflow | ❌ | ❌ |
| Team coordination | ✅ /team-agents | ❌ | ❌ |
เป้าหมาย: สร้าง PIV loop แบบพื้นฐาน
เข้าใจ PIV framework
Implement loop controller
class PIVLoop { async plan(task) { } async implement(plan) { } async validate(implementation) { } async execute(task, maxIterations) { }}ทดสอบด้วย task ง่ายๆ
ตรวจสอบ convergence
ส่งมอบ: PIV loop ที่ทำงานได้พร้อม tests
เป้าหมาย: สร้าง iterative code improvement loop
ออกแบบ loop
Generate → Review → Fix → Quality Check ↑ │ └──────────────────────┘Implement แต่ละ phase
เพิ่ม convergence criteria
ทดสอบด้วย sample task
ส่งมอบ: GRF loop ที่ทำงานได้พร้อม quality gates
เป้าหมาย: สร้าง pipeline กับหลาย AI agents
ออกแบบ agent roles
| Agent | Role | Responsibility |
|---|---|---|
| Planner | Task Analysis | แบ่ง tasks เป็น steps |
| Coder | Implementation | เขียนโค้ด |
| Reviewer | Quality Check | Review คุณภาพโค้ด |
| Tester | Validation | Test โค้ด |
Implement pipeline
class Pipeline { addAgent(agent) { } async execute(task) { }}เชื่อมต่อ agents เป็น sequence
ทดสอบด้วย complex task
ส่งมอบ: Multi-agent pipeline ที่ทำงานได้
Block 5: Architecture → ออกแบบระบบ AI-powered ที่สมบูรณ์
ไป Block 5 →