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 `pip install letta-client`
2from letta_client import Letta
3
4# create a client to connect to Letta
5client = Letta(token="LETTA_API_KEY")
6
7# create a shared memory block
8shared_block = client.blocks.create(
9 label="organization",
10 description="Shared information between all agents within the organization.",
11 value="Nothing here yet, we should update this over time."
12)
13
14# create a supervisor agent
15supervisor_agent = client.agents.create(
16 model="anthropic/claude-3-5-sonnet-20241022",
17 embedding="openai/text-embedding-3-small",
18 # blocks created for this agent
19 memory_blocks=[{"label": "persona", "value": "I am a supervisor"}],
20 # pre-existing shared block that is "attached" to this agent
21 block_ids=[shared_block.id],
22)
23
24# create a worker agent
25worker_agent = client.agents.create(
26 model="anthropic/claude-3-5-sonnet-20241022",
27 embedding="openai/text-embedding-3-small",
28 # blocks created for this agent
29 memory_blocks=[{"label": "persona", "value": "I am a worker"}],
30 # pre-existing shared block that is "attached" to this agent
31 block_ids=[shared_block.id],
32)

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