상위: 06_00_MOC

MemGPT / Letta — OS형 4계층 롱텀 메모리 · Sleep-time Compute

한 줄 요약

MemGPT(Packer et al., 2023)는 운영체제의 가상 메모리(Virtual Memory) 개념을 LLM에 끌어와, 컨텍스트 창(RAM)과 외부 저장소(Disk) 사이를 페이징하면서 무제한 컨텍스트라는 환상을 만들어 낸다. Letta는 이 구조를 4계층으로 넓히고, Sleep-time Compute를 통해 비동기 메모리 정제를 보탰다.

“Virtual context management — a technique drawing inspiration from hierarchical memory systems in traditional operating systems that provide the appearance of large memory resources through data movement between fast and slow memory.” — Packer et al., MemGPT, 2023


1. MemGPT 핵심 개념 (arXiv:2310.08560)

저자 7인: Charles Packer, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica, Joseph E. Gonzalez 제출 2023-10-12 / 개정 2024-02-12 / 라이선스 CC BY 4.0

1-1. 문제 인식

“Large language models (LLMs) have revolutionized AI, but are constrained by limited context windows, hindering their utility in tasks like extended conversations and document analysis.” — Packer et al., 2023

출발점은 컨텍스트 창의 물리적 한계다. 이 한계 탓에 긴 대화나 문서 분석이 막힌다는 문제의식에서 논문은 시작한다.

1-2. OS 비유 — Virtual Memory → Virtual Context

OS 개념MemGPT 대응
물리 RAMLLM 컨텍스트 창 (제한됨)
가상 메모리Virtual Context Management
페이지 파일 (Disk)외부 저장소 (Recall/Archival)
페이지 인/아웃메모리 관리 함수 호출
큰 메모리의 환상무제한 컨텍스트의 환상

1-3. 3계층 메모리 구조 (원본 MemGPT)

flowchart TB
    subgraph InContext["Main Context (RAM — 활성 컨텍스트 창)"]
        SYS["시스템 지침"]
        CORE["Core Memory<br/>(사용자·에이전트 정보 블록)"]
        HIST["최근 대화 이력"]
    end

    subgraph External["외부 저장소"]
        RECALL["Recall Storage (Disk)<br/>전체 이벤트 이력<br/>(메시지·tool call·시스템 이벤트)<br/>검색 가능 DB"]
        ARCHIVAL["Archival Storage (Cold Storage)<br/>문서·장기 지식<br/>시맨틱 검색 기반<br/>무제한 크기"]
    end

    InContext -->|"memory_append()<br/>memory_replace()"| CORE
    InContext -->|"recall_search()"| RECALL
    InContext -->|"archival_insert()<br/>archival_search()"| ARCHIVAL
    RECALL -->|"페이지 인 (in-context로)"| InContext
    ARCHIVAL -->|"페이지 인 (in-context로)"| InContext

메커니즘은 단순하다. LLM이 메모리 관리 함수(function call)를 직접 호출해 계층 사이로 데이터를 옮긴다. 즉 에이전트가 자기 메모리를 스스로 관리한다.

인터럽트(Interrupt) 메커니즘도 핵심이다. 사용자 메시지나 타이머 이벤트가 들어올 때마다 제어권이 에이전트로 넘어가며, 에이전트는 응답을 내놓기 전에 여러 내부 메모리 작업을 거칠 수 있다.


2. Letta의 4계층 메모리 확장

Letta는 MemGPT의 3계층을 4계층으로 넓혔다. 가장 큰 변화는 Message Buffer가 Core Memory에서 떨어져 나와 독립 계층이 된 점이다.

flowchart TB
    subgraph InContext["Main Context (In-Context)"]
        MB["① Message Buffer<br/>최근 대화 메시지<br/>(즉각적 대화 흐름)"]
        CM["② Core Memory Blocks<br/>label · description · value · char_limit<br/>편집 가능 구조화 블록<br/>(사용자 정보·에이전트 정보·목표)"]
    end

    subgraph External["외부 저장소 (Out-of-Context)"]
        RM["③ Recall Memory<br/>전체 대화 이력 DB<br/>검색 가능<br/>(에피소드 기억)"]
        AM["④ Archival Memory<br/>벡터 인덱스<br/>처리·인덱싱된 장기 지식<br/>(의미 기억·문서·무제한)"]
    end

    AGENT["LLM Agent"] -->|"memory_edit()"| CM
    AGENT -->|"recall_search()"| RM
    AGENT -->|"archival_search()<br/>archival_insert()"| AM
    RM -->|"검색 결과 → 컨텍스트로"| InContext
    AM -->|"검색 결과 → 컨텍스트로"| InContext

    SLEEP["Sleep-time Agent<br/>(비동기 실행)"] -->|"메모리 정제·갱신"| CM
    SLEEP -->|"압축·재구조화"| RM

4계층 상세

계층위치구조역할
① Message BufferIn-context순차 메시지 목록최근 대화 즉각적 컨텍스트
② Core Memory BlocksIn-context, 편집 가능label · description · value · char_limit구조화된 지속 정보 (사용자·에이전트 페르소나·목표)
③ Recall Memory외부, 검색 가능DB (전체 이벤트 이력)과거 대화·tool call 검색
④ Archival Memory외부, 벡터 인덱스벡터 DB장기 지식·문서 시맨틱 검색

Core Memory Blocks 정의:

“Core Memory Blocks: Structured, editable storage within the context window containing a label, description, value, and character limit.” — Letta, 2024

메모리 관리의 기본 원칙:

“Designing an agent’s memory is essentially context engineering: determining which tokens enter the context window and how they’re organized.” — Letta, 2024

메모리 관리 전략

  • Message Buffer 축소: 메시지를 약 70% 덜어낼 때 재귀 요약으로 연속성을 잇는다.
  • Core Memory 갱신: 에이전트가 memory_edit()를 호출해 직접 편집한다.
  • Recall 검색: 필요할 때 과거 이벤트를 DB에서 끌어온다.
  • Archival 검색: 시맨틱 유사도로 장기 지식을 찾는다.

3. Select 전략과의 연계 — 능동적 검색

Letta의 검색은 전통 RAG와 다르다.

“Unlike standard RAG which passively retrieves before generation, Letta is proactive — the LLM decides if, when, and what to retrieve using tools.” — Letta, 2024

방식주도권시점정밀도
전통 RAG시스템 자동생성 전 고정중간
Letta 능동 검색LLM이 직접 결정필요할 때높음 (추가 비용)

4. Sleep-time Compute — 비동기 메모리 정제 (Letta, 2025)

4-1. 개념

“AI systems that don’t just think reactively when prompted, but proactively deepen their understanding during what we call ‘sleep time’.” — Letta, 2025

“Reasoning during sleep time transforms ‘raw context’ into ‘learned context’, which can then be used later during test time.” — Letta, 2025

에이전트가 한가한 시간(idle time)에, 별도의 sleep-time 에이전트가 비동기로 메모리를 다듬는다.

flowchart LR
    subgraph Active["활성 시간 (User Online)"]
        PA["Primary Agent<br/>사용자 응답<br/>tool call 실행<br/>외부 메모리 접근"]
    end

    subgraph Sleep["유휴 시간 (User Offline)"]
        SA["Sleep-time Agent<br/>비동기 실행<br/>비차단(non-blocking)"]
        SA -->|"메모리 정제·재구성"| CM["Core Memory 갱신"]
        SA -->|"압축·재구조화"| RM["Recall Memory 최적화"]
    end

    PA <-->|"공유 메모리"| CM
    PA <-->|"공유 메모리"| RM

4-2. test-time compute와의 대비

패러다임시점블로킹 여부예시
test-time compute (o1류)사용자 대기 중 추론블로킹 (응답 지연)Chain-of-Thought
sleep-time compute (Letta)에이전트 유휴 중비블로킹메모리 정제

4-3. 이중 에이전트 설계

  • 주 에이전트(Primary): 사용자 응답, tool call 실행, 외부 메모리 접근을 맡는다.
  • sleep-time 에이전트: 주 에이전트의 Core Memory와 Recall Memory를 비동기로 편집·정제한다.

4-4. 성능 결과

  • AIME·GSM8K 벤치마크에서 Pareto 향상을 보였다.
  • 계산 부하를 유휴 시간으로 옮긴 덕분에 품질 저하 없이 응답 속도가 빨라졌다.

“Sleep-time agents on the other hand can continuously improve their learned context to generate clean, concise, and detailed memories.” — Letta, 2025


5. 최신 메모리 벤치마크 현황 (Mem0, 2026)

벤치마크점수비고
LoCoMo92.5점1,540개 대화 질문
LongMemEval94.3점6가지 회상 카테고리
BEAM (1M 토큰)64.1점
BEAM (10M 토큰)48.6점대규모에서 성능 저하

눈여겨볼 수치는 BEAM 10M 토큰 구간이다. 점수가 64.1에서 48.6으로 떨어진다. 대규모 메모리 시스템에서도 05 부패와 비슷한 현상이 되풀이된다는 신호로 읽힌다.

남은 과제는 다음과 같다.

  • 대규모 시간적 추상화(temporal abstraction at scale)
  • 크로스세션 신원 해소(cross-session identity resolution)
  • 고관련도 사실의 staleness 처리
  • 도메인 특화 평가 프레임워크의 부재

6. OS 비유 완성 — 전체 그림

OS 구성요소LLM/에이전트 대응
CPULLM 추론 엔진
RAM (빠른 메모리)컨텍스트 창 (Message Buffer + Core Memory)
가상 메모리 관리자Memory 관리 함수 (memory_edit, recall_search 등)
페이지 파일 (느린 메모리)Recall Memory (DB)
콜드 스토리지Archival Memory (벡터 인덱스)
백그라운드 프로세스Sleep-time Agent
인터럽트 핸들러MemGPT Interrupt Mechanism

참고문헌

관련 노트