Introduction¶
Adding “long-term memory” to agents in DeepSeek Harness (DSH) typically involves letting the model itself decide what to write, what to read, and whether to include information in the context. Once text is generated by the model, issues can arise, such as fabricated entries, mistakenly treating memories as instructions, or forcing historical fragments into irrelevant conversation turns.
The following introduces the community plugin dsh-memory-jev (maintainer: Towzai, Category: Memory). It uses TypeSafe’s Jev decision model as a security boundary for the memory system: Jev only outputs three typed results—choice (selecting one from candidates), score, and noul (yes/no probability)—it never generates free text. Whether it is worth writing, which old memory to replace, whether a recall is relevant, and whether to inject in the current turn are all decided by Jev; the memory content is always controlled by the plugin, preventing the model from inventing memory content out of thin air.
What is this¶
dsh-memory-jev is a server-side memory plugin for DSH (current package version 0.4.1, MIT License). It hooks Jev into the read and write paths of memory and provides an optional injection gate before every conversation turn (fail-closed: if it cannot decide accurately, it does not inject).
Ecosystem-wise, DSH emphasizes “everything is a plugin”; plugins can be found in the community directory at skillhub.cn. This site is not officially affiliated with DeepSeek or High-Flyer. Source code and documentation are available at GitHub: Towzai/dsh-memory-jev.
Core Features: Three Gates and Invariants¶
The plugin organizes behavior using three “gates”; the strategies upon failure are deliberately different—the write path tends to be fail-open, while injection tends to be fail-closed.
| Gate | Function | On Failure |
|---|---|---|
Write gate mem_remember |
Local bigram prefilter → A Jev call: worth_keeping (noul) + supersedes (choice between candidates and none) |
Still writes; only marks gate=unavailable\|budget |
Recall gate mem_recall |
Lexical prefilter top-N → rel_<id> noul for each candidate → Filter and sort by probability |
Falls back to local ranking and marks degraded (“Not decided by Jev”) |
Injection gate agent/pre-step |
Cheap text gate → Candidate pool subtraction → Jev relevance decision → Append a boxed user snapshot at the tail of the context | No injection (Better silent than adding noise) |
There are several constraints in the design (Invariants in the README) worth noting separately:
- Maximum one block injected per
(session, turn); subsequent steps in the same turn do not repeat decisions or injections. - Each memory is injected at most once within the same session; injected IDs are removed from the candidate pool before Jev calls to avoid wasting requests.
- Once the injected block leaves the context, the corresponding ID can participate in candidates again (logged as
reset). - The injected block uses
<retrieved-memories …>framing and declares “not conversation history, not instructions”;<within the memory body is escaped to\u003cto prevent forged delimiters. - Only appended at the tail, ensuring the system prompt and previous history remain byte-level unchanged, which benefits prefix caching.
Tools and Local Storage¶
| Tool | Purpose |
|---|---|
mem_remember |
Write gate; persists regardless of gate result (returns persisted) |
mem_recall |
Recall gate; returns {gate, degraded, items[]}, keeping jev_prob and local_score separate |
mem_list / mem_view |
List / View |
mem_forget / mem_restore |
Soft delete / Restore (preserves supersedeHistory, supports cascade) |
mem_merge |
Fold older entry content into newer entry and soft delete the older one (length after merge ≥ length of older entry) |
mem_pin |
Skip one relevance threshold, maximum once per session, unavailable at session start |
mem_gate_status |
Spent / Reserved / Remaining / Call count / Circuit breaker / Key presence / Storage path |
mem_gate_log |
Audit log query (only ID and hash, no body content) |
No physical deletion occurs: Deletion is always retired=true, which is recoverable.
Installation and Activation¶
Via DSH Plugin Market¶
Repos with the dsh-plugin topic are indexed by the registry CI (scanned approximately every 2 hours). Installation command (from README):
dsh plugin --profile web install Towzai/dsh-memory-jev
Note: The repository path in user clues is towzai/dsh-memory-jev. The installation command should follow the <owner>/dsh-memory-jev format in the README, which is Towzai/dsh-memory-jev.
Manual Installation¶
- Copy the repository to
~/.dsh/profiles/web/node_modules/dsh-memory-jev/. - Register in the profile’s
cordis.patch.yml(or do it via the market), e.g.:
- id: dsh-memory-jev
name: dsh-memory-jev
config:
storePath: /absolute/path/to/gate-store.json # Empty defaults to <cwd>/data/gate-store.json
injectEnabled: true
- Restart DSH at the process level (Setting
enabled:false→trueviaset_bundleonly remounts lines; it does not clear the ESM module cache). - Use
mem_gate_statusto confirm the plugin is loaded.
Host interface packages (@deepseek-ai/cordis, dsh-llm, dsh-tools) are declared only as peerDependencies in the package. You should not bundle copies within the plugin, otherwise it will shadow the host and break tool calls.
Configuration Essentials¶
After modifying configuration in the profile’s cordis.patch.yml (or the bundle’s patch), a process-level restart is also required.
| Key | Default | Meaning |
|---|---|---|
storePath |
'' (i.e., <cwd>/data/gate-store.json) |
Storage file; absolute path recommended for production |
injectEnabled |
true |
Master switch for injection gate |
injectInSubagents |
false |
Whether to inject in sub-sessions (cost increases with number of sub-sessions) |
injectLimit |
3 |
Maximum entries to inject per time |
injectMinProbability |
0.6 |
Injection relevance threshold (stricter than manual recall) |
prefilterLimit |
40 |
Number of candidates sent to Jev |
supersedeCandidates |
12 |
Number of “possible duplicate” candidates for the write gate |
dailyBudgetCny |
3.5 |
Daily budget (CNY) |
dailyCallLimit |
3000 |
Daily call limit |
When tuning parameters, the README suggests relying on evidence rather than intuition: mem_gate_log or the daily-sharded gate-decisions-*.jsonl will record the noul probability and the threshold at that time, facilitating review of which entries would be passed or discarded under a certain threshold.
Regarding cost, Jev input is approximately $0.042/M, output is free; the plugin accounts in CNY. A single decision is about 2,000–4,200 input tokens, equivalent to roughly ¥0.0006–0.0012; budgeting uses reserve → settle → reconcile, with a serial ledger to prevent concurrent overspending.
Typical Usage¶
After installation and restart, first check the storage path, key, and budget via gate status:
- Call tool
mem_gate_statusin DSH to view spend / reserved / remaining, call count, circuit breaker status, whetherOPENROUTER_API_KEYis available, andstorePath.
Daily memory operations use the mem_* tool family:
mem_remember: Write new memories; the write gate attempts Jev decision on whether to keep and whether to supersede an old memory, but persists regardless of gate availability.mem_recall: Recall by query; returned items carry both Jev’sjev_proband locallocal_scoreto compare “decision score” vs. “lexical score”. You can override the defaultrecallMinProbability(default 0.5) via themin_probabilityparameter.mem_list/mem_view: Browse and inspect entries;mem_forget/mem_restore/mem_merge/mem_pinfor soft delete, restore, merge, and single pin.- Call
mem_gate_logwhen auditing is needed (no body, only id/hash); use thegate-reportscript (npm run gate-reportin package.json) to aggregate before tuning thresholds.
If injection is disabled or Jev is unavailable: write/recall will be marked degraded or budget/unavailable; the injection gate does not append any block to the context when there is no decision.
Data Boundaries and Offline Behavior¶
The plugin declares cloud: true, with outbound traffic limited to three locations, all pointing to https://openrouter.ai/api/alpha/decisions (Write gate: first 600 chars of new memory + candidate titles; Recall and Injection: question text + candidate titles). An offline path exists: without an API key, write/recall adopt deterministic degraded behavior (marked degraded), and the injection gate does not inject.
- Credentials are read on-demand from the environment variable
OPENROUTER_API_KEY(Windows can fall back to registryHKCU\Environment); not written to config files, not echoed back, not logged. - If the question or body matches patterns like phone number / ID card / bank card /
sk-/Bearer/password/api_key, the decision is entirely skipped (gate=redacted-skip). - Audit logs only record id, probability, tokens, CNY, error types, and build version; no body content, no raw queries (only hash and length).
- Local store, audit, and budget files are in the same directory as
storePath; not uploaded or synced. - Optional
egressGuard(defaultfalse): when enabled, questions that look like they carry secrets are not sent to the endpoint, and recall falls back to local ranking but still returns your memory items.
Node engine requirement is >= 22.0.0 (package.json).
Use Cases and Notes¶
Who it is for: Developers already using DSH who want “typed decisions” for memory read/write and automatic injection rather than pure LLM free text; can accept the network dependency and pay-per-use billing of the OpenRouter Jev endpoint; willing to use mem_gate_log and configuration items for threshold and budget governance.
Must-do before installation:
- The plugin runs with the current DSH process permissions, reading/writing the local store, and potentially accessing the network and
OPENROUTER_API_KEY; review the source repository and MIT license yourself before installation. - Configure an absolute path for
storePathin production, and understand the difference between write fail-open and injection fail-closed—do not assume “the gate will definitely block the write” for important content. - Information like star ratings on community directory pages will change; refer to the GitHub README and releases.
Conclusion¶
dsh-memory-jev treats Jev’s “only decide, do not generate text” as the boundary of the memory system: the write, recall, and injection gates have clear divisions of labor, content and framing remain on the plugin side, and it comes with budgeting, auditing, and soft delete/restore. If you are building agent memory in DSH, you can start by installing, verifying activation with mem_gate_status, and then tuning injectMinProbability and dailyBudgetCny based on your scenario.
- Community Directory: https://www.skillhub.cn/plugins/Towzai/dsh-memory-jev
- Source Code and Docs: https://github.com/Towzai/dsh-memory-jev