0Pricing
AI Engineering Academy · Lesson

Shared Memory and Inter-Agent Communication

Implement a shared memory layer using a key-value store that agents read from and write to, enabling asynchronous collaboration without tight coupling between agents.

The Problem of Agent Isolation

In a multi-agent system, each agent runs in its own context and has no awareness of what other agents are doing or have done. If a researcher agent discovers a key fact, how does the writer agent know about it? How does a monitoring agent know when the coder agent encounters an error? Without a shared communication mechanism, agents are isolated silos that cannot collaborate effectively.

Shared Memory: The Blackboard Model

The classic solution for multi-agent communication is the blackboard model: a shared data store (the blackboard) that any agent can read from or write to. Agents post their findings, read others' contributions, and coordinate implicitly through the shared state. This model decouples agents from each other — they do not need to know about each other's existence, only about the structure of the shared memory.

# Simple in-memory blackboard using a dictionary
from threading import Lock

class Blackboard:
    def __init__(self):
        self._data = {}
        self._lock = Lock()  # thread-safe for parallel agents

    def write(self, key: str, value, agent_id: str):
        with self._lock:
            self._data[key] = {'value': value, 'written_by': agent_id}
            print(f'[{agent_id}] wrote: {key}')

    def read(self, key: str):
        with self._lock:
            return self._data.get(key, {}).get('value')

    def keys(self):
        with self._lock:
            return list(self._data.keys())

blackboard = Blackboard()

All lessons in this course

  1. Why Single Agents Hit a Wall
  2. Orchestrator-Subagent Pattern
  3. Building Multi-Agent Pipelines with LangGraph
  4. Shared Memory and Inter-Agent Communication
← Back to AI Engineering Academy