Skip to content

Proposal: Pluggable context engines — enabling LCM as a plugin (like OpenClaw's lossless-claw) #5701

@stephenschoettler

Description

@stephenschoettler

Summary

I built a context engine plugin slot for Hermes Agent and the first plugin that uses it: hermes-lcm — Lossless Context Management as a standalone installable plugin.

The Problem

Hermes has no way for plugins to replace the context compressor. The ContextCompressor is hardwired in run_agent.py. This means:

  1. Anyone wanting LCM (or any custom compaction) must fork and patch core
  2. PR feat(lcm): Lossless Context Management — never lose a message again #4033 does exactly this — 12 modules, 278 tests, all jammed into agent/lcm/
  3. OpenClaw solved this cleanly with a contextEngine plugin slot and lossless-claw as a standalone plugin

The Solution

Two things:

1. Context engine slot (PR #5700)

A ContextEngine ABC in agent/context_engine.py that makes the compressor swappable:

class ContextEngine(ABC):
    def update_from_response(self, usage) -> None: ...
    def should_compress(self, prompt_tokens) -> bool: ...
    def compress(self, messages, current_tokens) -> list: ...
    # + optional: get_tool_schemas(), handle_tool_call(), on_session_start/end/reset, etc.

ContextCompressor becomes the default implementation. Plugins register a replacement via ctx.register_context_engine(engine). No behavior change for existing users.

2. hermes-lcm plugin

LCM implemented as a plugin against that slot:

  • Immutable SQLite message store (every message preserved verbatim)
  • Summary DAG with depth-aware nodes (D0 minutes → D1 hours → D2 days)
  • 3-level escalation (L1 detailed → L2 bullets → L3 deterministic truncate)
  • Agent tools: lcm_grep, lcm_describe, lcm_expand
  • Install: cp -r hermes-lcm ~/.hermes/plugins/hermes-lcm

Based on the LCM paper by Ehrlich & Blackman (Voltropy, Feb 2026).

Why This Approach

PR #4033 (core patch) This proposal (plugin slot)
Core diff 12 modules, 278 tests in agent/lcm/ 2 files changed, 1 new ABC
Maintenance Core team maintains LCM Plugin author maintains LCM
User choice LCM or nothing Any engine, swappable
Install/remove Fork cp / rm a directory
Precedent OpenClaw contextEngine + lossless-claw

Status

Happy to iterate on the ABC design if the team has feedback on the interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions