Skip to content
  • Auto
  • Light
  • Dark
DiscordForumGitHubSign up
Experimental
View as Markdown
Copy Markdown

Open in Claude
Open in ChatGPT

Sleep-time Agents

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.

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.

// get a block by label
const block = await client.agents.blocks.retrieve(agentId, "persona");
// get a block by ID
const 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.

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

Section titled “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.

import { LettaClient, SleeptimeManagerUpdate } from "@letta-ai/letta-client";
const client = new LettaClient({ token: "LETTA_API_KEY" });
// create a sleep-time-enabled agent
const agent = await client.agents.create({
memoryBlocks: [
{ value: "", label: "human" },
{ value: "You are a helpful assistant.", label: "persona" },
],
model: "anthropic/claude-3-7-sonnet-20250219",
embedding: "openai/text-embedding-3-small",
enableSleeptime: true,
});
console.log(`Created agent id ${agent.id}`);
// get the multi-agent group
const groupId = agent.multiAgentGroup.id;
const currentFrequency = agent.multiAgentGroup.sleeptimeAgentFrequency;
console.log(`Group id: ${groupId}, frequency: ${currentFrequency}`);
// update the frequency to every 2 steps
const group = await client.groups.modify(groupId, {
managerConfig: {
sleeptimeAgentFrequency: 2,
} as SleeptimeManagerUpdate,
});

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.