Skip to content
Zane Hu

AI Engineering Governance · Multi-Agent SOP

1 Person + N Agents in Production: Isolated Slots, 5-Layer AST Guardrails & Split Review

Updated 2026-11 · ~10 min read · Open-source CLI: agent-arch-guard

Scaling engineering throughput with multiple AI coding agents requires treating codebase hygiene like a CI compiler check: upfront discovery, hard branch locks, AST diff ratchets, and strict generator-evaluator separation.

Dual-layer AI command model with isolated WIP slots and 5 deterministic AST verification gates
Figure 1. Production multi-agent workflow: separating planning from execution slots while gating every merge behind AST rules, 300-line ratchets, and independent review.

1. Why markdown instructions fail as headcount shifts to AI agents

As industry research on AI-assisted codebases consistently highlights, two failure modes explode when parallel agents write business code: Discovery Blindness (the agent does not realize your shared @acme/ui or error helper exists) and Copy-Paste Clones (LLMs optimize to make the local build green as fast as possible, duplicating formatMoney(), inline CSS, and raw Response.json() across files).

Adding longer paragraphs to AGENTS.md or .cursorrules slows down without preventing drift—natural language advice is always negotiable under context pressure. Only deterministic filesystem locks and AST syntax gates hold under multi-agent concurrency.

2. Dual-window command, WIP <= 3, and read-only main

Running five agents against the same working checkout creates instant merge conflicts and cross-feature contamination. My operating SOP enforces three physical boundaries:

  • Strategy vs. execution split: One master session manages architecture specs, issue triage, and merge ordering; worker sessions execute strictly inside isolated git worktree slots capped at WIP <= 3 with one task per branch.
  • Read-only main enforced by pre-commit: Commits directly on the reference trunk fail immediately at the Git hook level—forces clean branching even if an agent loses context.
  • Rule of Three escalation: Any agent that fails verification twice must stop editing and escalate root assumptions instead of hallucinating workarounds in a loop.
#!/usr/bin/env sh
# .git/hooks/pre-commit: physically prevent AI agents from committing on protected main
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "DETACHED")
if [ "$BRANCH" = "main" ]; then
  echo "BLOCKED: main is a read-only reference trunk. Checkout an isolated slot branch."
  exit 1
fi

3. Craft vs. Use and the 5-layer quality pipeline

Before touching a business screen, agents operate strictly under Use Mode—they inspect compact llms.txt and SDK symbol indexes and compose shared primitives. Only when a genuine cross-app primitive is missing do they switch into Craft Mode to extend the foundation library first.

To enforce that boundary mechanically, I distilled our internal Tree-sitter verification scripts into an open-source zero-dependency CLI: agent-arch-guard (Node 22 + ast-grep + ripgrep):

# 1. Incremental PR check against main using git --no-optional-locks (freeze legacy debt)
node src/cli.mts check --base main --require-ast-grep --cwd /path/to/repo

# 2. Structural clone, duplicate helper, oversized file & orphan dead-module audit
node src/cli.mts noise --cwd /path/to/repo
Defense Layer Concrete Artifact What It Eliminates
1. Zero-Search Discovery Compact llms.txt + SDK Index Discovery Blindness—exposes shared UI/core exports before coding starts.
2. Trunk & Slot Isolation Worktree slots + pre-commit hook Multi-task branch pollution and accidental edits on clean main.
3. AST Diff Ratchets agent-arch-guard check --base main Ignores comments/strings; catches raw form tags, inline style={{}}, raw Response.json, scattered process.env, and >300-line growth.
4. Structural Noise Audit agent-arch-guard noise Detects copied function hashes (SHA-256), duplicate format* helpers, and zero-import orphan files.
5. Split Evaluator Review Independent read-only session + AppSec Prevents author confirmation bias; validates dependency/secret/SAST scans and unmerged worktree checks before release.

4. Why diff ratchets beat big-bang rewrites

Turning a strict rule set onto an existing codebase all at once usually floods teams with 400 legacy errors and leads developers to disable the check completely. Instead, agent-arch-guard compares only newly added or modified diff lines against the merge base, and forbids net line growth in modules already exceeding 300 lines—while explicitly crediting refactors that shrink them.

Explore the rules, incremental diff parser, noise scanner, and 14 automated tests in github.com/zanehu-ai/agent-arch-guard.

Back to Writing