Multi-Agent Collaboration Architecture: Using a Versioned Repository as Shared Context
This article explains a practical architecture for multiple AI agents working in the same project, where the real bottleneck is shared context rather than model capability. It covers why a versioned repository is a better source of truth than shared chat logs, a four-layer reference architecture, tiered context loading with token budgets, concurrency and conflict handling, least-privilege permissions by capability, observability and cost governance, common anti-patterns, and a step-by-step adoption path.
1. The Real Problem: Agents Lack Shared Context, Not Model Capability
When a second or third AI agent joins a team, the bottleneck is rarely model capability. It is that the agents do not know what each other has already done. Human teammates align through meetings, documents, and hallway conversations. Agents need alignment to land on a medium that is persistent, versionable, and safe for concurrent access.
Choosing that medium well solves most of the problem. In software development, the natural choice is a versioned repository (commonly hosted on code hosting platforms, referred to generically in this article). The reason is direct: it already has the four properties agent collaboration requires — persistence, traceability, concurrency, and access control.
What is shared here is not just source code, but a complete set of “team facts”:
- Architecture documents and system boundary descriptions
- Architecture decision records (ADRs), meaning the reasoning chain behind “why we did it this way”
- Issue and defect entries, including reproduction steps and expected behavior
- Change proposals and review comments
- Commit history and diffs, meaning “what was changed, when, and by whom”
The last item matters especially for agents: a diff is the most compact “intent-to-result” sample available anywhere, closer to real engineering semantics than any natural language description.
2. Why a Repository Instead of a Shared Chat Log
Many teams’ first instinct is to create a shared conversation space where agents can “shout” at each other. This works in a demo and degrades quickly in a real project, for three reasons.
First, chat logs carry no authoritative semantics. You cannot tell from the text alone whether a statement is a conclusion or a rejected draft, whereas a merge record in a repository comes with a built-in state machine (proposed, merged, closed).
Second, chat logs are hard to search incrementally. The context window is a scarce resource, and an agent can only carry a tiny slice of history at a time. A repository supports targeted pulls by path, by label, and by time, which means loading context on demand instead of dumping everything in.
Third, chat logs have no conflict resolution mechanism. Concurrent work by multiple people and multiple agents inevitably produces disagreement, and the repository’s merge and conflict flow is already a mature protocol for converging on a decision.
The conclusion: treat the repository as the single source of truth for shared memory, and keep chat as a thin channel for notification and scheduling only.
3. Reference Architecture: Four Layers
A workable shared architecture can be split into four layers.
- Fact layer: files and history in the repository, the only authority.
- Index layer: structured extraction over the facts, producing searchable entries (path, summary, labels, related IDs).
- Scheduling layer: task dispatch, locks and leases, conflict escalation. It stores no business facts itself.
- Execution layer: multiple agent instances, each holding a limited context and limited tool permissions.
The key design principle: the execution layer is stateless, the fact layer is unambiguous. An agent can be destroyed and rebuilt at any time, with the recovery point coming entirely from the fact layer.
4. Tiered Context and Budget Control
Shared does not mean fully visible. Split context into three tiers, each with an explicit read policy.
- Resident tier: directory conventions, coding standards, build and test commands, commit message format. Small and slow-changing, so it can occupy budget long term.
- Task tier: document sections, interface definitions, and failing cases directly related to the current entry. Loaded dynamically per task.
- History tier: commit history, review discussions, past decisions. Not loaded by default; retrieved by keyword only when archaeology is needed.
Illustrative context assembly logic (pseudocode):
def build_context(task, repo):ctx = load_convention(repo) # resident tier, roughly 1~2k tokensctx += load_related_docs(task, repo, limit=3)ctx += load_failing_case(task, repo) # task tierif task.need_history:ctx += search_history(task.keywords, top_k=5) # history tier, on demandreturn ctx[:BUDGET]
The point is not the code itself but budget awareness: treat tokens as a finite resource and allocate them explicitly, so the agent does not drown in irrelevant history.
5. Concurrent Writes: Treat Conflicts as the Norm
Once work is shared, write conflicts go from occasional to constant. Four constraints make this manageable.
- One branch per task: every change for an entry happens on its own branch; writing directly to the main branch is forbidden.
- Path leases: introduce short-term leases for high-conflict directories (global config, shared type definitions). The lease is written to the fact layer and expires automatically, avoiding deadlock.
- Small commits: a single commit expresses one intent, lowering the cognitive cost of resolving merge conflicts.
- Conflicts are input: conflicting sections are not merged by guesswork. They are written back as entries awaiting human adjudication, with both sides’ reasoning summaries attached.
One thing should be explicit: agents must not have “force overwrite” capability. Any write path that bypasses review turns into unmaintainable historical debt within weeks.
6. Permissions and Boundaries: Grant Agents Least Privilege
Permissions are where a shared architecture most easily gets out of control. Authorize by capability rather than by identity:
| Capability | Read | Write branch | Merge to main | Close entry |
|---|---|---|---|---|
| Exploration agent | Yes | No | No | No |
| Implementation agent | Yes | Yes | No | No |
| Review agent | Yes | No | Human recommended | No |
Two bottom lines also apply: sensitive credentials never enter the repository and exist only as references in the execution environment; destructive operations (deleting branches, rewriting history) are not exposed to automated executors.
7. Observability and Cost Governance
After sharing, the system must be able to answer three questions: who changed what, why, and at what cost. Practical measures include requiring commit messages to reference entry IDs; keeping review records as an audit trail of decisions; and metering context size and tool call counts per task to form an optimizable cost baseline. For large artifacts and logs, generic cloud capabilities such as object storage, logging services, and monitoring and alerting can carry the load, keeping the fact layer separate from runtime data.
8. Common Anti-Patterns
- Letting agents read the full history: context is exhausted quickly and output quality drops off a cliff.
- Carrying conclusions in chat messages: conclusions scatter across a timeline, unsearchable and unauditable.
- Sharing one long-lived, never-changing agent: state drift becomes severe; use short-lived agents rebuilt from the fact layer instead.
- No bidirectional link between entries and commits: later nobody can answer “why does this code exist”.
9. Adoption Path
Step one, bring convention documents, decision records, and defect reproduction steps into the repository and normalize them; this is the prerequisite for all automation. Step two, connect a read-only agent and validate retrieval and comprehension quality. Step three, open branch writes and add a review gate. Step four, gradually enable implementation agents and fill in metering and alerting. Each step is accepted based on “is the fact layer clearer”, not “is the agent more autonomous”.
The hard part of sharing AI agents among a team was never on the model side. It is whether the team is willing to settle knowledge into structured, versionable facts. The repository is the most suitable shared space precisely because it forces a team to turn “I assumed everyone already knew” into “it is written down here”.
