Sleep-time Agents
Build agents that think while they sleep


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 mulit-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, create the agent with type sleeptime_agent
. When you create an agent of this type, this will automatically create:
- A primary agent (i.e. general-purpose agent) tools for
send_message
,conversation_search
, andarchival_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. It is possible that additional, ephemeral sleep-time agents will be created when you add data into data sources 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 is should 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.
When sleep-time is enabled for an agent, there will be one or more sleep-time agents create to manage the memory blocks of the primary agent. These sleep-time agents will run in the background and can modify the memory blocks of the primary agent asynchronously. One sleep-time agent (created when the primary agent is created) will generate learned context from the conversation history to update the memory blocks of the primary agent. Additional ephemeral sleep-time agents will be created when you add data into data sources of the primary agent to process the data sources in the background. These ephemeral agents will create and write to a block specific to the data source, and be deleted once they are finished processing the data sources.
Sleep-time agent for conversation


When a sleep-time-enabled agent is created, an additional sleep-time agent is created to generate learned context from the conversation history to update the memory blocks of the primary agent. Under the hood, the primary agent and sleep-time agent are part of a multi-agent group. The group ensures that for every N
steps by the primary agent, the sleep-time agent is invoked with data containing new messges 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 sleep_time_agent_frequency
parameter when creating the agent.
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.
Sleep-time agents for data sources


Sleep-time-enabled agents will spawn additional ephemeral sleep-time agents when you add data into data sources of the primary agent to process the data sources in the background. These ephemeral agents will create and write to a block specific to the data source, and be deleted once they are finished processing the data sources.
When a file is uploaded to a data source, it is parsed into passages (chunks of text) which are embedded and saved into the main agent’s archival memory. If sleeptime is enabled, the sleep-time agent will also process each passage’s text to update the memory block corresponding to the data source. The sleep-time agent will contrain an instructions
block that contains the data source description, to help guide the learned context generation.
Give your data sources an informative name
and description
when creating them to help the sleep-time agent generate better learned context, and to help the primary agent understand what the associated memory block is for.
Below is an example of using the SDK to attach a data source to a sleep-time-enabled agent:
This code will create and attach a memory block with the label employee_handbook
to the agent. An ephemeral sleep-time agent will be created to process the data source and write to the memory block, and be deleted once all the passages in the data source have been processed.
Processing each Passage
from a data source will invoke many LLM requests by the sleep-time agent, so you should only process relatively small files (a few MB) of data.