We're building an on-premises AI email assistant: it watches client mail in Microsoft 365, gives every actionable email an owner and a deadline, escalates when nobody answers, and drafts replies that a person must approve before anything is sent. The plan put the full product at about 260 person-days across three phases. In the first two days we had the foundation and a working first slice in 110 commits. The work was done by four coding agents, one of them acting as the lead.

#1. The Team

Every agent has a role, an area it owns, and a reviewer. That's all written in a team file at the root of the repository, so it's something the agents read rather than something I keep repeating:

AgentRoleWhy it got that role
Claude CodeLead: plans, delegates, reviews, builds, tests, mergesHolds the whole picture and the merge rights
CodexBackend core and integrationsLong-running, well-specified backend tasks
CursorArchitecture, AI, access control, securityCareful edits to sensitive code, close supervision
AntigravityFront end and end-to-end testsBuilding and checking UI in a browser

Reviews are paired, so no agent's work merges on its own word, and a person approves every merge. A short list of sensitive areas (authentication, anything that can send email, database migrations) always gets an extra review.

#2. Four Documents That Make It Work

Diagram
Spec            what to build    (numbered requirements, acceptance tests)
Rule book       how to build it  (rules every agent reads first)
Team file       who builds what  (ownership, reviewers, phases)
Task briefs     what to do next  (one brief per agent)
        │
        ▼
lead ─▶ worktree per task ─▶ agent ─▶ lead review ─▶ build + tests ─▶ merge
                                                       │
                          handover file ◀── status ────┘
  • The spec has numbered requirements and acceptance tests. Commits, branches and pull requests reference requirement IDs. If code and spec disagree, the agent stops and asks.
  • The rule book is a single AGENTS.md. Each tool's own rules file points at it instead of copying it, so there's only one version.
  • The team file holds ownership, review pairs, sensitive areas and the phase plan.
  • Task briefs give each agent its requirements, the area it owns, what to reuse, its acceptance tests and its handoffs, plus a dependency graph showing who waits for whom.

#3. Rules That Block a Merge

An email assistant handles other companies' mail, so a few rules aren't style guidance. Breaking one blocks the merge, whatever else the change does. In general terms:

  1. Nothing is sent without a recorded human approval. No background job or template can skip it.
  2. Deny by default. Every endpoint checks permission and scope on the server. A hidden button is never the control.
  3. Tenants never mix. No query, cache entry, log line or AI request may combine two clients' data, and that's enforced centrally, not left to each query.
  4. Email text is data, not instructions. Nothing inside an email can change a rule or trigger an action.
  5. No secrets in the repository.

The rules are also tests. A test fails if any API endpoint has no authorization requirement, and every new endpoint ships with the same three: not signed in, wrong permission, wrong client.

Write rules an agent can check

"Be careful with security" changes nothing. "Every endpoint declares its permission, or is explicitly anonymous with a comment saying why" is something an agent can follow, a test can enforce, and a reviewer can grep for.

#4. How the Lead Runs the Agents

Claude Code doesn't write most features. It writes the briefs, starts each agent in its own git worktree on its own branch, and runs every agent in a restricted mode: sandboxed edits and commands for one, edits only for another, nothing beyond accepted edits for the third. None of them commits, pushes or creates database migrations. They run in a terminal panel I can watch rather than as hidden background processes.

#The review routine

Every agent result goes through the same steps before it merges:

  1. Read the diff, and check it only touches the area that agent owns.
  2. Run a quick scan for risky patterns that must come back empty: raw HTML injection, tokens in browser storage, bypassing the tenant filter, secrets.
  3. Create database migrations centrally, one per merge, so parallel agents never produce conflicting ones.
  4. Build with zero warnings (warnings are errors), and run the tests against a real database in a container, not a mock.
  5. Take screenshots of new screens with a headless browser.
  6. Commit with co-author lines for the agent, merge, run everything again on the integration branch, and report to the person in charge.
Ownership produces honest handoffs

One agent's status report listed what it hadn't done and why: the tests it needed were in an area another agent owned, so it left them alone and wrote down the missing cases for the owner. Without ownership rules, it would have just edited the other agent's files.

#5. Surviving Token Limits

A lead running for two days will hit its usage limit. When that happens, another agent takes over as backup lead. Continuity lives in one handover file the lead keeps current: what's merged and the test counts, which agent is on which branch, where each one is running, the review routine, and the safe launch command for each agent. Its first lines set the limits: do nothing without a person's go-ahead, never push, never delete work that isn't merged.

The handover file was also useful between my own sessions. Anyone could pick up the work from a single page.

#6. The AI Part: Measured, Not Assumed

Classification runs on a local model served by Ollama, because client mail can't leave the building. The classifier decides category, priority, whether a reply is needed, whether the mail is automated noise, any deadline asked for, whether it's a chaser, and whether the client is saying "it's done".

Prompt changes are judged by a small evaluation set: invented emails (never real ones), each with the expected answer. On qwen3:8b:

PromptThinkingScoreAvg time
v5default26 / 35—
v6default26 / 3743 s, timeouts
v6low35 / 374 s
v6none33 / 371 s
v7 (whole-conversation summary)low41 / 434.1 s

The biggest gain didn't come from the prompt. It came from turning thinking down: with default reasoning the model ran for 43 seconds and timed out, and with low it was both faster and more accurate. The two remaining misses are written down, not hidden.

Treat the model as untrusted input

The AI only classifies and drafts. It can't send, close or reassign anything, and instructions inside an email are treated as text. Even a perfect score wouldn't change that.

#7. What Two Days Produced

  • Foundation: .NET 10 APIs, PostgreSQL, Redis, Angular apps, everything in Docker Compose with live reload.
  • Sign-in and access: single sign-on with MFA, passkeys, server-side sessions, roles with scoped permissions, and tenant separation enforced in the data layer.
  • Mail: Microsoft Graph delta sync, client identification, one conversation across several people's inboxes.
  • Work: AI classification, a conversation summary updated on every message, work items with business-hours deadlines, routing, snooze and reassign, notifications, and an audit log.

That's not the whole product. Drafting and approval, escalation and the client portal are later phases. But the foundation is the part that usually takes weeks, and every later feature depends on it being right.

#8. Takeaways

  • Write the spec first. Numbered requirements and acceptance tests give agents something to build against and reviewers something to check.
  • One rule book that every tool points at, and one team file for ownership and review pairs.
  • Pick agents by strength, give each its own area and worktree, and run them in restricted modes.
  • The lead's job is review, integration and proof: pattern scans, zero-warning builds, real-database tests, screenshots.
  • Keep a handover file so anyone can take over mid-flight.
  • Measure the AI with an eval set before and after every prompt or model change.

The same idea at a smaller scale is in migrating worker services to .NET 10 with skill files, and the day-to-day version with Herdr is in my AI dev team in Herdr.