Customize your agent memory

Letta agents have programmable in-context memory. This means a section of the context window is reserved for editable memory: context that can be edited by memory editing tools. Like standard system prompts, the memory also can be used to define the behavior of the agent and store personalization data. The key distinction is that this data can be modified over time.

Memory

The in-context (i.e. core) memory of agents is represented by a Memory object. This object contains:

  • A set of Block objects representing a segment of memory, with an associated character limit and label
  • A set of memory editing tools

Agent Core Memory

The core memory of an agent is a set of blocks, with an associated character limit, label, and value. The value is stored in the agent’s context window, so that information is always provided to the LLM.

Blocks

Blocks are the basic unit of core memory. A set of blocks makes up the core memory. Each block has:

  • A limit, corresponding to the character limit of the block (i.e. how many characters in the context window can be used up by this block)
  • A value, corresponding to the data represented in the context window for this block
  • A label, corresponding to the type of data represented in the block (e.g. human, persona)

Creating agents with memory

1from letta_client import Letta
2
3client = Letta(base_url="http://localhost:8283")
4
5agent = client.agents.create(
6 name="memory_agent",
7 memory_blocks=[
8 {"label": "persona", "value": "I am a memory agent"},
9 {"label": "human", "value": "Name: Bob", "limit": 10000},
10 ],
11 model="anthropic/claude-3-5-sonnet-20241022",
12 embedding="openai/text-embedding-ada-002",
13 tags=["worker"],
14)

Shared Memory

You can create blocks independently of agents. This allows for multiple agents to be attached to a block. This allows of synchronized context windows accross agents, enabling shared memory.

1# create a persisted block, which can be attached to agents
2block = client.blocks.create(
3 label="organization",
4 value="Organization: Letta",
5 limit=4000,
6)
7
8# create an agent with both a shared block and its own blocks
9shared_block_agent1 = client.agents.create(
10 name="shared_block_agent1",
11 memory_blocks=[
12 {"label": "persona", "value": "I am agent 1"},
13 ],
14 block_ids=[block.id],
15 model="anthropic/claude-3-5-sonnet-20241022",
16 embedding="openai/text-embedding-ada-002",
17)
18# create another agent sharing the block
19shared_block_agent2 = client.agents.create(
20 name="shared_block_agent2",
21 memory_blocks=[
22 {"label": "persona", "value": "I am agent 2"},
23 ],
24 block_ids=[block.id],
25 model="anthropic/claude-3-5-sonnet-20241022",
26 embedding="openai/text-embedding-ada-002",
27)
Built with