Skip to content
  • Auto
  • Light
  • Dark
DiscordForumGitHubSign up
Building Agents
Memory
View as Markdown
Copy Markdown

Open in Claude
Open in ChatGPT

Multi-Agent Shared Memory

Agents can share state via shared memory blocks. This allows agents to have a “shared memory”. You can shared blocks between agents by attaching the same block ID to multiple agents.

graph TD
    subgraph Supervisor
        S[Memory Block
I am a supervisor] SS[Shared Memory Block
Organization: Letta] end subgraph Worker W1[Memory Block
I am a worker] W1S[Shared Memory Block
Organization: Letta] end SS -..- W1S

In the example code below, we create a shared memory block and attach it to a supervisor agent and a worker agent. Because the memory block is shared, when one agent writes to it, the other agent can read the updates immediately.

// install letta-client with `npm install @letta-ai/letta-client`
import { LettaClient } from "@letta-ai/letta-client";
// create a client to connect to Letta
const client = new LettaClient({
token: "LETTA_API_KEY",
});
// create a shared memory block
const sharedBlock = await client.blocks.create({
label: "organization",
description: "Shared information between all agents within the organization.",
value: "Nothing here yet, we should update this over time.",
});
// create a supervisor agent
const supervisorAgent = await client.agents.create({
model: "anthropic/claude-3-5-sonnet-20241022",
embedding: "openai/text-embedding-3-small",
// blocks created for this agent
memoryBlocks: [{ label: "persona", value: "I am a supervisor" }],
// pre-existing shared block that is "attached" to this agent
blockIds: [sharedBlock.id],
});
// create a worker agent
const workerAgent = await client.agents.create({
model: "anthropic/claude-3-5-sonnet-20241022",
embedding: "openai/text-embedding-3-small",
// blocks created for this agent
memoryBlocks: [{ label: "persona", value: "I am a worker" }],
// pre-existing shared block that is "attached" to this agent
blockIds: [sharedBlock.id],
});

Memory blocks can also be accessed by other agents, even if not shared. For example, worker agents can write the output of their task to a memory block, which is then read by a supervisor agent. To access the memory blocks of other agents, you can simply use the SDK clients or API to access specific agent’s memory blocks (using the core memory routes).