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 memgptPros
- +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
| Layer | Purpose | Capacity |
|---|---|---|
| Core Memory | Active, frequently accessed information | ~4K tokens |
| Archival Memory | Long-term storage for less frequent info | Unlimited |
| Message Buffer | Recent conversation history | Configurable |
Memory Management
MemGPT uses a "paging" mechanism similar to operating systems:
- When core memory fills up, the agent decides what to archive
- Archived memories can be retrieved when needed
- 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 Case | Why MemGPT |
|---|---|
| Long-Term Memory | Effectively unlimited context for agents |
| Persistent Assistants | Remember users across sessions |
| Research Projects | Study agent memory management |
| Context-Limited Models | Extend small-context models |
Comparison with Alternatives
| Feature | MemGPT | Mem0 | AgentMemory | Zep |
|---|---|---|---|---|
| Paradigm | Self-managing memory | Self-improving | Persistent storage | Entity 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 Curve | High | Low | Medium | Medium |
| Best for | Unlimited context | Personalization | Coding agents | Structured memory |
Best Practices
- Define core memory carefully — Start with essential user information
- Monitor archival memory — Review stored memories periodically
- Use tools effectively — Define clear tool descriptions for agent use
- Test memory management — Verify agent makes good archival decisions
- Configure model properly — Use models with sufficient context for paging
Troubleshooting
| Issue | Solution |
|---|---|
| Agent forgets context | Increase core memory capacity or improve paging |
| Archival search fails | Use more specific query terms |
| Memory paging slow | Use faster vector store for archival memory |
| Tool calls fail | Verify tool docstrings are clear and specific |
