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.

1from letta_client import Letta
2
3client = Letta(base_url="http://127.0.0.1:8283")
4
5# create a shared memory block
6shared_block = client.blocks.create(label="organization", value="Organization: Letta")
7
8# create a supervisor agent
9supervisor_agent = client.agents.create(
10 model="anthropic/claude-3-5-sonnet-20241022",
11 embedding="openai/text-embedding-ada-002",
12 # blocks created for this agentj
13 memory_blocks=[{"persona": "I am a supervisor"}],
14 # pre-existing shared block that is "attached" to this agent
15 block_ids=[shared_block.id],
16)
17
18# create a worker agent
19worker_agent = client.agents.create(
20 model="anthropic/claude-3-5-sonnet-20241022",
21 embedding="openai/text-embedding-ada-002",
22 # blocks created for this agent
23 memory_blocks=[{"persona": "I am a worker"}],
24 # pre-existing shared block that is "attached" to this agent
25 block_ids=[shared_block.id],
26)

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

Built with