skillfed
REPO

Hermes-LCM treats context compression as reversible by keeping every raw message in a DAG

on: stephenschoettler/hermes-lcm

Standard context compression for long-running agents is a one-way door: once the model summarizes older turns, the original content is gone from the active prompt and there is no structured path back. Hermes-LCM takes a different position. It replaces that lossy compaction with a SQLite-backed DAG that keeps raw messages intact and builds a hierarchy of summary nodes over them, so an agent can always drill back to exact source material.

The mechanism is a six-stage loop: ingest each message with full-text search metadata, compact older messages outside a protected fresh tail into leaf summary nodes, condense same-depth nodes into higher-depth summaries, escalate oversized summaries from detailed prose to bullet form to deterministic truncation, assemble the active context from system prompt plus highest-depth summaries plus the fresh tail, and expose retrieval tools so the agent can recover what was compacted. Nothing is deleted in normal operation.

Fifteen agent-facing tools handle the retrieval side. The most interesting are lcm_recall, which fuses full-text search with vector retrieval using reciprocal rank fusion across summary and chunk arms; lcm_compute, which executes date arithmetic, distinct counts, and unit-compatible sums over exact cited evidence without calling an external provider; and lcm_compile_evidence, which validates a semantic proposal against stored refs and returns an explicit sufficiency verdict rather than letting the model treat its own claims as proof. That last one is doing real epistemic work: it refuses to return final prose and refuses to treat model-generated claims as finite coverage.

Three opt-in feature families extend the core loop. Large-output externalization moves oversized tool results to plugin-managed JSON files and replaces them in active replay with recoverable stubs, keeping giant tool outputs from crowding the prompt. Temporal memory adds day, week, and month rollup summaries accessible through natural-time queries. Semantic retrieval adds embedding-backed hybrid search with support for both free-tier cloud providers and fully local models.

The configuration surface is extensive but honest about tradeoffs. The threshold tuning section is particularly useful: it walks through the math of compaction trigger versus context window size, and explicitly notes that a million-token model does not mean you should spend most of those tokens before compaction starts. Cost and latency are real constraints, and the docs treat them as such.

Two design choices stand out as genuinely careful. First, the plugin delegates compaction for ignored or stateless sessions to Hermes' native compressor rather than silently overflowing. Second, sensitive-pattern redaction is forward-only and intentionally lossy for matched values — enabling it does not rewrite historical rows, and the README says so plainly rather than implying retroactive protection.

The dependency footprint is minimal: no required third-party runtime packages, with tiktoken used opportunistically for token counting and regex used for safe pattern matching with timeouts. The test suite runs without a Hermes checkout at all.

A structured alternative to lossy context compression that keeps raw messages recoverable and gives agents tools to cite exact evidence rather than trust summaries.

Sources & links