Skip to main content

Shared Memory for Multi-Agent Systems: Patterns, Trade-offs, Pitfalls

Four proven patterns for shared memory in multi-agent AI systems, compared side by side, plus the pitfalls to avoid in production.

Updated 8 min readMarkdown
Shared Memory for Multi-Agent Systems: Patterns, Trade-offs, Pitfalls

Your first agent works. It remembers what you told it, answers well, and feels smart. Then you add a second agent, then a third, and suddenly the system contradicts itself, repeats work, and forgets things one agent knew a minute ago.

That is the shared memory problem. Single-agent memory is mostly about fitting history into a context window. AI agent memory systems in a multi-agent setup also have to answer harder questions: who can write, who can read, whose version wins, and what happens when two agents disagree.

In this article we walk through four proven patterns for shared memory for AI agents, compare them side by side, and cover the pitfalls that show up in production. You will leave with a decision framework for your own multi-agent memory architecture.

Prerequisites: basic familiarity with LLM agents and tool calling, and comfort reading short Python snippets. The ideas are framework-agnostic, so they apply whether you use LangGraph, CrewAI, AutoGen, or your own orchestrator.

Why shared memory is the hard part

In a single-agent loop, memory has one writer and one reader. Everything is consistent by construction.

In a multi-agent system, memory becomes a shared resource, and shared resources bring classic distributed-systems problems:

  • Staleness: Agent B acts on facts Agent A already updated.
  • Conflicts: two agents write different values for the same fact.
  • Bloat: every agent dumps everything, and the context fills with noise.
  • Leakage: an agent sees information it should not use for its task. Good agent memory architecture is mostly about controlling these four things deliberately instead of by accident.

What AI agent memory actually is

Before choosing a pattern, separate the layers. Most confusion comes from mixing them.

Short-term (working) memory

The current conversation and task state inside one agent's context window. It is fast, but it disappears when the run ends.

AI agent long-term memory

Facts, preferences, and past outcomes that persist across sessions. This usually lives in a database or vector store outside the model.

Shared memory

Any memory that more than one agent can read or write. This is the layer that creates coordination problems, and it is the focus of this article.

Rule of thumb: keep working memory private to each agent, and make shared memory explicit, small, and governed.

Pattern 1: Shared scratchpad (blackboard)

All agents read from and write to one common workspace, like a whiteboard in a meeting room.

class Blackboard:
   def __init__(self):
       self.entries = []
 
   def write(self, agent: str, key: str, value: str):
       self.entries.append({"agent": agent, "key": key, "value": value})
 
   def read(self, key: str):
       return [e for e in self.entries if e["key"] == key]

The code above keeps every write with the author's name, so you never lose provenance. We append instead of overwrite so that conflicts stay visible and can be resolved later.

Best for: small teams of agents solving one task together.

Watch out for: the scratchpad grows fast. Without pruning, it becomes the noise problem all over again.

Pattern 2: Vector memory for agents

Agents store memories as embeddings and retrieve the most relevant ones by semantic similarity. This is what most people mean by vector memory for agents.

def remember(store, agent, text, metadata=None):
   store.add(
       text=text,
       embedding=embed(text),
       metadata={"agent": agent, **(metadata or {})},
   )
 
def recall(store, query, agent_filter=None, k=5):
   return store.search(embed(query), k=k, filter=agent_filter)

We attach metadata (author agent, timestamp, task id) on every write. That makes filtered recall possible, so an agent can ask for "memories from the billing agent about this customer" instead of searching everything.

Best for: large, fuzzy knowledge such as past conversations, documents, and user history.

Watch out for: similarity is not truth. The nearest memory is not always the correct or the latest one.

Pattern 3: Structured state store

Instead of free text, agents read and write typed fields in a shared state object or database row.

from typing import TypedDict, Optional
 
class SharedState(TypedDict):
   customer_id: str
   intent: Optional[str]
   order_status: Optional[str]
   last_updated_by: str
   version: int

Typed fields make agent context management predictable: every agent knows exactly where a fact lives. The version field lets you detect conflicting writes, which we cover in the pitfalls section.

Best for: workflows with well-defined facts, such as support tickets, orders, and approvals.

Watch out for: rigid schemas. Anything that does not fit a field gets lost.

Pattern 4: Event log with per-agent views

Agents never edit shared facts directly. They append events to a log, and each agent builds its own view from the events it cares about.

events = []
 
def emit(agent, event_type, payload):
   events.append({"seq": len(events), "agent": agent,
                  "type": event_type, "payload": payload})
 
def view_for(agent_types):
   return [e for e in events if e["type"] in agent_types]

This is event sourcing applied to agents. The log is the single source of truth, and each agent only loads the slice relevant to its role. That keeps prompts small and makes every decision auditable.

Best for: larger systems where traceability and debugging matter.

Watch out for: more engineering work, and you still need a policy for compacting old events.

Comparison table

Pattern Strength Weakness Conflict handling Best fit
Shared scratchpad Simple, transparent Grows noisy fast Manual, visible in history Small agent teams, prototypes
Vector memory Scales to large knowledge Semantic match is not truth Weak, needs metadata and recency Long-term recall, user history
Structured state Predictable, easy to validate Rigid schema Strong, with versioning Defined workflows, ops tasks
Event log + views Auditable, small prompts Higher complexity Strong, append-only Production multi-agent systems

In practice, mature systems combine two patterns: a structured state store for hard facts and a vector store for fuzzy history, often fed by an event log.

Agent context management: what each agent should see

More shared memory does not mean better answers. Give each agent the minimum it needs.

  • Scope by role: a billing agent does not need the full chat transcript.
  • Summarize before sharing: pass distilled facts, not raw dumps.
  • Rank by recency and relevance: newer, higher-confidence memories first.
  • Set a token budget: reserve a fixed share of the context for retrieved memory. This is the core of agent context management: decide what enters each agent's window on purpose.

Pitfalls and how to catch them

1. Stale reads

Agent B acts on data Agent A changed seconds ago. Fix: attach timestamps or version numbers and reject writes based on old versions.

2. Write conflicts

Two agents update the same fact differently. Fix: use optimistic locking (check the version before writing), or designate one owner agent per fact.

def safe_update(state, field, value, expected_version, agent):
   if state["version"] != expected_version:
       raise ConflictError("State changed, re-read before writing")
   state[field] = value
   state["version"] += 1
   state["last_updated_by"] = agent

This function refuses a write if someone else changed the state first, which forces the agent to re-read and retry instead of silently overwriting.

3. Memory poisoning

A wrong or malicious entry gets written once, then trusted by every agent afterward. Fix: record provenance, validate writes from untrusted sources, and let only specific agents write to sensitive fields.

4. Context bloat

Everyone writes, nobody prunes, and quality drops. Fix: summarize old entries, expire low-value memories, and cap retrieval size.

5. Hidden coupling

Agents quietly depend on each other's undocumented memory keys. Fix: treat memory keys like a public API and document who writes and who reads each one.

6. No observability

You cannot tell why an agent made a decision. Fix: log every memory read and write with agent, timestamp, and reason.

Key takeaways

  • Keep working memory private and shared memory explicit. Not everything an agent thinks belongs in the shared layer.
  • Match the pattern to the workload: scratchpads for prototypes, vector memory for fuzzy recall, structured state for hard facts, event logs for production traceability.
  • Design for conflicts up front with versioning and clear ownership.
  • Limits: the right AI agent memory design depends on your scale, latency needs, and risk tolerance. Treat the patterns here as starting points, and test them against your own failure cases. A good next step is to pick one workflow, list every fact your agents share, and assign each fact a single owner and a storage pattern.

Join the discussion

How do you handle shared memory in your multi-agent systems? Do you lean on vector search, a structured store, or something else, and what was your worst memory bug in production? Share it in the comments below, I would love to compare notes.

About the author

  • We write about multi-agent systems, agentic AI, and omnichannel automation, the architecture decisions behind them, where they break in production, and what actually changes for teams running support, sales, and ops through them. We built BotSailor, where we help businesses run WhatsApp, Instagram, Telegram, and Messenger automation from one place so most of what we write comes from things we've actually shipped, broken, and fixed, not just trend-watching. Currently publishing two series here: Multi-Agent Systems, Practically and Agentic AI in Production. If you're building with agents, orchestration, or omnichannel automation, we'd genuinely like to hear what you're running into, drop it in the comments or reply to any post.

No comments yet. Be the first to comment.