# Multi-agent SOLUTION_ERP โ€” Master Coordination Guide > **Architecture:** 3 sub-agents Opus 4.7 1M Max + em main coordinator. > Pattern: Anthropic Building Effective Agents orchestrator-workers + Cognition "writes single-threaded" hybrid. > Setup: Session 20 turn 12 (2026-05-11) โ€” empirical-grounded tแปซ NAMGROUP s41-s43 trial curve. --- ## ๐ŸŽฏ Architecture ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ EM (Main) โ€” Opus 4.7 1M Max โ”‚ โ”‚ โ€ข Reasoning + write code (single-threaded principle) โ”‚ โ”‚ โ€ข User dialog + architectural decisions โ”‚ โ”‚ โ€ข Coordinate 3 sub-agents via SendMessage โ”‚ โ”‚ โ€ข Synthesize cross-agent findings end-of-session โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ†“ spawn + keep-alive (Opus 4.7 1M Max each) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Investigator โ”‚ โ”‚ Implementer โ”‚ โ”‚ Reviewer โ”‚ โ”‚ READ only โ”‚ โ”‚ WRITE strictโ”‚ โ”‚ READ only โ”‚ โ”‚ โ”‚ โ”‚ classificationโ”‚ โ”‚ โ”‚ โ”‚ Research + โ”‚ โ”‚ Cookie-cutterโ”‚ โ”‚ Adversarial โ”‚ โ”‚ Audit + โ”‚ โ”‚ + Multi-fileโ”‚ โ”‚ pre-commit + โ”‚ โ”‚ External โ”‚ โ”‚ independent โ”‚ โ”‚ live verify โ”‚ โ”‚ research โ”‚ โ”‚ ONLY โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ cyan yellow red ``` --- ## ๐Ÿ”„ Invocation decision tree (em main apply) Task input โ†’ classify task type: ``` โ”œโ”€โ”€ Read-only research / audit / scan > 5 files / external fetch? โ”‚ โ†’ Spawn Investigator (always safe) โ”‚ โ”œโ”€โ”€ Adversarial pre-commit verify / heavy diff / deploy claim? โ”‚ โ†’ Spawn Reviewer (always before push critical) โ”‚ โ”œโ”€โ”€ Cookie-cutter mechanical (N independent files same pattern, deterministic spec)? โ”‚ โœ“ N >= 5 files โ”‚ โœ“ Spec deterministic (no implicit decisions) โ”‚ โœ“ Pattern proven > 1ร— prior โ”‚ โ†’ Spawn Implementer (Case 1 Anthropic verified) โ”‚ โ”œโ”€โ”€ Multi-file independent changes (different modifications per file)? โ”‚ โœ“ Each file verifiable independently โ”‚ โœ“ Files NOT cross-stack tight coupling โ”‚ โ†’ Spawn Implementer (Case 2 orchestrator-workers) โ”‚ โ”œโ”€โ”€ Test generation for isolated methods? โ”‚ โ†’ Spawn Implementer (Case 3 verified) โ”‚ โ”œโ”€โ”€ Mass code migration (framework upgrade, per-file deterministic)? โ”‚ โ†’ Spawn Implementer (Case 5 verified) โ”‚ โ”œโ”€โ”€ Quick task < 30 min (overhead spawn khรดng xแปฉng)? โ”‚ โ†’ Em solo direct โ”‚ โ”œโ”€โ”€ Schema design / UX flow / architectural decision / cross-stack tight coupling? โ”‚ โ†’ Em solo (Cognition "writes single-threaded") โ”‚ โ†’ Investigator pre-flight optional โ”‚ โ†’ Reviewer pre-commit always โ”‚ โ””โ”€โ”€ Bug fix tightly coupled (cross BE/FE/DB, reasoning chain)? โ†’ Em solo (Anthropic warning: "tightly interdependent coding") โ†’ Investigator pre-flight optional โ†’ Reviewer pre-commit always ``` --- ## ๐Ÿ“‹ Implementer task classification โ€” CRITICAL rules **Em main MUST self-check before spawning Implementer:** ### โœ… ACCEPT criteria (ALL must be true) 1. โœ… Spec deterministic (no implicit decisions left for agent) 2. โœ… Files independent (modifications don't depend on each other) 3. โœ… Pattern repeatable (proven > 1ร— prior session โ€” reference memory entries) 4. โœ… Estimated effort > 30 min (overhead worth) 5. โœ… Max 2 layers cross-stack (NOT BE entity + DTO + FE wire 3-layer) 6. โœ… Each file output verifiable independently ### โŒ REFUSE criteria (ANY triggers refusal) 1. โŒ Schema design decisions needed 2. โŒ UX flow decisions needed 3. โŒ Cross-stack > 2 layers tight coupling 4. โŒ Bug fix involving reasoning chain 5. โŒ Integration testing involving multiple components 6. โŒ < 30 min trivial task 7. โŒ First time pattern (no prior precedent) 8. โŒ Spec ambiguity > 20% **Implementer agent ALSO has self-check trong system prompt โ†’ auto-refuse out-of-scope.** --- ## ๐Ÿ’พ Memory consult discipline Each agent has `.claude/agent-memory//MEMORY.md` persistent diary: - **Spawn:** Auto-inject first 200 lines / 25KB cแปงa MEMORY.md - **During work:** Agent may Read full MEMORY.md if task complex - **Before return:** Agent MUST update MEMORY.md vแป›i findings (BแบฎT BUแป˜C) - **Cross-session:** MEMORY.md persists on disk **Em main routine end-of-session:** ``` SendMessage Investigator: "Flush MEMORY.md vแป›i findings session nร y. Format: 1-2 sentences per finding. Categories: patterns / anti-patterns / gotchas discovered / external research summary." SendMessage Implementer: "Flush MEMORY.md vแป›i patterns applied + ambiguities encountered + scope refusals." SendMessage Reviewer: "Flush MEMORY.md vแป›i anti-patterns observed + gotcha regressions caught + claim verification results." Em read 3 MEMORY.md updates โ†’ synthesize cross-agent learnings โ†’ integrate vร o project memory / session log. Em proceed normal close-out: STATUS update + commit + push. ``` --- ## ๐Ÿ› ๏ธ SendMessage discipline **Cost optimization:** - Within 5min cache TTL window khi possible (90% discount cached prefix) - Compact prompts (~5K new content each) thay vรฌ dump (~24K) - Skip spawn cho task < 30min **Context discovery preservation:** - Include explicit "Include surprising findings + edge cases discovered" trong spec - Periodic checkpoint mแป—i 1-2h heavy work: prompt agents flush MEMORY.md - Session crash โ†’ MEMORY.md preserved on disk, in-session context lost --- ## ๐ŸŽฏ Project-specific tunings (SOLUTION_ERP) **Stack:** .NET 10 Clean Architecture + CQRS MediatR + EF Core 10 + SQL Server + 2 React 19 Vite 8 FE (admin + user) + Gitea Actions CI + Windows IIS. **Current state (Session 20 turn 12):** 27 migrations ยท 59 DB tables ยท ~142 endpoints ยท 34 FE pages ยท 81 test pass ยท 44 gotchas ยท 14 memory entries ยท 6 skills ยท 30 demo user ยท 3 prod domain `*.solutions.com.vn`. **Skills preload mแป—i sub-agent:** - **Investigator:** `contract-workflow` + `permission-matrix` + `ef-core-migration` (research patterns + schema audit) - **Implementer:** `ef-core-migration` + `permission-matrix` + `form-engine` (scaffold + 3-file rule + permission seed) - **Reviewer:** `dependency-audit-erp` + `iis-deploy-runbook` + `contract-workflow` (security/deploy/workflow audit) **Context paste session start (em main responsibility):** - `docs/STATUS.md` current state - `docs/CLAUDE.md` root tech context - Latest 2 session logs `docs/changelog/sessions/` - Active gotchas `docs/gotchas.md` - Memory entries `C:\Users\pqhuy\.claude\projects\D--Dropbox-CONG-VIEC-SOLUTION\memory\MEMORY.md` โ†’ Auto-inject baseline ~80-150K per agent. Plus task-specific Read on-demand. **Windows MAX_PATH pitfall:** Project path `D:\Dropbox\CONG_VIEC\SOLUTION\SOLUTION_ERP\` ฤ‘รฃ nested 51 chars + Dropbox-managed. **Implementer frontmatter KHร”NG dรนng `isolation: worktree`** (per Pitfall 1 template). Default branch isolation OK. **UAT live mode (Phase 9 active):** Memory `feedback_uat_skip_verify` โ€” skip `dotnet test` mแป—i chunk, vแบซn `npm run build` ร— 2 app. Reviewer khi spawn pre-commit cแบงn รกp rule nร y (khรดng yรชu cแบงu test increment cho UAT iteration), VแบชN verify wire BE + security + anti-fiddle. --- ## ๐Ÿ“Š Cost reality | Component | Effective tokens billed (after caching) | |---|---| | 3 sub-agents spawn setup | ~564K (3 ร— 188K cache WRITE) | | 10 SendMessages each ~24K new | ~450K (10 ร— 45K equivalent vแป›i cache READ) | | Em main session | ~200K | | **Total per heavy session** | **~1.2M (~6ร— solo)** | | **Optimized (compact + cache + skip trivial)** | **~600K (~3ร— solo)** | **Max 20ร— plan absorbs ~3ร— solo cost comfortable.** --- ## ๐Ÿงช Trial workflow (2-4 tuแบงn evaluate) - **Week 1:** Setup + Plan trial cookie-cutter (Case 1 verified). SOLUTION_ERP candidate: Contract V2 wire Mig 28+29 mirror PE pattern โ€” pattern proven 1ร— S17-S19 (PE V2). ~600+ LOC, 2 mig + Service + Controller + FE ร— 2 app. - **Week 2-3:** Feature wire (Solo em + Inv pre-flight + Rev pre-commit) โ€” phรขn quyแปn strict V2 + drop legacy V1. - **Week 4:** Evaluate quality vs cost real numbers. - Pass criteria: Rev catch โ‰ฅ 2 wire bugs trฦฐแป›c commit + time saving โ‰ฅ 25% Case 1+2 + Max 20ร— quota comfortable - Fail criteria: any of above unmet โ†’ rollback solo, agents archived --- ## ๐Ÿ”— References - [Anthropic Building Effective Agents](https://www.anthropic.com/engineering/building-effective-agents) - [Cognition "Multi-Agents Working"](https://cognition.ai/blog/dont-build-multi-agents) - [Anthropic Sub-agents docs](https://docs.claude.com/en/docs/claude-code/sub-agents) - Memory entries (`C:\Users\pqhuy\.claude\projects\D--Dropbox-CONG-VIEC-SOLUTION\memory\`): - `feedback_per_chunk_commit.md` โ€” per-chunk discipline reference cho Implementer pattern - `feedback_uat_skip_verify.md` โ€” Reviewer rule trong Phase 9 - `feedback_drastic_refactor_scope.md` โ€” Implementer refuse criteria reference - `feedback_audit_reuse_before_clone.md` โ€” Investigator audit-first pattern