← Back to Plugins
Tools

Memclaw

sopaco By sopaco 👁 9 views ▲ 0 votes

The openclaw's memory context engine and plugin implementation of cortex memory

Homepage GitHub

Install

npm install @memclaw/memclaw`

Configuration Example

{
  "plugins": {
    "entries": {
      "memclaw": {
        "enabled": true,
        "config": {
          "tenantId": "tenant_claw",
          "autoStartServices": true,
          "llmApiKey": "your-llm-api-key",
          "llmModel": "gpt-5-mini",
          "embeddingApiKey": "your-embedding-api-key",
          "embeddingModel": "text-embedding-3-small"
        }
      }
    },
    "slots": {
      // Optional: if you want to use Context Engine instead
      // "contextEngine": "memclaw-context-engine"
    }
  },
  "agents": {
    "defaults": {
      "memorySearch": { "enabled": false }  // Disable OpenClaw built-in memory
    }
  }
}

README

<p align="center">
    <img src="./assets/intro_banner_glance.webp">
</p>
<h1 align="center">MemClaw</h1>

<p align="center">
    <a href="./README.md">English</a>
    |
    <a href="./README_zh.md">ไธญๆ–‡</a>
</p>

<p align="center">
    <a href="https://github.com/openclaw/openclaw"><img alt="OpenClaw Compatible" src="https://img.shields.io/badge/OpenClaw-compatible-brightgreen"/></a>
    <a href="https://raw.githubusercontent.com/sopaco/cortex-mem/refs/heads/main/assets/benchmark/cortex_mem_vs_openclaw_3.png?raw=true"><img alt="Benchmark" src="https://img.shields.io/badge/Benchmark-Perfect-green?logo=speedtest&labelColor=%231150af&color=%2300b89f"></a>
    <a href="https://github.com/sopaco/cortex-mem/tree/main/litho.docs/en"><img alt="Litho Docs" src="https://img.shields.io/badge/Litho-Docs-green?logo=Gitbook&color=%23008a60"/></a>
    <a href="https://github.com/sopaco/cortex-mem/tree/main/litho.docs/zh"><img alt="Litho Docs" src="https://img.shields.io/badge/Litho-ไธญๆ–‡-green?logo=Gitbook&color=%23008a60"/></a>
</p>

> **MemClaw** โ€” A [Cortex Memory](https://github.com/sopaco/cortex-mem) enhancement suite for OpenClaw, providing production-grade L0/L1/L2 layered semantic memory with native Context Engine integration.

---

## TL;DR

MemClaw seamlessly integrates [Cortex Memory](https://github.com/sopaco/cortex-mem)'s three-tier memory architecture into [OpenClaw](https://docs.openclaw.ai/zh-CN), enabling AI Agents to **automatically remember the past, proactively recall relevant memories, and browse the complete memory space on demand** โ€” all while achieving **up to 95% token savings** compared to OpenClaw's built-in memory solution.

| LoCoMo **#1** in memory recall capability | Slash token use by **90%** |
| :--- | :--- |
| ![Layered Context Loading](./assets/intro_overview.webp) | ![architecture_style_modern](./assets/intro_benchmark.webp) |

---

## Table of Contents

- [Why MemClaw](#why-memclaw)
- [Project Structure](#project-structure)
- [Core Features](#core-features)
- [Architecture Overview](#architecture-overview)
- [Three-Tier Memory Architecture](#three-tier-memory-architecture)
- [Quick Start](#quick-start)
  - [Install Memory Plugin](#install-memory-plugin)
  - [Install Context Engine](#install-context-engine)
- [Configuration Guide](#configuration-guide)
- [Available Tools](#available-tools)
- [Memory Plugin vs Context Engine โ€” Which Should I Choose](#memory-plugin-vs-context-engine--which-should-i-choose)
- [Relationship with Other Projects](#relationship-with-other-projects)
- [Performance Benchmarks](#performance-benchmarks)
- [Troubleshooting](#troubleshooting)
- [FAQ](#faq)
- [License](#license)

---

## Why MemClaw

OpenClaw is a powerful AI Agent gateway, but its built-in memory solution has the following limitations:

| Issue | OpenClaw Built-in Memory | MemClaw Solution |
|-------|--------------------------|------------------|
| Token Consumption | Loads complete history every time, ~15,982 tokens/query | Layered loading, ~2,900 tokens/query |
| Memory Accuracy | 35.65% (LoCoMo10) | **68.42%** |
| Multi-hop Reasoning | Weak | **84.29%** (Cat 4) |
| Memory Organization | Flat list | L0/L1/L2 structured hierarchy |
| Context Management | Built-in fixed strategy | Pluggable Context Engine |

MemClaw solves these problems โ€” transforming stateless Agents into intelligent assistants that can **remember user preferences, learn across sessions, and provide personalized interactions**.

---

## Project Structure

MemClaw consists of two independently installable OpenClaw plugins. Users can choose one or install both:

```
memclaw/
โ”œโ”€โ”€ plugin/              # @memclaw/memclaw โ€” Memory Plugin (passive memory storage)
โ”‚   โ”œโ”€โ”€ dist/            #   Build artifacts
โ”‚   โ”œโ”€โ”€ skills/          #   Agent skill files (tool usage guides, best practices)
โ”‚   โ”œโ”€โ”€ src/             #   Source code
โ”‚   โ”œโ”€โ”€ openclaw.plugin.json
โ”‚   โ””โ”€โ”€ README.md        #   Plugin detailed documentation
โ”‚
โ”œโ”€โ”€ context-engine/      # @memclaw/context-engine โ€” Context Engine (active context management)
โ”‚   โ”œโ”€โ”€ dist/            #   Build artifacts
โ”‚   โ”œโ”€โ”€ index.ts         #   Plugin entry point
โ”‚   โ”œโ”€โ”€ context-engine.ts #  Context Engine lifecycle implementation
โ”‚   โ”œโ”€โ”€ client.ts        #   Cortex Memory client
โ”‚   โ”œโ”€โ”€ tools.ts         #   Tool definitions
โ”‚   โ”œโ”€โ”€ config.ts        #   Configuration management
โ”‚   โ”œโ”€โ”€ binaries.ts      #   Binary service management
โ”‚   โ””โ”€โ”€ TECH_DESIGN.md   #   Technical design document
โ”‚
โ”œโ”€โ”€ bin-darwin-arm64/    # macOS Apple Silicon pre-compiled binary package
โ”‚   โ””โ”€โ”€ bin/
โ”‚       โ”œโ”€โ”€ qdrant              # Qdrant vector database
โ”‚       โ””โ”€โ”€ cortex-mem-service  # Cortex Memory REST API service
โ”‚
โ”œโ”€โ”€ bin-linux-x64/       # Linux x64 pre-compiled binary package (same structure)
โ”œโ”€โ”€ bin-win-x64/         # Windows x64 pre-compiled binary package (same structure)
โ”‚
โ””โ”€โ”€ LICENSE
```

### What Does Each Directory Do?

| Directory | NPM Package Name | Type | Purpose |
|-----------|------------------|------|---------|
| `plugin/` | `@memclaw/memclaw` | Memory Plugin (`kind: "memory"`) | Provides memory tools, requires Agent to actively call them |
| `context-engine/` | `@memclaw/context-engine` | Context Engine (`kind: "context-engine"`) | Automatically manages context, lifecycle hook driven |
| `bin-*/` | `@memclaw/bin-*` | Pre-compiled binary distribution | Qdrant + cortex-mem-service ready to use out of the box |

---

## Core Features

### Provided by Both Plugins

- **Three-Tier Memory Architecture** โ€” L0 abstract (~100 tokens) / L1 overview (~2000 tokens) / L2 full content, progressive disclosure
- **Semantic Vector Search** โ€” Vector similarity retrieval based on Qdrant, supports multi-layer weighted scoring
- **Automatic Service Management** โ€” Automatically starts Qdrant and cortex-mem-service when plugin launches, no manual ops required
- **One-Click Migration** โ€” Seamlessly migrate from OpenClaw native memory to MemClaw
- **Cross-Platform** โ€” Full coverage for Windows x64, macOS Apple Silicon, Linux x64
- **Zero External Dependency Installation** โ€” Qdrant and cortex-mem-service are pre-compiled and packaged, works with `npm install`

### Memory Plugin (`plugin/`) Exclusive

- **Manual Tool-Driven** โ€” Agent operates memory by calling tools like `cortex_search`, `cortex_add_memory`, `cortex_commit_session`, etc.
- **Fine-Grained Layer Control** โ€” Each search can specify which layers (L0/L1/L2) to return
- **Memory Filesystem Browsing** โ€” `cortex_ls` to browse `cortex://` URI space

### Context Engine (`context-engine/`) Exclusive

- **Fully Automatic Context Management** โ€” No need for Agent to call tools, automatically recalls relevant memories before each model run
- **Automatic Message Capture** โ€” Automatically writes each conversation turn to memory, triggers commit when threshold is reached
- **Smart Compression Takeover** โ€” `ownsCompaction: true`, fully controls context compression strategy
- **Archive Expansion** โ€” `cortex_archive_expand` tool to backtrack original conversations from compressed summaries
- **Bypass Mode** โ€” Configure `bypassSessionPatterns` to disable engine for specific sessions

---

## Architecture Overview

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  OpenClaw Gateway                                            โ”‚
โ”‚                                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  Memory Plugin   โ”‚    โ”‚   Context Engine             โ”‚   โ”‚
โ”‚  โ”‚  (@memclaw/      โ”‚    โ”‚   (@memclaw/                 โ”‚   โ”‚
โ”‚  โ”‚   memclaw)       โ”‚    โ”‚    context-engine)           โ”‚   โ”‚
โ”‚  โ”‚                  โ”‚    โ”‚                              โ”‚   โ”‚
โ”‚  โ”‚  โ€ข cortex_search โ”‚    โ”‚   โ€ข ingest()  โ† message recv โ”‚   โ”‚
โ”‚  โ”‚  โ€ข cortex_recall โ”‚    โ”‚   โ€ข assemble() โ† ctx assembleโ”‚   โ”‚
โ”‚  โ”‚  โ€ข cortex_add_*  โ”‚    โ”‚   โ€ข afterTurn() โ† write+commit   โ”‚
โ”‚  โ”‚  โ€ข cortex_commit โ”‚    โ”‚   โ€ข compact() โ† compress+extract  โ”‚
โ”‚  โ”‚  โ€ข cortex_ls     โ”‚    โ”‚                              โ”‚   โ”‚
โ”‚  โ”‚  โ€ข cortex_migrateโ”‚   โ”‚   + full toolset             โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚          โ”‚                          โ”‚                      โ”‚
โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ”‚
โ”‚                     โ–ผ                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  cortex-mem-service (HTTP REST API, port 8085)     โ”‚    โ”‚
โ”‚  โ”‚                                                     โ”‚    โ”‚
โ”‚  โ”‚  POST /api/v2/sessions           create session    โ”‚    โ”‚
โ”‚  โ”‚  POST /.../sessions/{id}/messages write message    โ”‚    โ”‚
โ”‚  โ”‚  POST /.../sessions/{id}/commit   commit+extract   โ”‚    โ”‚
โ”‚  โ”‚  GET  /.../sessions/{id}/context  get context      โ”‚    โ”‚
โ”‚  โ”‚  POST /api/v2/search              semantic search  โ”‚    โ”‚
โ”‚  โ”‚  GET  /api/v2/filesystem/*        virtual filesystemโ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                         โ”‚                                  โ”‚
โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                   โ”‚
โ”‚          โ–ผ                             โ–ผ                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚  โ”‚ Local FS      โ”‚          โ”‚  Qdrant Vector DB  โ”‚        โ”‚
โ”‚  โ”‚               โ”‚          โ”‚  (port 6333/6334)   โ”‚        โ”‚
โ”‚  โ”‚  session/     โ”‚          โ”‚                     โ”‚        โ”‚
โ”‚  โ”‚  user/        โ”‚          โ”‚  Vector index +     โ”‚        โ”‚
โ”‚  โ”‚  agent/       โ”‚          โ”‚  semantic retrieval โ”‚        โ”‚
โ”‚  โ”‚  resources/   โ”‚          โ”‚                     โ”‚        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚                                                            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## Three-Tier Memory Architecture

MemClaw's core innovation is the L0/L1/L2 three-tier memory system, mimicking the progressive process of human memory from "vague impression" to "clear recollection":

| Layer | Filen

... (truncated)
tools

Comments

Sign in to leave a comment

Loading comments...