Shared Memory Blocks
Enable multi-agent collaboration through shared memory
Overview
Memory blocks can be shared between multiple agents, enabling powerful multi-agent collaboration patterns. When a block is shared, all attached agents can read and write to it, creating a common workspace for coordinating information and tasks.
This tutorial demonstrates how to:
- Create memory blocks that multiple agents can access
- Build collaborative workflows where agents contribute different information
- Use read-only blocks to provide shared context without allowing modifications
- Understand how memory tools handle concurrent updates
By the end of this guide, you’ll understand how to build simple multi-agent systems where agents work together by sharing memory.
This tutorial uses Letta Cloud. Generate an API key at app.letta.com/api-keys and set it as LETTA_API_KEY
in your environment. Self-hosted servers only need an API key if authentication is enabled.
The web_search
tool used in this tutorial requires an EXA_API_KEY
environment variable when self-hosting. You can learn more about self-hosting here.
What You’ll Learn
- Creating standalone memory blocks for sharing
- Attaching the same block to multiple agents
- Building collaborative workflows with shared memory
- Using read-only blocks for policies and system information
- Understanding how memory tools handle concurrent updates
Prerequisites
You will need to install letta-client
to interface with a Letta server:
Steps
Step 1: Initialize Client
Step 2: Create a Shared Memory Block
Create a standalone memory block that will be shared between multiple agents. This block will serve as a collaborative workspace where both agents can contribute information.
We’re going to give the block the label “organization” to indicate that it contains information about some organization. The starting value of this block is “Organization: Letta” to give the agents a starting point to work from.
Step 3: Create Agents with Shared Block
Create two agents that will both have access to the same memory block. You can attach blocks during creation using block_ids
or later using the attach
method.
We’ll provide each agent with the web_search
tool to search the web for information. This tool is built-in to Letta. If you are self-hosting, you will need to set an EXA_API_KEY
environment variable for either the server or the agent to use this tool.
Step 4: Have Agents Collaborate via Shared Memory
Now let’s have both agents research different topics and contribute their findings to the shared memory block.
- Agent 1: Searches for information about the connection between memory blocks and Letta.
- Agent 2: Searches for information about the origin of Letta.
We’re going to ask each agent to search for different information and insert what they learn into the shared memory block, prepended with the agent’s name (either Agent1:
or Agent2:
).
Step 5: Inspect the Shared Memory
Let’s retrieve the shared memory block to see both agents’ contributions:
The output should be something like this:
Organization: Letta
Agent1: Memory blocks are integral to the Letta framework for managing context in large language models (LLMs). They serve as structured units that enhance an agent’s ability to maintain long-term memory and coherence across interactions. Specifically, Letta utilizes memory blocks to organize context into discrete categories, such as “human” memory (user preferences and facts) and “persona” memory (the agent’s self-concept and traits). This structured approach allows agents to edit and persist important information, improving performance, personalization, and controllability. By effectively managing the context window through these memory blocks, Letta enhances the overall functionality and adaptability of its LLM agents.
Agent2: Letta originated as MemGPT, a research project focused on building stateful AI agents with long-term memory capabilities. It evolved into a platform for building and deploying production-ready agents.
Note that each agent has placed their information into the block, prepended with their name. This is a simple way to identify who contributed what to the block. You don’t have to prepend agent identifiers to the block, we only did this for demonstration purposes.
Understanding concurrent updates: Memory tools handle concurrent updates differently:
memory_insert
is additive and the most robust for multi-agent systems. Multiple agents can insert content simultaneously without conflicts, as each insert simply appends to the block.memory_replace
validates that the exact old content exists before replacing it. If another agent modifies the content being replaced, the tool call fails with a validation error, preventing accidental overwrites.memory_rethink
performs a complete rewrite of the entire block and follows “most recent write wins.” This is a destructive operation - use cautiously in multi-agent systems as it can overwrite other agents’ contributions.
Step 6: Using Read-Only Blocks
Read-only blocks are useful for sharing policies, system information, or terms of service that agents should reference but not modify.
Agents can see read-only blocks in their context but cannot modify them using memory tools. This is useful for organizational policies, system configuration, or any information that should be reference-only.
Complete Example
Here’s the full code in one place that you can run:
Key Concepts
Multiple agents can access the same memory block, enabling collaboration and information sharing
Blocks can be attached during agent creation with block_ids or later using the attach method
Memory tools handle concurrent updates differently - insert is additive, replace validates, rethink overwrites
Prevent agent modifications while still providing shared context like policies or system information
Use Cases
Multi-Agent Research
Have multiple agents research different topics and contribute findings to a shared knowledge base.
Organizational Policies
Create read-only blocks with company policies, terms of service, or system guidelines that all agents reference.
Task Coordination
Use shared blocks as a coordination layer where agents update task status and communicate progress.
Collaborative Problem Solving
Enable agents with different specializations to work together by sharing context and intermediate results.