Sleep-Time Compute: A New Memory Architecture for LLM Agents

    This article explains sleep-time compute, an offline memory architecture for LLM agents that uses idle periods to replay interaction logs, detect errors, synthesize structured notes, and consolidate a persistent text-based memory store. It covers the definition and boundaries of agent memory, core system components, differences from summary compression, deployment considerations, application scenarios, benefits, and open challenges.

    As large language models are increasingly used in complex tasks and multi-turn interactions, enabling models to accumulate experience across sessions and avoid forgetting has become a core challenge in agent engineering. Traditional approaches usually follow two paths: fine-tuning model weights, which is expensive and can damage existing capabilities, or inserting more context into a single conversation, which is limited by window length and cannot support long-term accumulation. Recently, a new memory architecture inspired by human memory consolidation—Sleep-Time Compute—has begun to attract developer attention. Rather than simply extending context length, this architecture redefines the nature of “memory”: during idle periods between interactions, the model reviews past logs offline, corrects reasoning errors, writes structured notes, and persists these results as plain text for later sessions to read. This process is often described as “dreaming,” and its core goal closely matches the function of memory replay and information integration in human sleep.

    1. Defining Agent Memory and Its Boundaries

    Before discussing the architecture, its memory scope must be strictly defined. Agent memory here refers specifically to experiential knowledge that the model acquires from task execution and user interaction, can retain across sessions, and can be read later as plain-text context. It explicitly excludes three categories:

    • Modification of model weights: parameters are not changed through gradient updates, avoiding catastrophic forgetting and costly training.
    • In-context learning within a single conversation: temporary information read immediately does not belong to long-term memory.
    • Context replacement by compressing old conversations into summaries: traditional summary compression can alleviate length limits, but it is essentially lossy compression that discards information, whereas sleep-time compute aims for more refined experience extraction.

    This boundary is important because it means the carrier of memory is “text”—a human-readable, model-parseable, externally editable intermediate representation that ensures transparency and auditability.

    2. Sleep-Time Compute: From Concept to Implementation

    Sleep-Time Compute was initially proposed by a research team working with a university. Its core idea is to use idle time between two interactions—such as when a user leaves or a task is waiting—to perform additional computation. Unlike forward propagation during inference, this computation does not produce an immediate response; it is dedicated to “digesting” existing data. In a concrete implementation, the system marks the complete log of the current session—including user instructions, model replies, tool-call results, and intermediate reasoning chains—as pending, then triggers the following pipeline:

    1. Replay: The model rereads the log, not merely word by word, but by reconstructing the event sequence in chronological or causal order and identifying decision points.
    2. Anomaly Detection: By comparing against the existing memory store, it finds logical contradictions, factual errors, or unfinished goals. For example, if the model incorrectly calculates a date in one turn, that error is flagged during “sleep.”
    3. Note Synthesis: Correct conclusions, key preferences, and unresolved issues are extracted into structured text notes using a unified template, such as “User preference: use a concise style in replies” or “Task status: phase three incomplete; waiting for data.”
    4. Consolidation: New notes are deduplicated, merged, and reconciled with the existing memory store to form an updated plain-text knowledge base stored in an external vector database or file system.

    The entire “dreaming” process is asynchronous and does not block user requests. When a new session begins, the system injects snippets from the memory store that are relevant to the current task into the prompt, effectively giving the model a “long-term knowledge card.”

    3. Core Architecture Components: From Log Ingestion to Memory Extraction

    A production-grade sleep-time compute system usually contains five modules, each with a distinct role:

    • Interaction log collector: Captures all input and output streams with timestamps and metadata such as session ID and tool results. It must ensure log completeness and tamper resistance.
    • Sleep scheduler: Decides when to trigger offline processing. Common strategies include idle timeout (for example, five minutes without a request), session end, or periodic nightly batch processing. The scheduler must balance resource usage and update timeliness.
    • Reflection engine: This is the intellectual core of “dreaming.” It is usually handled by another LLM or the same LLM with a different prompt template. The reflection prompt guides the model to act as an “auditor,” for example:
      1. You are reviewing a conversation. Please identify:
      2. 1. Factual errors
      3. 2. Unfinished commitments
      4. 3. Preferences the user has expressed repeatedly
      5. 4. Decisions that can be abstracted into general rules
      6. Output format: error list | note list
    • Memory storage: Stores notes as plain-text files or in a vector database. Each note contains content, source session ID, timestamp, and confidence. Retrieval uses embedding-based similarity matching.
    • Injection controller: In the initial prompt of a new conversation, dynamically selects the 5–10 most relevant notes based on the user question and memory index, then concatenates them into a “memory summary block.” The controller must limit injection length to avoid overusing context.

    4. How It Differs Fundamentally from Traditional Approaches

    Many existing systems use “conversation summaries” to mitigate context explosion, such as generating a summary after each turn and injecting it at the start of the next turn. But this differs fundamentally from sleep-time compute:

    • Granularity: A summary compresses an entire conversation and loses fine-grained logic. Sleep-time compute preserves two layers of information—“error corrections” and “notes”—recording both final conclusions and key turning points in the reasoning process.
    • Initiative: Summaries passively “summarize,” whereas sleep-time compute actively “finds errors,” can detect and correct biases in the model’s own reasoning, and then uses the corrections to update memory.
    • Persistence: Summaries are usually used only for the next turn and cannot accumulate over time. Sleep-time notes form a continuously growing knowledge base and support cross-session references to historical decision rationales.

    For example, in a multi-turn customer service task, a user once said, “I don’t like table-based replies.” A traditional summary would record only “User preference: dislikes tables.” Sleep-time compute can also record “In bill inquiry scenarios, the user wants amount changes described in natural language,” and further derive the rule “This user is sensitive to how data is presented,” so later financial advice automatically adjusts the output style.

    5. Engineering Practice: Deploying Sleep-Time Compute

    For developers, implementing this architecture does not require specialized hardware. Instead, it adds a layer of scheduling and memory management logic on top of existing LLM APIs. The following is a reference architecture (pseudocode, not tied to a specific product interface):

    1. # Pseudocode: executing a sleep task
    2. def sleep_cycle(session_log):
    3. memory_notes = load_memory()
    4. prompt = f"""
    5. You are a reflection engine. Below is an interaction log:
    6. {session_log}
    7. Please analyze it and output:
    8. 1. A list of errors (if any)
    9. 2. New notes (as a JSON array)
    10. 3. IDs of old memory entries that should be deleted or are contradicted
    11. """
    12. response = llm_call(prompt)
    13. parsed = parse_json(response)
    14. # Apply corrections: write error fixes to the error log and merge new notes into memory
    15. for note in parsed["new_notes"]:
    16. add_note(note)
    17. for old_id in parsed["contradictions"]:
    18. remove_note(old_id)
    19. save_memory(memory_notes)

    Key design considerations:

    • Idempotency: Sleep tasks may be executed repeatedly, so a session hash should be recorded to ensure the same log is processed only once.
    • Conflict resolution: When a new note contradicts an old note, the most recent timestamp can be preferred, or the conflict can be reviewed manually.
    • Cost control: Sleep computation consumes tokens, so a budget must be set. It can be enabled only for important sessions, such as those involving tool calls or very long conversations.
    • Observability: Record memory changes before and after each “dream” to make model behavior easier to debug.

    6. Application Scenarios and Benefits

    This architecture is particularly suitable for the following scenarios:

    • Personal assistants: Remember user preferences, schedules, and unfinished items across days without relying on fine-tuning.
    • Coding agents: Continuously accumulate API usage patterns and common error fixes within a project, reducing repeated exploration in later coding.
    • Enterprise knowledge base Q&A: Extract standard handling procedures from historical tickets and automatically reference them when new issues appear.

    The main benefits include: continual learning capability—model behavior can improve day by day without retraining; low-latency memory retrieval—injecting snippets on demand is more precise than compressing the full history; and explainability—all memory exists as text and can be audited and manually edited.

    7. Challenges and Future Directions

    Despite its promise, the architecture still faces several challenges:

    • Memory drift: Notes accumulated over time may contradict each other or become outdated, requiring periodic “deep cleanup”—analogous to slow-wave sleep in the human brain—to globally reconstruct memory.
    • Resource contention: Sleep tasks compete with online inference for GPUs, requiring priority scheduling or use of off-peak periods.
    • Security: If memory is poisoned, such as through malicious instruction injection, it can cause long-term errors. Memory-write validation mechanisms are needed.

    In the future, an ideal direction is to give the “dreaming” process itself metacognition—the model would not only record facts but also record “when a certain memory should be trusted,” and dynamically adjust memory weights based on conversational feedback. In addition, a shared memory store across multiple agents might enable collective intelligence, allowing different sessions to learn from one another, though privacy isolation would need to be addressed.

    Conclusion

    Sleep-Time Compute offers a pragmatic path toward long-term memory for large language models. It mimics the brain’s offline consolidation mechanism, turning transient experience into structured knowledge. For developers, this is not only a technical approach but also a shift in thinking: instead of trying to insert all history into every interaction, teach the model to reflect when it is alone. When agents can truly “correct errors while dreaming,” we will be one key piece closer to another milestone on the path toward general artificial intelligence.