dsh-memory-lite: A Hierarchical Memory Library with On-Demand Retrieval

Overview

The core design of DeepSeek Harness (DSH) is lightweight, plugin-based. When handling Agent memory, most existing approaches choose “automatic injection every turn,” causing memory content to be repeatedly sent in every conversation turn and leading to unnecessary Token waste. dsh-memory-lite addresses this pain point by treating memory as hierarchical Markdown and returning only matched snippets during queries.

This plugin uses a “zero resident” and “zero dependency” design, keeping the memory read volume for a single query to about 700 characters, saving around 92% compared with full reading. It is both a DSH plugin and a standalone CLI.

Core Design: Three Invariants

  1. Zero resident: Memory does not enter the system prompt. The only always-on item in the plugin version is a tool schema (about 50-100 tokens), and memory content is generated only when queried.
  2. Zero dependency: It uses only Node.js built-in modules and introduces no database, server, or background process.
  3. Traceable: Every memory entry carries a source mark, and the verify command can check it back to the original conversation.

Installation and Enablement

Install the plugin to a specified Profile with the following command:

dsh plugin --profile web add github:MiHjy12138/dsh-memory-lite

After installation completes, the backend needs to be restarted (DSH assembly rule: newly added bundles are not hot-loaded).

Usage

This project provides two usage modes, both sharing the src/lib.mjs implementation.

Mode A: As a DSH Plugin

After installation, mem_query appears in the Agent’s tool list. The Agent can directly invoke this tool to retrieve memory. The memory store is located in the workspace’s memory/ directory by default.

Mode B: As a CLI Tool

It does not depend on the DSH environment and can be run directly with Node. It is suitable for manual retrieval or non-DSH scenarios.

Workflow and Commands

Before using the plugin, you need to complete data collection, distillation, and construction.

  1. Collect material
    Scan conversation logs and generate material files under the .staging directory.
   node src/mem.mjs collect
  1. Build the memory store
    Distill the material into SUMMARY.md, INDEX.md, and topics/*.md.
   node src/build.mjs
  1. Query memory
    Retrieve by keywords and return only matched snippets.
   node src/mem.mjs query "powershell bom" --n 5
  1. Verify provenance
    Verify whether the extracted memories accurately correspond to the original material.
   node src/verify.mjs examples/extracts-example.json --staging examples/staging

Features

  • Hierarchical Markdown: Includes a top-level SUMMARY.md (one-sentence distillation), an INDEX.md index, and topic-partitioned topics/*.md.
  • Token optimization: Measured memory queries reduced from 11,819 characters to 738 characters, saving about 92%.
  • Zero dependency: Pure Node.js implementation, cross-platform.
  • Low summary tax: The resident summary accounts for only 0.9% of the full text.

Applicable Scenarios

Suitable for scenarios sensitive to Token cost and requiring precise control of retrieved content by a human or an Agent. Not suitable for scenarios requiring semantic recall, knowledge graphs, or cross-machine synchronization.

Summary

dsh-memory-lite solves the Token waste problem in Agent memory retrieval through hierarchical storage and on-demand retrieval. It does not use automatic injection; instead, it manages memory through the explicit mem_query tool or CLI commands, ensuring that only necessary information is passed in each interaction.

GitHub Repository
DSH Plugin Directory

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye