MemoryOS Documentation

repository·main·Indexed 23 days ago

https://github.com/bai-lab/memoryos

A hierarchical memory management system for AI agents providing short-term, mid-term, and long-term memory capabilities. It features a plug-and-play architecture for storage and retrieval, support for various LLMs (OpenAI, Deepseek, Qwen, etc.), and an MCP (Model Context Protocol) server for integration with clients like Claude Desktop, Cline, and Cursor. The system manages a multi-tier lifecycle to improve personalization and coherence through user profiles and knowledge extraction.

Tokens
3.9K
Snippets
11
Records
22
Agent score
78%

What's inside MemoryOS

  1. Overview of MemoryOS

    main

    MemoryOS is a memory operating system designed for personalized AI agents. It enables coherent, personalized, and context-aware interactions by managing memory through a hierarchical storage architecture.

    Core modules include:

    • Storage: Hierarchical layers for different memory durations.
    • Updating: Logic for processing and promoting information between layers.
    • Retrieval: Mechanisms to fetch relevant context.
    • Generation: Using retrieved memory to inform LLM responses.

    Key features include a plug-and-play architecture for storage engines and retrieval algorithms, support for various LLMs (OpenAI, Deepseek, Qwen, etc.), and an MCP (Model Context Protocol) server for easy integration into agent workflows.

  2. MemoryOS System Architecture and Components

    main

    MemoryOS operates using a hierarchical memory management system. The project structure reveals the core functional components:

    • memoryos.py: The main orchestrator class.
    • short_term.py: Manages recent interactions.
    • mid_term.py: Consolidates short-term interactions into mid-term memory.
    • long_term.py: Manages long-term persona memory, including user profiles and knowledge.
    • retriever.py: Handles information retrieval across all memory layers.
    • updater.py: Processes updates and promotes information between layers (e.g., from short-term to mid-term).
    • prompts.py: Contains the LLM prompts used for summarization and analysis.
  3. How MemoryOS works

    main

    MemoryOS manages agent memory through a multi-tier lifecycle:

    1. Initialization: Sets up dedicated storage for users and assistants using provided IDs, API keys, and storage paths.
    2. Short-Term Memory: User inputs and agent responses are stored as QA pairs in short-term memory.
    3. Mid-Term Processing: When short-term memory reaches capacity, the Updater module consolidates interactions into segments and moves them to mid-term memory.
    4. Long-Term Memory (LPM) Updates: Mid-term segments accumulate "heat" (based on frequency and length). Once a threshold is met, the system extracts user profile insights, specific facts, and assistant knowledge to update long-term storage.
    5. Retrieval & Response: For every query, the Retriever fetches context from short-term history, mid-term segments, user profiles, and assistant knowledge to provide the LLM with comprehensive context.
  4. Reproduce evaluation results

    main

    To reproduce the evaluation results, navigate to the eval directory and run the parsing and evaluation scripts. Ensure you have configured the necessary API keys in the code before running.

    cd eval
    # Configure API keys in the code first
    python3 main_loco_parse.py
    python3 evalution_loco.py
  5. Get started with MemoryOS_ChromaDB

    main

    To use the ChromaDB implementation of MemoryOS, install the required dependencies and run the provided test script.

    Note: If you switch embedding models, you must use a different data_storage_path to avoid data corruption or incompatibility.

    cd memoryos-chromadb
    pip install -r requirements.txt
  6. Run MemoryOS using Docker

    main

    You can deploy MemoryOS using Docker for quick setup or production.

    Option 1: Pull Official Image

    docker pull ghcr.io/bai-lab/memoryos:latest
    docker run -it --gpus=all ghcr.io/bai-lab/memoryos /bin/bash

    Option 2: Build from Source

    git clone https://github.com/BAI-LAB/MemoryOS.git
    cd MemoryOS
    docker build -t memoryos .
    docker run -it --gpus=all memoryos /bin/bash
  7. Install MemoryOS via PyPi or GitHub

    main

    Prerequisites

    • Python >= 3.10
    • Recommended environment setup:
      conda create -n MemoryOS python=3.10
      conda activate MemoryOS

    Installation

    Via PyPi

    pip install memoryos-pro -i https://pypi.org/simple

    Via GitHub (Latest)

    git clone https://github.com/BAI-LAB/MemoryOS.git
    cd MemoryOS/memoryos-pypi
    pip install -r requirements.txt
    pip install memoryos-pro -i https://pypi.org/simple
  8. Use the MemoryOS Playground

    main

    The playground provides a web interface to interact with the memory system.

    1. Launch the app:
      cd MemoryOS/memoryos-playground/memdemo/
      python3 app.py
    2. Configure: In the browser, enter your User ID, OpenAI API Key, Model, and API Base URL.
    3. Data Location: Memories are stored in MemoryOS-main/memoryos-playground/memdemo/data.
    python3 app.py
  9. Install MemoryOS from GitHub

    main

    To install the latest version directly from the GitHub repository, clone the repo and install the requirements from the memoryos-pypi directory.

    git clone https://github.com/BAI-LAB/MemoryOS.git
    cd MemoryOS/memoryos-pypi
    pip install -r requirements.txt
  10. Set up MemoryOS-MCP server

    main

    MemoryOS-MCP allows you to inject long-term memory into AI agent clients (like Claude Desktop or Cline) via the Model Context Protocol.

    1. Install Dependencies

    cd memoryos-mcp
    pip install -r requirements.txt

    2. Configure config.json

    Create a config.json file with the following structure:

    {
      "user_id": "用户ID",
      "openai_api_key": "OpenAI API 密钥",
      "openai_base_url": "https://api.openai.com/v1",
      "data_storage_path": "./memoryos_data",
      "assistant_id": "助手ID",
      "llm_model": "gpt-4o-mini",
      "embedding_model_name": "BAAI/bge-m3"
    }

    3. Start the Server

    python server_new.py --config config.json

    4. Client Configuration (e.g., Cline)

    When configuring your client, ensure the command points to the correct Python interpreter in your virtual environment.

    "command": "/path/to/your/venv/bin/python"
  11. Set up MemoryOS as an MCP server

    main

    MemoryOS can be run as a Model Context Protocol (MCP) server.

    1. Install dependencies:
      cd memoryos-mcp
      pip install -r requirements.txt
    2. Configure config.json: Ensure you provide user_id, openai_api_key, openai_base_url, data_storage_path, assistant_id, llm_model, and embedding_model_name.
    3. Start the server:
      python server_new.py --config config.json
    4. Client Integration (e.g., Cline): Copy the mcp.json file to your client and ensure the command path points to the correct Python interpreter of your virtual environment.
    python server_new.py --config config.json