Sahil-SS9

hermes-memlock

Re-assert standing instructions after context compaction to prevent instruction decay in long-running Hermes agent conversations.

9 starsPythonMIT

Repository last updated Jun 17, 2026

Overview

MemLock is a Hermes Agent plugin that prevents instruction decay by re-asserting standing instructions after context compaction events. It monitors conversations for compaction markers and audits whether pinned instructions (anchors) remain in the active region of the context window. When drift is detected, MemLock rehydrates the lost instructions by appending a reminder block to the current user turn, ensuring the model continues to follow specific output formats or behavioral rules even during extended dialogues.

The plugin works by hooking into the pre_llm_call event, scanning the conversation history for the compaction marker [CONTEXT COMPACTION — REFERENCE ONLY]. When a new compaction is detected, MemLock splits the context into summary and active regions, then audits each pinned anchor against the active region using keyword probes or semantic embedding similarity. Drifted anchors are rehydrated with a reminder block, while intact anchors are left untouched to minimize token overhead and preserve prompt cache stability.

MemLock is designed for developers and power users of Hermes Agent who need reliable adherence to instructions across long sessions. It is particularly useful for maintaining output formats, tool preferences, or writing styles that would otherwise be lost after context compaction. The plugin offers configurable detection modes, injection strategies, and cross-session persistence for global anchors.

Highlights

  • Detects context compaction and audits active memory for instruction drift
  • Rehydrates lost instructions via keyword probes or semantic embedding similarity
  • Provides a guard_pin tool for managing persistent behavioral instructions
  • Configurable injection strategies: on-drift (default) or always
  • Cross-session persistence for global anchors using a pluggable backend
  • Integrity scoring and alerting for drift monitoring

Features

Compaction Detection and Audit

Monitors conversation history for compaction markers and audits pinned anchors against the active region to detect drift.

Drift Rehydration

Automatically rehydrates drifted anchors by appending a reminder block to the current user turn, restoring instructions to active context.

Semantic Detection Mode

Optionally uses sentence-transformers for embedding-based similarity detection, with per-window max similarity for accurate comparison.

Slash Command and Tool

Provides the <code>/guard</code> command to view integrity score and anchor list, and the <code>guard_pin</code> tool for pinning/unpinning instructions with priority and scope.

Cross-Session Persistence

Supports global anchors that persist across sessions via a pluggable storage backend, defaulting to a zero-dependency filesystem store.

Configurable Injection Strategy

Choose between <code>on-drift</code> (audit-gated) or <code>always</code> (every turn) injection to balance token cost and determinism.

Requirements

  • Hermes Agent installed and configured
  • Python 3.8+

How it's built

MemLock is implemented in Python and integrates with Hermes Agent via the plugin system. The repository layout includes core modules: detection.py for compaction detection and anchor auditing, persistence.py for cross-session storage, and store.py for anchor management. Configuration is specified in config.yaml and plugin.yaml. The plugin registers a pre_llm_call hook and a tool handler for guard_pin.

Architecturally, MemLock splits the conversation into summary and active regions using the SUMMARY_PREFIX marker. Anchors are stored in memory with metadata (text, priority, probes, scope). The audit step uses either keyword probes (exact substring matching) or semantic similarity via sentence-transformers. In semantic mode, the active region is split into windows (default 1000 characters) and embedded in batch; an anchor is considered alive if its maximum cosine similarity across windows meets the sim_threshold. The plugin supports optional dispatch-layer forwarding for correct session binding in concurrent environments, documented in docs/optional-dispatch-patch.md.

The plugin is licensed under MIT and requires no external dependencies for keyword mode. Semantic mode requires the optional sentence-transformers package. The default embedding model is all-MiniLM-L6-v2, downloaded lazily on first use.

Source

This summary was written for Neura Market from the project's own repository. Install commands, identifiers and licence details are reproduced unchanged. The Sahil-SS9/hermes-memlock repository is the authoritative source and the place to file issues or contribute.

Category: Memory & Knowledge · Licensed under MIT

Related Hermes plugins