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.

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.

1// install letta-client with `npm install @letta-ai/letta-client`
2import { LettaClient } from '@letta-ai/letta-client'
3
4// create a client to connect to Letta
5const client = new LettaClient({
6 token: "LETTA_API_KEY"
7});
8
9// create a shared memory block
10const sharedBlock = await client.blocks.create({
11 label: "organization",
12 description: "Shared information between all agents within the organization.",
13 value: "Nothing here yet, we should update this over time."
14});
15
16// create a supervisor agent
17const supervisorAgent = await client.agents.create({
18 model: "anthropic/claude-3-5-sonnet-20241022",
19 embedding: "openai/text-embedding-3-small",
20 // blocks created for this agent
21 memoryBlocks: [{ label: "persona", value: "I am a supervisor" }],
22 // pre-existing shared block that is "attached" to this agent
23 blockIds: [sharedBlock.id]
24});
25
26// create a worker agent
27const workerAgent = await client.agents.create({
28 model: "anthropic/claude-3-5-sonnet-20241022",
29 embedding: "openai/text-embedding-3-small",
30 // blocks created for this agent
31 memoryBlocks: [{ label: "persona", value: "I am a worker" }],
32 // pre-existing shared block that is "attached" to this agent
33 blockIds: [sharedBlock.id]
34});

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).