ME

MemGPT

18,000PythonMemory System

LLM operating system with self-editing memory for unlimited context.

PythonMemoryContext ManagementSelf-editingOpen Source

Overview

MemGPT is an LLM operating system that enables AI agents to manage their own memory, giving them effectively unlimited context. It implements a hierarchical memory architecture with core memory, archival memory, and a memory management system that automatically decides what to keep, archive, or delete. This allows agents to remember long conversations, learn from interactions, and maintain persistent knowledge.

Features

  • Self-editing memory with automatic management
  • Hierarchical memory architecture
  • Unlimited context through memory paging
  • Tool use and function calling
  • Support for multiple LLM backends
  • CLI and API interfaces
  • Integration with popular frameworks

Installation

pip install memgpt

Pros

  • +True unlimited context for LLMs
  • +Automatic memory management
  • +Open-source and self-hostable
  • +Strong research backing
  • +Good for long-running agent sessions

Cons

  • Complex architecture to understand
  • Memory paging adds latency
  • Newer project with evolving API
  • Documentation gaps in advanced features

Alternatives

Documentation

MemGPT

Overview

MemGPT is an LLM operating system that enables AI agents to manage their own memory, giving them effectively unlimited context. It implements a hierarchical memory architecture that automatically decides what information to keep in active memory, what to archive, and what to delete.

This allows agents to remember long conversations, learn from interactions over time, and maintain persistent knowledge across sessions—something traditional LLMs cannot do due to context window limitations.

Features

  • Self-Editing Memory: The agent decides what to remember and forget
  • Hierarchical Memory Architecture: Core memory, archival memory, and message buffer
  • Unlimited Context: Memory paging enables effectively infinite context
  • Tool Use and Function Calling: Execute external tools and APIs
  • Multi-Provider Support: OpenAI, Anthropic, local models via Ollama
  • CLI and API Interfaces: Use via command line or integrate programmatically
  • Framework Integration: Works with LangChain, LlamaIndex, and more

Installation

pip install memgpt

Quick Start

# Initialize MemGPT
memgpt run

# Create an agent
memgpt agent create my-agent --model gpt-4o

Core Concepts

Memory Layers

LayerPurposeCapacity
Core MemoryActive, frequently accessed information~4K tokens
Archival MemoryLong-term storage for less frequent infoUnlimited
Message BufferRecent conversation historyConfigurable

Memory Management

MemGPT uses a "paging" mechanism similar to operating systems:

  1. When core memory fills up, the agent decides what to archive
  2. Archived memories can be retrieved when needed
  3. The agent learns which memories are important over time

Quick Start (Python)

import memgpt

# Create a client
client = memgpt.Client()

# Create an agent
agent = client.create_agent(
    name="my-agent",
    model="gpt-4o",
    memory=memgpt.Memory(
        core_memory=memgpt.CoreMemory(
            human="User is a software developer interested in AI."
        )
    )
)

# Send a message
response = client.send_message(
    agent_id=agent.id,
    role="user",
    message="What do you know about me?"
)

print(response.messages)

Advanced Features

Archival Memory

# Store information in archival memory
client.insert_archival_memory(
    agent_id=agent.id,
    memory="User prefers Python for data science tasks."
)

# Search archival memory
results = client.search_archival_memory(
    agent_id=agent.id,
    query="programming language preferences"
)

Tool Use

# Define a custom tool
@memgpt.tool
def get_weather(location: str) -> str:
    """Get the current weather for a location."""
    # Implementation here
    return f"The weather in {location} is sunny, 72°F."

# Agent can call tools automatically
response = client.send_message(
    agent_id=agent.id,
    role="user",
    message="What's the weather like in San Francisco?"
)

Multiple Agents

# Create multiple agents
agent1 = client.create_agent(name="analyst", model="gpt-4o")
agent2 = client.create_agent(name="writer", model="claude-3-5-sonnet")

# Agents can communicate
response = client.send_message(
    agent_id=agent1.id,
    role="user",
    message="Analyze this data and send your findings to the writer agent."
)

Pros

  • ✅ True unlimited context for LLMs
  • ✅ Automatic memory management
  • ✅ Open-source and self-hostable
  • ✅ Strong research backing from UC Berkeley
  • ✅ Good for long-running agent sessions
  • ✅ Supports multiple LLM backends

Cons

  • ❌ Complex architecture to understand
  • ❌ Memory paging adds latency
  • ❌ Newer project with evolving API
  • ❌ Documentation gaps in advanced features

When to Use

  • Building agents that need long-term memory
  • Creating assistants that learn from interactions
  • Applications requiring persistent knowledge
  • Research projects on agent memory systems
  • When context window limits are a bottleneck

Use Cases

Use CaseWhy MemGPT
Long-Term MemoryEffectively unlimited context for agents
Persistent AssistantsRemember users across sessions
Research ProjectsStudy agent memory management
Context-Limited ModelsExtend small-context models

Comparison with Alternatives

FeatureMemGPTMem0AgentMemoryZep
ParadigmSelf-managing memorySelf-improvingPersistent storageEntity extraction
Unlimited Context✅ Yes⚠️ Via storage⚠️ Via storage⚠️ Via storage
Self-Editing✅ Yes✅ Yes❌ No⚠️ Via extraction
Hierarchical✅ Yes⚠️ Partial⚠️ Via context❌ No
Self-Hostable✅ Yes⚠️ Cloud only✅ Yes✅ Yes
Learning CurveHighLowMediumMedium
Best forUnlimited contextPersonalizationCoding agentsStructured memory

Best Practices

  1. Define core memory carefully — Start with essential user information
  2. Monitor archival memory — Review stored memories periodically
  3. Use tools effectively — Define clear tool descriptions for agent use
  4. Test memory management — Verify agent makes good archival decisions
  5. Configure model properly — Use models with sufficient context for paging

Troubleshooting

IssueSolution
Agent forgets contextIncrease core memory capacity or improve paging
Archival search failsUse more specific query terms
Memory paging slowUse faster vector store for archival memory
Tool calls failVerify tool docstrings are clear and specific

Resources