KRIT.JUNSREE PERSONAL WEBSITE
MEDIUM

ทำให้ Claude Code Agent Coordinate 100% และแก้ Context Amnesia

Ilyas Ibrahim Mohamed เล่าเส้นทางจริง — สร้าง 26 agent → ค้นพบไม่ coordinate → Agent-Memory-Protocol → ลดเหลือ 8 → bypass main agent (พัง) → กลับมาให้ main agent จัดการ 22 flat agent. บทเรียนใหญ่: validate architecture ก่อน optimize, context window ยืดจาก 15-20 นาที → 2+ ชั่วโมง

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

☰ ON THIS PAGE

Ilyas Ibrahim Mohamed เล่าเรื่องจริงจากการทดลอง — สร้าง 26 agent, พบว่าไม่ coordinate, ทำ Agent-Memory-Protocol, ลดเหลือ 8, ลอง bypass main agent, สุดท้ายกลับมาให้ main agent จัดการทุกอย่าง. บทเรียน: validate architecture ก่อน optimize

เริ่มจาก Low-Resource Language

ผู้เขียนสร้าง classifier สำหรับ low-resource language — ต้องแยก formal vs colloquial (TikTok, Threads). ใช้ Claude Code ช่วยเร่งจากเดือนเป็นสัปดาห์

3 คำถามหลักตอนเริ่ม:

  1. Claude Code agent ทำงานยังไง? design ยืดหยุ่นแค่ไหน?
  2. Agent coordinate กันได้มั้ย? ยังไง?
  3. Agent ต้องรู้อะไรเกี่ยวกับ project? ทำให้ persistent ได้มั้ย?

ตื่นเต้นกับ Sub-Agent — แล้วเจอความจริง

สร้าง 26 agent ครอบคลุมทั้ง ML pipeline + dashboard + site. Theory ดี แต่:

  1. Main agent ไม่ coordinate — พยายามทำเอง แก้ง่าย: interrupt แล้วชื่อ specialist ใน prompt
  2. Agent ไม่ collaborate กัน — ทำงานร่วมแต่ไม่ reference งานของกันและกัน report ไม่ cross-reference = ทำซ้ำ ไม่รู้ว่าคนอื่นทำอะไร

หลังทุก task ต้องอ่านหลายร้อยบรรทัดที่แต่ละ agent เขียน หา gap ปัญหาไม่ใช่ automation แต่คือความไม่ coherent ระหว่าง agent

Agent-Memory-Protocol

แนะนำ Agent-Memory-Protocol — ไฟล์ .md ใน .claude ที่ให้ agent ทำตามโครง: ใช้ registry + update report หลังจบ task. ทุก agent เช็ค registry ก่อนเริ่มงานใหม่

ต่างจาก Claude.md ที่ static — Memory-Protocol dynamic อัพเดทตลอด

โครงสร้างเริ่มต้น (user level 26 files + project level):

text
~/.claude/
├── AGENT_MEMORY_POLICY.md
├── DESIGN_SYSTEM.md
├── STYLE_GUIDE.md
├── UX_WRITING_GUIDE.md
├── reports/
│ ├── _registry.md
│ ├── analysis/  arch/  bugs/  design/
│ ├── implementation/  review/  tests/
└── archive/

แต่ไม่ work เสมอ — บางครั้ง Claude Code ignore protocol หรือใช้แค่ครึ่งเดียว. ช้าด้วย

Insight: coordination ไม่ใช่เป้าปลายทาง — outcome ของ coordination ต่างหากที่สำคัญ. Context คือ key เหมือนคนที่ตัดสินใจดีขึ้นเมื่อเห็นภาพรวม — context ขยาย judgment, coordination ขยาย context

Streamline Workflow

เจอโอกาส streamline ชัด — section ที่ซ้ำใน agent ทุกตัว (branding + memory-check section 50+ บรรทัดต่อไฟล์), reference doc ผิดที่, orchestrator 3 ตัวหน้าที่ทับกัน

รวม 26 agent → 8 core agent ที่ delegate ไป sub-agent ใน body ตัวเอง:

text
ml-projects-orchestrator + mlops-pipeline-orchestrator = ml-orchestrator
data-analyst + data-collector + data-preprocessor = data-engineer
frontend-engineer + backend-engineer = full-stack-engineer
code-reviewer + code-debugger + test-runner + qa-test-engineer = code-quality
devops-engineer + git-specialist = devops-specialist
ux-ui-designer + ux-ui-expert + ux-writer = ux-designer
system-architect + pipeline-orchestrator = architect
documentation-writer + webdev-documentation-writer = documentation

แปลง guide เป็น Skill ที่ auto-invoke สำหรับ just-in-time knowledge, ใช้ slash command สำหรับ workflow ใช้บ่อย, output style ทำ deliverable ให้เป็นมาตรฐาน

Bold Move: Bypass Main Agent

พยายาม bypass main Claude Agent — พังเร็ว จบเร็ว

ไม่ Autonomous จริง

Coordination + institutional memory ดีขึ้นจริง — แต่ paradox: context consumption แย่ลง. Protocol ถูกโหลดซ้ำโดยทุก agent (850 บรรทัด)

สำหรับ task ง่าย:

text
Request: "Mobilize specialized agents to build feature X in line with agent-memory-protocol"
· Main Claude Agent: Auto-loads agent-memory-protocol (850 lines) + registry (~500+ lines) + prior reports (~2,000+ lines)
· Coordinator Agent(s): Auto-loads agent-memory-protocol AGAIN (850 lines) + registry + prior reports
· Coordinator Agent(s): Develops plans + implements + generates reports + updates registry

ลด Redundancy — ต้นทุนของ Autonomy

บีบ protocol จาก 850 → 280 บรรทัด (67% ลด) + focus แต่ละ coordinator ที่สิ่งสำคัญ (เฉลี่ย 73% ลด):

  • architect: 216 → 47 (78%)
  • code-quality: 177 → 48 (73%)
  • data-engineer: 145 → 49 (66%)
  • devops-specialist: 185 → 48 (74%)
  • documentation: 279 → 51 (82%)
  • full-stack-engineer: 147 → 49 (67%)
  • ml-orchestrator: 148 → 50 (66%)
  • ux-designer: 186 → 52 (72%)

ถึงจะลดได้ — design นี้กินทรัพยากรแย่สุด. ตัด middleman (main agent) ออก แต่ทุก agent อ่านทุกอย่างเอง context window ถูกบีบ อยู่ได้ไม่ถึง 15-20 นาที

บทเรียนใหญ่: ควรระบุ optimization ที่ impact สูงสุดก่อน. บีบ protocol ประหยัด ~60% แต่จัด auto-invoke จะประหยัดกว่านั้นมาก

ทำสัญญากับ Main Agent

สุดท้ายกลับมาให้ main Claude Agent จัดการเหมือนเดิม. พยายาม replace main agent = สุดท้ายเราต้องทำงานของมันเอง. เปลี่ยนไปเป็น: guide project strategic + ให้ main agent จัดการ subagent + subagent report กลับ main

Revised protocol → 370 บรรทัด, rename เป็น agent-coordination. Flatten agent — ตัด coordinator ออก เหลือ 22 agent ที่ main agent จัดการทุกอย่าง:

text
Main Claude Code Agent (User-facing, coordination)
When user says "mobilize agents":
 1. Invokes agent-memory-protocol skill (370 lines)
 2. Reads project registry
 3. Reads relevant reports
 4. Determines which agents needed
 5. Decides parallel vs sequential execution
 6. Invokes agents with complete context
 7. Verifies deliverables
 8. Synthesizes results
 9. Updates registry
 10. Reports to user
        │ Provides complete context in task prompts
        ▼
22 Specialized Task Agents (Flat)
 Each agent:
 - Receives context from main agent
 - Does specialized work
 - Returns output to main agent
 - NEVER reads registry/reports
 - NEVER invokes agent-memory-protocol

GitHub (final .claude folders, commands, skills, output styles): github.com/ilyasibrahim/claude-agents-coordination v1.0.0

ผลลัพธ์: context window ยาวขึ้นเป็น 2+ ชั่วโมง (จาก 15-20 นาที)

Key Takeaway

Claude Code agent coordination ที่สำเร็จ = เข้าใจว่า “context broadens judgment, and coordination broadens context”. Solution สุดท้าย = centralize coordination ผ่าน main agent + specialist agent ไม่โหลด shared resource ซ้ำ

Efficiency gains can seem impressive when built on an unstable foundation… Rebuilding from a solid foundation brings truly unbeatable gains. Validate the architecture before jumping into optimization.


แหล่งที่มา: “How I Made Claude Code Agents Coordinate 100% and Solved Context Amnesia” (Part 1) โดย Ilyas Ibrahim Mohamed ตีพิมพ์ 16 พ.ย. 2025 บน Medium · อ่านต้นฉบับ

Leave a Reply

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