MemoryOS is a specialized memory management system designed for personalized AI agents. It ensures that interactions remain coherent, contextually aware, and tailored to the individual user. The architecture is modeled after the hierarchical memory management found in traditional operating systems. Four primary modules—storage, update, retrieval, and generation—oversee the entire memory lifecycle. Rigorous testing on the LoCoMo benchmark demonstrates its effectiveness: MemoryOS improved F1 scores by an average of 49.11% and BLEU-1 scores by 46.18%.
The objective is to provide AI agents with a robust recall mechanism that mimics an OS, allowing them to retain interaction histories, maintain detailed user profiles, and build evolving knowledge structures.
MemoryOS functions through four interconnected modules:
Storage Module: Responsible for persisting data across the various memory tiers.
Update Module: Refreshes stored information and handles the promotion of data between different levels of the hierarchy.
Retrieval Module: Extracts the most relevant context from each specific memory layer based on the current query.
Generation Module: Synthesizes the retrieved context to produce the final agent response.
memoryos/
├── __init__.py # Package initializer
├── __pycache__/ # Python cache (auto-generated)
├── long_term.py # Manages long-term user profile storage
├── memoryos.py # Core class that coordinates all system components
├── mid_term.py # Manages mid-term memory and STM consolidation
├── prompts.py # Prompt templates for LLM-based memory processing
├── retriever.py # Logic for retrieving info across all memory layers
├── short_term.py # Manages short-term memory for recent interactions
├── updater.py # Handles memory updates and tier promotion logic
└── utils.py # Shared utility functions and helpers
MemoryOS requires Python 3.10 or a newer version installed on your local environment.
conda create -n MemoryOS python=3.10
conda activate MemoryOS
pip install -i https://pypi.org/simple/ MemoryOS-BaiJia
The following script demonstrates how to initialize the system and add basic user information:
import os
from memoryos import Memoryos
# Basic configuration
USER_ID = "demo_user"
ASSISTANT_ID = "demo_assistant"
API_KEY = "YOUR_OPENAI_API_KEY" # Replace with your actual API key
BASE_URL = "" # Optional: set if using a custom OpenAI proxy or endpoint
DATA_STORAGE_PATH = "./simple_demo_data"
LLM_MODEL = "gpt-4o-mini"
def simple_demo():
print("MemoryOS Simple Demo")
# 1. Initialize MemoryOS
print("Initializing MemoryOS...")
try:
memo = Memoryos(
user_id=USER_ID,
openai_api_key=API_KEY,
openai_base_url=BASE_URL,
data_storage_path=DATA_STORAGE_PATH,
llm_model=LLM_MODEL,
assistant_id=ASSISTANT_ID,
short_term_capacity=7,
mid_term_heat_threshold=5,
retrieval_queue_capacity=7,
long_term_knowledge_capacity=100
)
print("MemoryOS initialized.\n")
except Exception as e:
print(f"Error: {e}")
return
# 2. Add memories to the system
print("Adding memories...")
memo.add_memory(
user_input="Hi! I'm Tom, I work as a data scientist in San Francisco.",
agent_response="Hello Tom! Nice to meet you. Data science is such an exciting field. What kind of data do you work with?"
)
# 3. Test memory recall
test_query = "What do you remember about my job?"
print(f"User: {test_query}")
response = memo.get_response(
query=test_query,
)
print(f"Agent: {response}")
if __name__ == "__main__":
simple_demo()
Sunshine Streaming Host Specs: What Hardware You Actually Need
YPrompt Review: Build Better AI Prompts With This Smart Tool
Web Codegen Scorer: Test AI-Generated Web Code Quality Before You Ship
Cogency: Build AI Agents in Python with Transparent ReAct Loops
AI Interactive Fiction Generator Builds Stories You Actually Control
Build AI Agent Interfaces Faster with agents-ui-kit
Scira: The Minimalist AI Search Engine for Grok, Claude, and Beyond
Koishi Chatbot Framework: Build a Cross-Platform Bot in Minutes
ERPNext Open Source ERP: Installation Guide for Accounting and Inventory
Add Area Fill to Line Charts in Excel: Step-by-Step
LiveTerm: A Next.js Terminal-Style Website Template
How to Highlight Top 3 and Bottom 3 Bars in an Excel Chart