# Multi-agent SOLUTION_ERP โ€” Master Coordination Guide (7-agent) > **Architecture:** 7 sub-agents Opus 4.8 1M Max + em main coordinator. > Pattern: Anthropic Building Effective Agents orchestrator-workers + Cognition "writes single-threaded" hybrid + post-deploy automated watchdog. > **Upgrade S39 (2026-05-29):** 4โ†’7 agent (split investigator + implementer, +test-specialist) + budget +50% + 5 RAG MCP per agent. Reference BVAAU 7-agent config (adapted, NOT copied โ€” SOLUTION_ERP 2-FE-app fit + 6 skill proven battle-test 38 session). Prior: S20t12 initial 3 + S21t1 +cicd-monitor. --- ## ๐ŸŽฏ Architecture (7 agent) ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ EM (Main) โ€” Opus 4.8 1M Max โ”‚ โ”‚ โ€ข Reasoning + write code (single-threaded principle) โ”‚ โ”‚ โ€ข Schema/UX/architecture decision + cross-stack tight couplingโ”‚ โ”‚ โ€ข Coordinate 7 sub-agents via spawn + SendMessage โ”‚ โ”‚ โ€ข Synthesize cross-agent findings + commit/push (em main only)โ”‚ โ”‚ โ€ข Fallback solo nแบฟu spawn fail (gotcha #53 truncate / 529) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ†“ spawn + keep-alive (Opus 4.8 1M Max inherit each) โ”€โ”€ RESEARCH (READ) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”€โ”€ IMPLEMENT (WRITE) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”€โ”€ QUALITY โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚investigator- โ”‚ โ”‚invest-โ”‚ โ”‚implementer- โ”‚ โ”‚implement-โ”‚ โ”‚test- โ”‚ โ”‚reviewer โ”‚ โ”‚cicd- โ”‚ โ”‚codebase โ”‚ โ”‚igator-โ”‚ โ”‚backend โ”‚ โ”‚er- โ”‚ โ”‚special-โ”‚ โ”‚ โ”‚ โ”‚monitor โ”‚ โ”‚ โ”‚ โ”‚api โ”‚ โ”‚ โ”‚ โ”‚frontend โ”‚ โ”‚ist โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ INTERNAL audit โ”‚ โ”‚EXTERN-โ”‚ โ”‚ .NET Domain+App โ”‚ โ”‚ FE 2 app โ”‚ โ”‚ tests/ โ”‚ โ”‚adversa- โ”‚ โ”‚post- โ”‚ โ”‚ SQL/EF/grep/ โ”‚ โ”‚AL docsโ”‚ โ”‚ +Infra+Api โ”‚ โ”‚cookie- โ”‚ โ”‚dedica- โ”‚ โ”‚rial pre-โ”‚ โ”‚deploy โ”‚ โ”‚ reference mirror โ”‚ โ”‚CVE/libโ”‚ โ”‚ entity/CQRS/Mig โ”‚ โ”‚cutter โ”‚ โ”‚ted โ”‚ โ”‚commit + โ”‚ โ”‚Gitea + โ”‚ โ”‚ โ”‚ โ”‚/cross-โ”‚ โ”‚ /Controller โ”‚ โ”‚mirror โ”‚ โ”‚xUnit โ”‚ โ”‚live curlโ”‚ โ”‚bundle โ”‚ โ”‚ โ”‚ โ”‚projectโ”‚ โ”‚ โ”‚ โ”‚SHA256 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚+ smoke โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ cyan blue yellow orange purple red green ``` --- ## ๐Ÿšจ RULE BแบฎT BUแป˜C (S39 updated) **Em main BแบฎT BUแป˜C phรขn viแป‡c cho sub-agent ฤ‘รบng vai trรฒ khi ACCEPT criteria match. Budget +50% โ†’ lean toward delegate + parallel, รญt em main solo fallback.** **Workflow forward S39+:** - Trฦฐแป›c mแปi task โ†’ classify qua decision tree dฦฐแป›i - Read-only research โ†’ **split**: internal codebase audit โ†’ `investigator-codebase` ยท external docs/CVE/lib โ†’ `investigator-api` (cรณ thแปƒ spawn parallel cแบฃ 2) - WRITE scaffold โ†’ **split**: .NET backend โ†’ `implementer-backend` ยท FE 2 app โ†’ `implementer-frontend` (parallel khi independent โ€” vd BE entity + FE types cรนng lรบc) - Test โ†’ **`test-specialist`** dedicated (KHร”NG ฤ‘แปƒ implementer kiรชm) - Deploy claim โ†’ `cicd-monitor` sau push (skip docs-only gotcha #41) - Heavy diff / security / wire BE claim โ†’ `reviewer` pre-commit **Em main solo CHแปˆ khi:** schema/UX/architecture decision ยท cross-stack tight coupling ยท bug fix reasoning chain ยท gotcha #53 fallback (spawn truncate/529 โ†’ em main solo reliable, proven S37 BE 700 LOC + FE 4 file). **Anti-truncation rules (gotcha #53 โ€” 5ร— occurrence S35-S37):** - Brief WRITE agent โ‰ค 8K (heavy spec ~10K โ†’ truncate risk). FE tight brief proven 0 truncation S36. - Curate MEMORY pre-spawn nแบฟu > 25KB (Investigator 32KB S37 โ†’ truncate mid-MEMORY). - Agent keep entry โ‰ค 1.5K chars (frontmatter rule mแป—i agent). - Em main grep verify manual nแบฟu agent return truncated mid-task. - 529 Overload transient โ†’ em main solo fallback (KHร”NG retry loop). --- ## ๐Ÿ”„ Invocation decision tree (em main apply) ``` โ”œโ”€โ”€ Read-only INTERNAL audit (codebase/SQL/EF diff/grep > 5 files)? โ”‚ โ†’ investigator-codebase (cyan) โ”‚ โ”œโ”€โ”€ Read-only EXTERNAL (official docs / NuGet-npm CVE / lib eval / cross-project ref)? โ”‚ โ†’ investigator-api (blue) โ”‚ โ†’ Cแบฃ 2 investigator parallel OK khi task cแบงn both (vd "audit current + research best practice") โ”‚ โ”œโ”€โ”€ WRITE .NET backend (entity/EF Config/Mig/CQRS/Controller/DbInit)? โ”‚ โœ“ Spec deterministic ยท pattern proven >1ร— ยท >30min ยท โ‰ค2 layer โ”‚ โ†’ implementer-backend (yellow) [Case 1/2/3/5] โ”‚ โ”œโ”€โ”€ WRITE FE 2 app (page/types/component cookie-cutter mirror)? โ”‚ โœ“ UX flow chแป‘t by em main ยท spec deterministic โ”‚ โ†’ implementer-frontend (orange) [Case 1/2] โ”‚ โ†’ BE + FE parallel khi independent (em main chแป‘t DTO shape first) โ”‚ โ”œโ”€โ”€ WRITE test (xUnit Domain policy / Infra handler / authz regression)? โ”‚ โ†’ test-specialist (purple) [test-before bug/critical, test-after feature UAT] โ”‚ โ”œโ”€โ”€ After push code commit (NOT docs-only)? โ”‚ โ†’ cicd-monitor (green) โ€” Gitea poll + bundle hash + Mig prod + smoke โ”‚ โ”œโ”€โ”€ Adversarial pre-commit / heavy diff / wire BE claim / security? โ”‚ โ†’ reviewer (red) โ€” Smart Friend 5-category + live curl โ”‚ โ”œโ”€โ”€ Quick task < 30 min? โ†’ Em solo direct โ”‚ โ””โ”€โ”€ Schema/UX/architecture/cross-stack tight/bug reasoning chain? โ†’ Em solo (Cognition) + investigator pre-flight optional + reviewer pre-commit ``` --- ## ๐Ÿ“‹ Phรขn viแป‡c matrix โ€” split boundary (CRITICAL) | Layer / File | Owner | |---|---| | `src/Backend/SolutionErp.{Domain,Application,Infrastructure,Api}/**` | **implementer-backend** | | `fe-admin/src/**` + `fe-user/src/**` | **implementer-frontend** | | `tests/**` | **test-specialist** | | Mig design / FK strategy / discriminator / schema | **em main solo** (implementer-backend scaffold sau khi chแป‘t) | | UX flow (drawer/tab/modal) / page structure | **em main solo** (implementer-frontend scaffold sau khi chแป‘t) | | Internal SQL/EF/grep audit | **investigator-codebase** | | External docs/CVE/lib/cross-project | **investigator-api** | | Pre-commit verify | **reviewer** (NEVER write) | | Post-deploy verify | **cicd-monitor** (NEVER write) | **Boundary dแปฉt khoรกt:** implementer-backend KHร”NG touch FE ยท implementer-frontend KHร”NG touch BE (chแป‰ Read DTO shape) ยท cแบฃ 2 implementer KHร”NG viแบฟt test (โ†’ test-specialist) ยท test-specialist reveal prod bug โ†’ REPORT em main KHร”NG fix. --- ## ๐Ÿ› ๏ธ Skill assignment (6 skill, re-distributed S39) | Agent | Skills | |---|---| | investigator-codebase | `contract-workflow` + `permission-matrix` + `ef-core-migration` | | investigator-api | `dependency-audit-erp` | | implementer-backend | `ef-core-migration` + `permission-matrix` + `contract-workflow` + `form-engine` | | implementer-frontend | `permission-matrix` | | test-specialist | `contract-workflow` + `permission-matrix` | | reviewer | `dependency-audit-erp` + `contract-workflow` + `permission-matrix` | | cicd-monitor | `iis-deploy-runbook` + `dependency-audit-erp` + `ef-core-migration` | ## ๐Ÿ”ง Tool grant (S39 โ€” +3 RAG MCP per agent) All 7 agent cรณ 5 RAG MCP: `search_memory` + `search_code` (BM25, prefer over Read full file โ€” tiแบฟt kiแป‡m token) + `cross_project_search` + `store_memory` + `list_projects`. Base tools per role (READ: Read/Grep/Glob/Bash [+WebFetch/Search cho api] ยท WRITE: +Edit/Write/Skill). --- ## ๐Ÿ’พ Memory discipline Each agent `.claude/agent-memory//MEMORY.md` persistent diary. Spawn auto-inject 200 lines/25KB. Update BEFORE return (BแบฎT BUแป˜C, entry โ‰ค 1.5K chars). 7 folder: investigator-codebase (history tแปซ investigator) ยท investigator-api (NEW seed) ยท implementer-backend (history tแปซ implementer) ยท implementer-frontend (NEW seed) ยท test-specialist (NEW seed) ยท reviewer ยท cicd-monitor. **End-of-session:** em main SendMessage mแป—i agent flush MEMORY โ†’ ฤ‘แปc 7 update โ†’ synthesize cross-agent โ†’ integrate project memory/session log โ†’ commit/push. --- ## ๐Ÿ“Š Cost reality (budget +50% S39) | Component | Effective tokens billed (after caching) | |---|---| | 7 sub-agents spawn setup | ~1.1M (7 ร— ~155K cache WRITE) | | SendMessages cached | ~500K | | Em main session | ~250K | | **Total per heavy session** | **~1.85M (~9ร— solo)** | | **Optimized (compact + cache + skip trivial + parallel)** | **~1.05M (~5ร— solo)** | **+50% budget** (vs prior ~700K opt / ~1.35M heavy โ†’ now ~1.05M opt / ~2M heavy ceiling). Max 20ร— plan absorbs ~5ร— comfortable. Trade-off justify: split nhแบน hฦกn mแป—i spawn (giแบฃm gotcha #53 truncate) + parallel BE+FE+test (giแบฃm wall-clock) + test-specialist clear coverage gap backlog (quality). --- ## ๐ŸŽฏ Project tunings (SOLUTION_ERP) **Stack:** .NET 10 Clean Arch + CQRS MediatR + EF Core 10 + SQL Server + 2 React 19 Vite 8 FE + Gitea CI + Windows IIS. **State (S38 โ€” 2026-05-28):** 40 mig ยท 84 tables ยท ~223 endpoints ยท 53 FE pages ยท 130 test PASS ยท 53 gotchas ยท 27 memory ยท 6 skills ยท **7 sub-agents** ยท Phase 10 COMPLETE 11/11 Plan G-*. **Windows MAX_PATH:** project path nested + Dropbox-managed โ†’ implementer KHร”NG dรนng `isolation: worktree`. Default branch OK. **UAT live mode (Phase 9):** `feedback_uat_skip_verify` โ€” skip `dotnet test` mแป—i chunk, vแบซn `npm run build` ร— 2. test-specialist test-after khi UAT confirm; test-before cho bug/critical algo. --- ## ๐Ÿ”— References - [Anthropic Building Effective Agents](https://www.anthropic.com/engineering/building-effective-agents) - [Cognition "Don't Build Multi-Agents"](https://cognition.ai/blog/dont-build-multi-agents) - BVAAU 7-agent reference: `D:\Dropbox\CONG_VIEC\BENHVIEN_A_AU\SOURCE_CODDE\.claude\agents\` (adapted S39 โ€” split trแปฅc + 5 RAG tool; SOLUTION_ERP giแปฏ 6 skill + backend/frontend split thay domain/infra cho 2-FE-app fit) - Memory: `feedback_per_chunk_commit` ยท `feedback_uat_skip_verify` ยท `feedback_audit_reuse_before_clone` ยท `feedback_implementer_truncation_mitigation` (gotcha #53) ## โš ๏ธ CLI restart required Agent definition change (S39 split 4โ†’7) โ†’ **anh main restart Claude Code CLI** ฤ‘แปƒ registry hot-reload (per S27 lesson โ€” model:inherit + new agent files). Verify post-restart: spawn smoke test mแป—i agent mแป›i (investigator-api / implementer-frontend / test-specialist) confirm load OK.