Sleep-time Agents

Based on the new sleep-time compute research paper

Sleep-time agents are experimental and may be unstable. For more information, visit our Discord.

To learn more about sleep-time compute, check out our blog and research paper.

In Letta, you can create special sleep-time agents that share the memory of your primary agents, but run in the background and can modify the memory asynchronously. You can think of sleep-time agents as a special form of multi-agent architecture, where all agents in the system share one or more memory blocks. A single agent can have one or more associated sleep-time agents to process data such as the conversation history or data sources to manage the memory blocks of the primary agent.

To enable sleep-time agents for your agent, set enableSleeptime: true when creating your agent. This will automatically create:

  • A primary agent with tools for conversation_search and archival_memory_search. This is your “main” agent that you configure and interact with.
  • A sleep-time agent with tools to manage the memory blocks of the primary agent.

Background: Memory Blocks

Sleep-time agents specialize in generating learned context. Given some original context (e.g. the conversation history, a set of files) the sleep-time agent will reflect on the original context to iteratively derive a learned context. The learned context will reflect the most important pieces of information or insights from the original context.

In Letta, the learned context is saved in a memory block. A memory block represents a labeled section of the context window with an associated character limit. Memory blocks can be shared between multiple agents. A sleep-time agent will write the learned context to a memory block, which can also be shared with other agents that could benefit from those learnings.

Memory blocks can be access directly through the API to be updated, retrieved, or deleted.

1// get a block by label
2const block = await client.agents.blocks.retrieve(agentId, "persona");
3
4// get a block by ID
5const block = await client.blocks.retrieve(blockId);

When sleep-time is enabled for an agent, a sleep-time agent is created to manage the memory blocks of the primary agent. The sleep-time agent runs in the background and can modify the memory blocks asynchronously. The sleep-time agent generates learned context from the conversation history to update the memory blocks of the primary agent.

Sleep-time agent for conversation

When sleep-time is enabled, a primary agent and a sleep-time agent are created as part of a multi-agent group under the hood. The sleep-time agent is responsible for generating learned context from the conversation history to update the memory blocks of the primary agent. The group ensures that for every N steps taken by the primary agent, the sleep-time agent is invoked with data containing new messages in the primary agent’s message history.

Configuring the frequency of sleep-time updates

The sleep-time agent will be triggered every N-steps (default 5) to update the memory blocks of the primary agent. You can configure the frequency of updates by setting the sleeptime_agent_frequency parameter when creating the agent.

1import { LettaClient, SleeptimeManagerUpdate } from '@letta-ai/letta-client'
2
3const client = new LettaClient({ token: "LETTA_API_KEY" });
4
5// create a sleep-time-enabled agent
6const agent = await client.agents.create({
7 memoryBlocks: [
8 { value: "", label: "human" },
9 { value: "You are a helpful assistant.", label: "persona" }
10 ],
11 model: "anthropic/claude-3-7-sonnet-20250219",
12 embedding: "openai/text-embedding-3-small",
13 enableSleeptime: true
14});
15console.log(`Created agent id ${agent.id}`);
16
17// get the multi-agent group
18const groupId = agent.multiAgentGroup.id;
19const currentFrequency = agent.multiAgentGroup.sleeptimeAgentFrequency;
20console.log(`Group id: ${groupId}, frequency: ${currentFrequency}`);
21
22// update the frequency to every 2 steps
23const group = await client.groups.modify(groupId, {
24 managerConfig: {
25 sleeptimeAgentFrequency: 2
26 } as SleeptimeManagerUpdate
27});

We recommend keeping the frequency relatively high (e.g. 5 or 10) as triggering the sleep-time agent too often can be expensive (due to high token usage) and has diminishing returns.