# MemEngine

> A unified, modular library for building advanced memory in LLM-based agents

- Category: Agents & Automation / Agent Memory
- Language: Python
- Repository: https://github.com/nuster1128/MemEngine
- Canonical page: https://ai-tldr.dev/tools/memengine/

## In short

MemEngine is a Python library for developing the memory layer of LLM-based agents. It sits in the Agent Memory category of the Agents & Automation tools and is open-source, written in Python. To get started: install from source (recommended).

## Overview

MemEngine is a Python library for developing the memory layer of LLM-based agents. It brings together memory models from recent research papers and implements them under one unified, modular framework, so you can use a single interface instead of reimplementing each design from scratch.

It is aimed at researchers and engineers who want to add memory to agents and compare different approaches. Memory modules organize their logic into hierarchical levels where higher-level modules reuse lower-level ones, and a configuration module lets you adjust hyper-parameters and prompts without rewriting code.

Within the agent-memory space, MemEngine focuses on being pluggable. Its memory modules expose common operations like store and recall, can be dropped into existing agent frameworks, and support local use as a Python package or remote use as a service behind a port.

## What it does

- Unified, modular framework with three hierarchical levels where higher-level modules reuse lower-level ones
- Many published agent-memory models implemented under one interface, so you can switch and test them with different configs
- Configuration module for adjusting hyper-parameters and prompts at different levels
- Pluggable memory modules with simple store and recall operations that work across agent frameworks
- Default, configurable, and automatic memory usage modes
- Local deployment as a Python library or remote deployment as a service via uvicorn and FastAPI

## Getting started

Install MemEngine into a Python 3.9+ environment, then create a memory module and use its store and recall operations inside your agent.

1. Install from source (recommended)

   The maintainers recommend installing from source to get the latest version. Create a Python 3.9 environment, clone the repo, and install in editable mode.

```bash
conda create -n memengine_env python=3.9
git clone https://github.com/nuster1128/MemEngine.git
cd MemEngine
pip install -e .
```

2. Or install from pip

   If you prefer a packaged release, install from PyPI. Note this may not be the latest version.

```bash
conda create -n memengine_env python=3.9
pip install memengine
```

3. Create a memory module and use it

   Import a memory model such as FUMemory with its config, then call recall to fetch context and store to save new observations. This mirrors the dialogue-agent example from the README.

```python
from memengine.config.Config import MemoryConfig
from memengine.memory.FUMemory import FUMemory

memory = FUMemory(MemoryConfig(DialogueAgentMemoryConfig))

# fetch relevant context for the current input
context = memory.recall(observation)

# save a new turn into memory
memory.store('%s: %s' % (role, response))
```

## When to use it

- Adding persistent memory to a conversational agent so it can recall earlier turns
- Comparing several published memory models on the same task by switching configs
- Prototyping a new memory model by extending the library's operations and functions
- Running memory as a shared service behind a port for multiple agents to use
