Skip to content

Community Implementation: Hermes ContextEngine plugin for TencentDB offload V2 API #404

Description

@ysun0804

Community ContextEngine Implementation

Following up on #202 (Hermes Context Engine support), we built and open-sourced a feature-complete Python ContextEngine plugin for Hermes Agent that uses TencentDB Gateway's offload V2 API.

Repo

https://github.com/ysun0804/tencentdb-offload

What it does

Aligns with the official OpenClaw offload implementation, providing:

  • post_tool_call hook — async tool_pair ingest after each tool call (L1 data source)
  • pre_llm_call hook — heartbeat filtering + MMD canvas injection + incremental compression
  • L3 4-level compression — fastpath → mild → aggressive → emergency (via Gateway compact API)
  • L2 Mermaid canvas injection — via Gateway query-mmd endpoint
  • Reclaimer — stale session cleanup
  • SessionRegistry + SessionState — multi-session state management with LRU eviction
  • Graceful degradation — tail-truncation fallback when Gateway is unavailable
  • Zero dependencies — pure Python stdlib (urllib, json, threading, logging)

Key implementation details

  1. Hermes ContextEngine ABC doesn't have assemble() or afterToolCall — we use pre_llm_call and post_tool_call hooks as equivalents
  2. context_window is dynamically calculated (tokens / 0.7) to make Gateway's ratio land in the mild compression range
  3. ingest_before_compact preserves full messages before truncation

Tests

25/25 passing (14 core + 11 feature-specific)

Compatibility

  • TencentDB Agent Memory v1.0.0+ (offload V2 API)
  • Hermes Agent v0.17.0+
  • Python 3.10+

Happy to collaborate if the team is interested in an official integration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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