LOSSLESS CONTEXT MANAGEMENT

Bounded context.
Unbounded memory.

LCM-X replaces one-shot compression in Hermes Agent with a SQLite-backed, DAG-based context engine. The live prompt stays small, every raw message is preserved, and the agent can recover exact detail long after compaction.

Get LCM-Xgit clone https://github.com/electricsheephq/lcm-x
SCROLL TO EXPLORE
UTurn 395 tok

CORS is failing on the token exchange.

ATurn 4380 tok

Fixed via redirect URI config; tokens now persist.

ACT ITHE PROBLEM
TRADITIONAL

A fixed token budget

A conventional agent holds the whole conversation inside one token budget. Every user message and every tool result eats space — and the budget must keep headroom for the model to write a summary once it runs out.

4 turns live
660 / 2,000 tok
0 recoverable
TRADITIONAL

The threshold fires

Around 80% of the budget the system stops and batches as much history as it can into a single summarization call. The conversation blocks while it runs.

10 turns live
1,710 / 2,000 tok
blocking call
TRADITIONAL

One flat summary, and the rest is gone

Ten turns collapse into a paragraph. Space is reclaimed, but nothing points back at what was dropped. The agent will misremember specifics, contradict decisions it already made, and ask again for things it was already told.

1 flat summary
420 / 2,000 tok
8 turns unrecoverable
ACT IILOSSLESS CONTEXT MANAGEMENT
ENTER LCM

There is a better way

LCM-X starts the same way — messages accumulating in a budget — but nothing is ever thrown away. Raw messages are persisted in a local SQLite store before anything is compacted.

5 turns live
5 rows persisted
0 discarded
LCM

The fresh tail is protected

The most recent raw messages are never compacted. Everything older becomes eligible. The tail is four turns here; in real use it is much larger.

fresh tail = 4
4 turns eligible
0 discarded
LCM

Incremental compaction

When eligible messages outside the fresh tail cross the threshold, compaction fires asynchronously — the conversation is never interrupted. Because the source rows still exist, compaction is always safe.

async pass
6 turns → 1 node
conversation uninterrupted
LCM

A summary node with lineage

The chunk becomes a depth-0 node. It replaces those messages in the active prompt, but it keeps references to every source row — so it can be expanded back to the exact original text on demand.

  • sum_01 · Turns 1–6 · ↳ 12 msgs
1,540 → 880 tok
+1 D0 node
12 source rows linked
LCM

The cycle repeats

New turns arrive, the tail advances, another cohort ages out, another pass fires. Depth-0 nodes accumulate — each one a dense slice of the conversation with a full source trail behind it.

  • sum_03 · Turns 9–12
  • sum_04 · Turns 13–16
4 D0 nodes
20 turns covered
0 discarded
LCM

Condensation into depth-1

Once enough nodes pile up at the same depth, LCM condenses them. Four depth-0 summaries are synthesized into one depth-1 node: more abstract, more durable, covering the whole arc.

  • sum_d1_01 · Turns 1–16 · ↳ 4 × D0
4 × D0 → 1 × D1
24 turns covered
lineage preserved
LCM

Depth-aware prompts

Each level runs a different prompt. D0 keeps exact decisions and technical detail. D1 distills the arc — outcomes, what changed, current state. D2 writes a durable narrative that stays useful for weeks.

3 prompt tiers
D0 minutes · D1 hours · D2 days
LCM

Bounded context, unbounded memory

Sixty-four turns in, the active prompt is still small — and not one message has been discarded. The DAG holds minutes at D0, hours at D1, days at D2, weeks above that.

  • sum_d2_01 · Turns 1–64 · ↳ 128 msgs
64 turns spoken
1,040 tok live
128 messages recoverable
ACT IIIGETTING IT BACK
RETRIEVAL

lcm_describe

Before spending a single token on expansion, the agent inspects a node: subtree token count, source token count, and a child manifest. Enough to plan a retrieval strategy.

0 tok expanded
manifest read
20,480 tok subtree seen
RETRIEVAL

lcm_grep

Search every node in the DAG — raw rows and summaries alike, across all depths, literal or semantic. Results carry depth labels, so the agent knows whether a topic still lives in raw text or has been distilled upward.

3 hits
D0 · D1 · RAW
depth-labelled
RETRIEVAL

lcm_expand_query

When a summary isn't enough, the agent issues a scoped delegation grant — a conversation scope plus a token budget — and spawns a sub-agent to walk the DAG on its behalf.

grant = 4,000 tok
sub-agent spawned
main context untouched
RETRIEVAL

Full fidelity, bounded cost

The sub-agent explores a 20k-token subtree and spends under 800. It returns one focused answer. The main context is unchanged — but now holds exact detail from turn three of a sixty-four turn conversation.

781 / 4,000 tok spent
+65 tok to main context
exact turn recovered
THAT'S THE WHOLE IDEA

Drop it into Hermes Agent and your prompts stay bounded while the history stays whole.

Get LCM-X
01THE PLUGIN

LCM-X is that engine, wired into Hermes Agent

Hermes' built-in compressor prunes older tool results and rebuilds the prompt from a summary plus a recent tail. The session rows may still be searchable at the host level, but the model's active context loses both the verbatim turns and any structured path back to them. LCM-X makes recall part of the context engine itself.

SQLite message store

Every raw message persisted with FTS metadata before a single token is compacted. The store is plugin-local and built for drill-down, not just archival.

Summary DAG

Depth-aware nodes over compacted history. Each node keeps source lineage, so any summary can be walked back to the exact rows it came from.

Bounded recovery

Raw messages, child summaries and externalized payloads come back in pages — never as an unbounded dump into the active prompt.

Source-aware retrieval

Filter raw rows and summaries by descendant lineage, with explicit session-boundary rules.

Large-payload controls

Oversized tool, media and raw payloads are externalized behind stable refs, protecting SQLite from inline base64 blobs.

Sensitive-pattern redaction

Optional named redaction of API keys, bearer tokens, passwords and private keys before LCM stores or summarizes anything.

Temporal memory

Opt-in day, week and month rollups with natural-time recall through lcm_recent.

Semantic retrieval

Embedding-backed semantic and hybrid grep modes, with free-tier cloud or fully local providers.

02AGENT TOOLS

Fifteen ways back into the DAG

Three of them carry the story above. The other twelve cover search, expansion, evidence and store health.

  • IN THE STORY
    lcm_grep

    Literal, semantic or hybrid search across raw rows and every summary depth.

  • IN THE STORY
    lcm_describe

    Node manifest: subtree tokens, source tokens, children — before you spend.

  • IN THE STORY
    lcm_expand_query

    Delegation grant plus a budgeted sub-agent that walks the DAG for you.

SEARCHfind it again
lcm_recall
Pull back prior material by topic with depth-labelled results.
lcm_recent
Natural-time recall — yesterday, last week — over temporal rollups.
lcm_retrieve
Targeted fetch of nodes and raw pages by id or lineage.
EXPANDwalk back to the source
lcm_expand
Expand a summary one level toward its exact source messages.
lcm_query_state
Ask structured questions about the current context assembly.
lcm_compute
Run bounded computations over retrieved material.
EVIDENCEcite what you found
lcm_compile_evidence
Assemble a cited set of sources behind an answer.
lcm_evidence_pack
Ship that evidence as a compact, reviewable bundle.
lcm_load_session
Attach a prior session's store for cross-session recall.
MAINTAINkeep the store healthy
lcm_status
Live budget, node counts, compaction and condensation activity.
lcm_inspect
Low-level look at store rows, refs and externalized payloads.
lcm_doctor
Health checks with backup-first repair and rotate paths.
AGENT LOOP · PYTHON
# the agent hits a summary and needs the exact wordingmanifest = await lcm_describe(node="sum_d2_01")#  depth 2 · subtree 20,480 tok · 3 children hits = await lcm_grep("budget cap", mode="hybrid")#  D0  sum_03    “…hard cap of $3,000, flights excluded…”#  RAW turn_07   “…keep the total under 3k, seriously…” answer = await lcm_expand_query(    query="original budget constraint", budget=4000)#  spent 781 / 4,000 tok · main context delta +65 tok
IN YOUR AGENT LOOP

Inspect before you spend

Every retrieval starts with a manifest, so the agent knows the cost of an expansion before it pays for it. Recovery is paged and budgeted — never an unbounded dump back into the live prompt.

20,480
tok subtree inspected
781
tok actually spent
+65
tok added to the live prompt
03QUICK START

Two commands and you're running

  1. STEP 01

    Clone into your plugins directory

    bash
    git clone https://github.com/electricsheephq/lcm-x \
      ~/.hermes/plugins/hermes-lcm

    hermes-lcm is discovered on next agent start.

  2. STEP 02

    Or install from an existing checkout

    bash
    ./scripts/install.sh

    Symlinks the plugin and verifies your Python runtime.

REQUIREMENTS
  • Hermes Agent
  • Python 3.11 – 3.14
  • No required runtime dependencies
  • tiktoken used if present, character estimates otherwise
  • Optional /lcm slash commands
WHAT YOU GET
15 agent tools
grep, expand, describe, walk the DAG
SQLite store
every raw row kept, nothing overwritten
Summary DAG
depth-aware nodes with full lineage
/lcm commands
inspect state without leaving the session