Agent Architecture9 min readยท

Shared Context for Multi-Agent Systems: Why Agent Swarms Need a Common Context Graph

A research swarm sends three subagents after the same question. Two of them pull the same documents. One cites a 30-day return window and another cites 45, and the handoff to the writer agent drops the source.

A research swarm sends three subagents after the same question. Two of them pull the same documents. One cites a 30-day return window and another cites 45, and the handoff to the writer agent drops the source. The fix is to split context by owner. Private memory holds per-turn state and agent notes, and every agent reads business facts from one shared, governed context graph. In Sanity Context, that graph is the Content Lake, which every agent queries through one read-only MCP endpoint.

The stakes go up with every agent you add. Anthropic reports that agents use about 4x more tokens than chat, and multi-agent systems use about 15x. When subagents repeat each other's retrieval, part of that spend pays for the same documents twice. When they ground against different copies of a fact, customers get contradictory answers, and nobody can trace which agent trusted which source.

This guide treats "agent memory vs a shared knowledge base" as a question of ownership and lifetime, not a choice between two products. It covers why swarms fail without shared state and the three ways to share context. It also covers what a shared layer has to provide (types, permissions, freshness, and provenance) and how Sanity Context provides it.

Why do multi-agent systems break down without shared state?

Multi-agent systems break down without shared state because each agent builds its own picture of the world, and those pictures drift apart. Three failures show up first: duplicated retrieval, conflicting facts, and lost handoffs. None of them is a model problem. They are architecture problems, and a better prompt will not fix them.

Duplicated retrieval happens when two subagents run nearly identical searches because neither knows what the other already found. Anthropic's write-up of its multi-agent research system reports that agents use about 4x more tokens than chat, and multi-agent systems about 15x. When subagents overlap, some of that spend buys the same documents twice. Secondary analyses of orchestrator-worker setups also describe the opposite problem: coverage gaps, where every agent assumed another one had a topic covered.

Conflicting facts happen when agents ground against different copies of the same claim. A support agent reads a help center that says returns are accepted within 30 days, and a sales agent reads a product page that says 45. Each answer matches its source, and the system as a whole is still wrong. If there is no single place where the conflict is visible, nobody resolves it.

Lost handoffs happen when one agent passes a summary to the next and the summary leaves out the reference, version, or constraint that mattered. The receiving agent cannot follow a pointer it never got.

Research supports the pattern. Cemri et al., "Why Do Multi-Agent LLM Systems Fail?" (NeurIPS 2025), analyzed more than 1,600 execution traces across seven multi-agent frameworks. They found 14 failure modes in three groups: system design, inter-agent misalignment, and task verification. Shared state addresses inter-agent misalignment most directly. Agents that disagree about what is true, or about who did what, cannot coordinate, however capable each one is on its own.

Anthropic's caveat is about passing context, not sharing it

Anthropic reports that its lead agent with subagents outperformed a single Opus 4 agent by 90.2% on its internal research eval. It also warns that domains "that require all agents to share the same context or involve many dependencies between agents are not a good fit for multi-agent systems today." That warning applies to context that agents have to pass to each other. Dependencies get expensive when every agent carries context forward by hand. They get cheaper when agents read it from one governed source.

What are the three ways to share context between AI agents?

There are three ways to share context in a multi-agent system: each agent keeps private memory, agents pass messages to each other, or all agents read and write one shared context graph. Most production systems mix all three, so the useful question is which kind of context belongs in which pattern.

With private agent memory, each agent keeps its own persistent notes, summaries, and session state. Memory layers such as Mem0, Zep, and Letta are built for this. Private memory is the right home for what one agent learned on its own, such as a user's preferences, a running summary, or a playbook it wrote for its next session. It is the wrong home for facts every agent must agree on, because each private copy goes stale on its own schedule.

With message passing, agents hand results to each other directly, often through an orchestrator. Anthropic's research system uses this orchestrator-worker shape, with a lead agent that spawns subagents. Frameworks such as LangGraph add shared graph state and checkpointing within a run. Message passing works well for parallel, independent subtasks. Its weakness is that the context lives inside the run and the code. It disappears when the run ends, and the business entities it mentions are plain strings, not references.

A shared context graph is one structured source that every agent queries. Entities have types, they reference each other, and every agent sees a change as soon as it is made. It is the only one of the three patterns where a correction made once reaches every agent. It is also the only one where someone outside the engineering team can see and govern what the agents know.

The three patterns do not compete. Private memory covers what an agent knows about itself, message passing covers coordination inside a task, and a shared context graph covers what the organization knows. Problems start when one pattern is stretched to do all three jobs.

Illustration for Shared Context for Multi-Agent Systems: Why Agent Swarms Need a Common Context Graph
Illustration for Shared Context for Multi-Agent Systems: Why Agent Swarms Need a Common Context Graph

What are best practices for agent memory vs a shared knowledge base?

The best practice is to split context by lifetime and owner. Keep per-turn state and agent-authored notes in private agent memory, and put instructions and retrieved business content in a shared, governed knowledge base. Sanity's field guide on production agents describes four kinds of context, each with its own lifetime, owner, and access pattern. Those four kinds map directly onto the memory vs shared knowledge base question.

Static instructions, such as brand voice, scope, and policy, are scoped to a release and owned by product or brand teams. They belong in the shared layer, because every agent in the swarm should follow the same rules.

Per-turn state, such as the current user, cart, or conversation, lasts one turn and is owned by the application. It belongs in private memory or in the request itself. Sharing it across agents adds leakage risk and nothing else.

Retrieved content, such as product data, documentation, and support articles, is stable and owned by the content team. It belongs in the shared layer, because this is the material where duplicated retrieval and conflicting facts show up.

Agent-authored notes, such as summaries and reflections an agent writes for its future self, persist across sessions and are owned by the agent. By default they belong in private memory. Move a note into the shared layer only when a person decides it has become organizational knowledge.

The field guide states the risk plainly: "If your stack treats all four as one bucket, the wrong people end up making the wrong decisions." The compliance officer who approves what agents can say is not the engineer tuning retrieval. A stack that blends memory and knowledge forces one of them to do the other's job.

Three practical rules follow. First, never let an agent's private memory become the source of truth for a business fact. Second, give every shared fact one canonical location that agents reference rather than copy. Third, make promoting an agent note into shared knowledge an explicit step that someone can review.

What does a shared context layer need to work for an agent swarm?

A shared context layer for an agent swarm needs four properties: typed entities with references, permissions scoped to each agent, freshness without a sync job, and a record of who changed what. If any one is missing, shared context stops being an asset and becomes a faster way to spread mistakes.

Typed entities with references mean that a product, a policy, or a location is a document with a schema, and documents point at each other instead of repeating each other. If fifty product pages reference one return policy instead of pasting it in, there is one copy that can drift instead of fifty. Types also tell an agent where to look. A field called price is a better retrieval target than a paragraph that happens to mention a price.

Permissions per agent mean that a billing agent and a marketing agent do not see the same context. The cleanest approach is auth forwarding, where the agent acts with the permissions of the user or role it serves. The agent then inherits row-level rules that already exist, so nobody has to maintain a second permission system for agents.

Freshness means that a change made by an editor, a system, or another agent is visible to every agent on the next query. If the shared layer is a copy of the real content behind an indexing pipeline, every agent is only as current as the last successful sync.

Provenance means that every fact and every change records who made it and when, whether a person or an agent. Without it, a swarm cannot answer the questions auditors and incident reviews ask: which source did the agent trust, and who changed it last?

A 2026 preprint on governed shared memory for multi-agent LLM systems describes related failure modes: unauthorized leakage, stale propagation, contradiction persistence, and provenance collapse. Each one is what happens when one of the four properties is missing. The Model your business pillar applies here. A shared layer is only as useful as the schema that describes the business.

How does Sanity Context work as a shared context graph for many agents?

Sanity Context works as a shared context graph by letting many agents query the same Content Lake. In the Content Lake, a schema types each document, references link documents to each other, and results are current at request time. Sanity is the AI Content Operating System, the intelligent backend for companies building AI content operations at scale. Sanity Context is the part that gives agents structured, governed access to that content. It has an MCP, a knowledge base, and an ingest path.

Agents read through Context MCP, a hosted read-only endpoint that any agent loop can connect to. It has two retrieval modes. GROQ mode queries the dataset at request time, with no build step and nothing to keep in sync. It needs a deployed schema (sanity schema deploy, Studio v5.1.0 or later). GROQ follows references, so an agent can fetch a product and resolve stockLocation->{ name, available } in the same query. That means one agent can hand off a document ID instead of a lossy summary. With dataset embeddings enabled, one GROQ query can combine structured filters with semantic ranking by using text::semanticSimilarity() inside score(). Semantic similarity only ranks results, so the filters still decide which documents qualify.

Knowledge Base mode (Beta) serves an index built ahead of time from datasets, websites, PDFs, and support databases. Each MCP connection serves one source type. If both are attached, the dataset source wins, and you can set the mode per connection with ?mode=groq or ?mode=knowledge_base.

When agents need to write back to the shared graph, they go through the Agent API or the Content Lake APIs, not Context MCP. The split is deliberate. Reads are broad and cheap, and writes go through a schema-aware path into the same governed documents editors work in. This is the Power anything pillar applied to agents: one Content Lake behind the website, the apps, and every agent in the swarm.

โœจ

Freshness you don't have to maintain

From Sanity's guide to hybrid retrieval: "When retrieval is wired into your content backend, the freshness problem stops being something you maintain. When it's a separate vector DB plus glue code, freshness becomes a permanent line item on your roadmap." In a swarm, that line item multiplies. Every agent that reads a stale index repeats the stale fact.

How do editors govern a shared context graph that AI agents read and write?

Editors govern a shared context graph in Sanity by writing agent instructions and business content in the Studio. That content goes through the same drafts, permissions, history, and release process as the website. Governance is what separates a shared context graph from a shared index. An index tells agents what exists. Governance decides what is true and who is allowed to change it.

Agent instructions live as documents. Nearform put it directly: "Storing the system prompt in a Sanity document is genuinely useful. Editors tuned the agent's voice without any code changes." Vipps wanted product managers, not engineers, to own prompts. Splitting the prompt document into separate fields, such as voice, scope, and policy, is a form of access control, because Roles & Permissions can control who edits each field. Content Releases then stage agent behavior the way a team stages a website launch. A new policy can be previewed before it ships, then updated once for the web, apps, and customer agents together.

Conflicting facts get resolved by a person. Knowledge Bases (Beta) detect when the same fact differs across sources and raise an Issue that shows both claims with their sources. For example, a help center might say 30 days for returns while a product page says 45. Someone picks the ground truth, and an Instruction records which source to trust. Each Instruction is tied to its sources, so a build retires it automatically when those sources change.

Provenance comes from history and audit trails on every document. Auth-forwarded tools log each action against the user rather than the model. Workflows (Beta) turn audits into queries, so a question like what was published without legal review becomes a single GROQ query.

This is the Automate everything pillar with a person in the loop. Agents can act at scale because editors can see, stage, and reverse what the agents know.

โ„น๏ธ

Conflict detection is in Beta

Knowledge Bases and Workflows are in Beta. They are opt-in and may change before general availability. A Knowledge Base build raises an Issue when sources disagree, for example 30 days vs 45 days for returns, and shows each claim next to its source so a person can choose the ground truth.

Shared context layers for multi-agent systems compared

FeatureSanityPineconepgvector / NeonContentful
Typed entities and referencesA schema types every document in the Content Lake, and GROQ follows references such as stockLocation->{ name, available }, so agents resolve related entities in one query.Vectors carry metadata fields. Relationships between business entities live in your application or another system and are joined in glue code.Strong here: Postgres tables, foreign keys, and joins give typed relations natively, with vector columns in the same database.Content types with reference fields give typed, linked entries. Agent retrieval over them is usually assembled with external search through the App Framework.
Freshness when content changesGROQ mode queries the dataset at request time with no build step. Dataset embeddings are tied to content, so there is no separate vector pipeline to keep in sync.Index updates are upserts you trigger. Changes, deletes, and re-embedding run through a pipeline your team builds and operates.Rows update transactionally. Embeddings refresh only when a job or trigger you build and maintain recomputes them.Webhooks signal publishes. Keeping an external search or vector index current means owning the sync and re-embedding pipeline.
Hybrid retrievalNative: text::semanticSimilarity() inside score(), blended with match() and structured filters in one GROQ query.Supported through sparse-dense vectors and metadata filters. Structured filtering depends on which metadata you copied into the index.Possible by combining pgvector similarity with Postgres full-text search in SQL. You write the ranking and blending logic yourself.Assembled from native content queries plus an external search or vector service, connected through apps or custom code.
Conflicting facts across sourcesKnowledge Bases (Beta) raise an Issue when sources disagree, show each claim with its source, and record the chosen ground truth as an Instruction.The index holds whatever is embedded. Detecting that two chunks contradict each other takes application logic or a separate evaluation step.Constraints can enforce consistency in structured rows. Contradictions in prose, or across ingested sources, need custom detection.Editorial workflows can catch conflicts inside a space. Detecting conflicts with external sources, such as a help center, is custom work.
Governed agent instructionsSystem prompts are Studio documents with field-level permissions, drafts, and history. Content Releases stage agent behavior before it ships.Not designed to hold instructions. Prompts usually live in code, in config, or in a separate prompt-management tool.Prompts can be kept as rows, but your team has to build drafts, review, staging, and an editing interface.Prompts can be modeled as entries with roles and a publishing workflow. Staging changes for agents and delivering them to agents is assembled.
Agent access and provenanceAgents read through the hosted read-only Context MCP endpoint and write through the Agent API. Document history and audit trails record who changed what.API keys and namespaces scope and partition access. Provenance for each change is metadata you choose to write alongside vectors.Postgres roles and row-level security give fine-grained access. Recording who changed what needs audit tables or triggers you add.Roles, environments, and entry version history track editorial changes. Agents connect through its APIs, and agent-level audit is left to the integration.