RepoDaily · 2026-07-10 · Infrastructure / Runtime

TencentDB Agent Memory: Local 4-Tier Agent Memory That Cuts Tokens 61% Without External APIs

#10 Infrastructure / Runtime TypeScript +625 TencentCloud/TencentDB-Agent-Memory Open repository

An OpenClaw plugin that turns fragmented agent conversations into structured L0–L3 memory layers, running entirely on local SQLite vector search with no cloud API calls.

Repo typeInfrastructure / Runtime
Best forTeams running OpenClaw or Hermes agents who need persistent cross-session memory without sending conversation data to third-party APIs
Risk levelMedium — early version (0.3.6), depends on OpenClaw >= 2026.3.13 and Node >= 22.16
Time to evaluate2–4 hours to install, link as a local plugin, and run a short benchmark session

Primary question: Does the L0→L1→L2→L3 progressive pipeline produce useful persona and scene memory on your agent workload without external API calls?

91/100

RepoDaily adoption score

RepoDaily rates this as 91/100 (strong) for adoption: evidence, installation path, production risk, differentiation, license clarity, and AI/agent fit are scored from the article sources and adoption notes.

Directional score from RepoDaily sources and adoption notes, not a benchmark.Risk: Medium
100Evidence quality

5 source(s) across 4 source category/categories, plus a RepoDaily-specific evidence module when available.

100Installability

6 workflow step(s), 6 next-action step(s), and 4 command/install signal(s) were detected.

65Maintenance confidence

Trending momentum is +625 stars, with maintenance/release/issue signals counted when present.

93Production readiness

Risk is marked medium, with 5 security note(s) and 4 explicit skip condition(s).

100Differentiation

3 opportunity lens item(s), 4 alternative(s), and 3 type-specific section(s) support differentiation.

82License clarity

License source or license wording is present.

84Agent / AI fit

6 AI/agent-related signal(s) were detected in the article text and metadata.

Project overview

TencentDB Agent Memory is an MIT-licensed TypeScript plugin published as @tencentdb-agent-memory/memory-tencentdb at version 0.3.6. It gives AI agents a persistent memory system built on a four-layer progressive pipeline: L0 captures raw conversation, L1 extracts structured records, L2 aggregates scenes, and L3 constructs user personas. The entire pipeline runs locally using SQLite with sqlite-vec 0.1.7-alpha.2 for vector search and an optional local LLM via node-llama-cpp, with zero external API dependencies by default.

The plugin integrates primarily with OpenClaw (>= 2026.3.13) through a plugin manifest at openclaw.plugin.json and a hooks system under src/hooks/. A secondary adapter lives in hermes-plugin/ for the Hermes agent framework. Development requires no build step because Node.js 22.16+ supports native TypeScript type stripping — OpenClaw loads .ts source files directly at runtime.

According to the README, when integrated with OpenClaw the plugin cut token usage by 61.38% on the WideSearch benchmark (221.31M → 85.64M tokens), improved pass rate by 51.52% relative (33% → 50%), and raised PersonaMem accuracy from 48% to 76%. On SWE-bench, token usage dropped 33.09% (3474.1M → 2375.4M) with pass rate rising from 58.4% to 64.2%. These benchmarks ran over continuous long-horizon sessions of 50 consecutive tasks each.

Problem it solves

  • Flat vector stores shred conversations into disconnected fragments, making recall a blind search with no macro-level guidance — the README explicitly rejects this pattern
  • Agents waste tokens re-explaining SOPs, project context, tool conventions, and output formats that should persist across sessions
  • Brute-force history accumulation inflates context windows; irreversible lossy summarization discards information that later proves necessary
  • Sending conversation data to external embedding APIs creates privacy and data-sovereignty concerns for enterprise deployments
  • Long-horizon agents running 50+ consecutive tasks accumulate context pressure that degrades both recall quality and token efficiency

How it works

  1. L0 Conversation layer (src/conversation/): captures raw dialogue into JSONL shards, with daily sharding boundaries now configurable via the timezone setting
  2. L1 Record layer (src/record/): extracts structured information from L0 data, including deduplication and extraction prompts that adapt to the user's input language automatically
  3. L2 Scene layer (src/scene/): aggregates records into scene summaries with snapshot-and-restore protection — if LLM extraction fails, BackupManager.restoreLatestDirectory recovers from the latest backup instead of leaving scene_blocks/ half-written
  4. L3 Persona layer (src/persona/): constructs user profiles from accumulated scenes, writing persona.md files with structured sections whose field names stay in English as a stable contract while free-text content follows the user's language
  5. Storage layer (src/store/): persists to SQLite or TCVDB with timestamps always stored as UTC instants; the migrate-sqlite-to-tcvdb CLI handles database migration between backends
  6. Symbolic short-term memory: condenses heavy tool logs into compact Mermaid symbols to reduce token consumption within active tasks, separate from the long-term layered pipeline

Product demo and interface preview

Retrievable and Recoverable Drill-Down Chain
Retrievable and Recoverable Drill-Down Chain — Official README visual asset that helps readers understand the project interface, architecture, workflow, or output. README.md image
TencentDB Agent Memory L0 to L3 semantic pyramid
TencentDB Agent Memory L0 to L3 semantic pyramid — Official README visual asset that helps readers understand the project interface, architecture, workflow, or output. README.md image

Architecture Read: L0→L1→L2→L3 Pipeline and Storage

The source tree maps directly to the four-tier pipeline. src/conversation/ handles L0 raw capture, src/record/ does L1 extraction, src/scene/ performs L2 aggregation, and src/persona/ builds L3 profiles. The storage layer at src/store/ abstracts SQLite and TCVDB behind a common interface, with sqlite-vec 0.1.7-alpha.2 providing vector similarity search.

The plugin entry point is index.ts, declared in openclaw.plugin.json with a pluginApi compatibility requirement of >= 2026.3.13. The package.json main field points to ./dist/index.mjs, built via tsdown. Three CLI binaries ship with the package: migrate-sqlite-to-tcvdb, export-tencent-vdb, and read-local-memory, each with its own tsconfig.json under scripts/.

Key dependencies reveal the technology choices: @ai-sdk/openai (^3.0.53) for LLM communication, @node-rs/jieba (^2.0.1) for Chinese tokenization, js-tiktoken for token counting, zod (^4.4.3) for schema validation, and undici (^8.1.0) for HTTP. The optional opik dependency (^1.0.0) provides observability integration. Peer dependencies on node-llama-cpp (^3.16.2) and openclaw (>= 2026.3.7) are both marked optional in peerDependenciesMeta.

Integration Surface: OpenClaw, Hermes, and Configuration

  • OpenClaw integration: install via openclaw plugins install --link . to register the local directory as a plugin; restart the Gateway after code changes
  • Hermes integration: hermes-plugin/ directory contains the adapter; the Python client supports MEMORY_TENCENTDB_GATEWAY_API_KEY for automatic Bearer header injection
  • Gateway security: server.apiKey / TDAI_GATEWAY_API_KEY enables Bearer auth on all non-/health routes using crypto.timingSafeEqual to prevent timing attacks
  • CORS control: server.corsOrigins / TDAI_CORS_ORIGINS accepts explicit origin lists; empty list disables CORS headers, "*" preserves legacy permissive behavior
  • Recall budget: recall.maxCharsPerMemory and recall.maxTotalRecallChars (default 0 = unchanged) trim oversized entries before injection into <relevant-memories>
  • Embedding compatibility: embedding.sendDimensions (default true) can be set to false for fixed-dimension models like BGE-M3 that reject the dimensions field with HTTP 400
  • Reasoning model control: llm.disableThinking and offload.disableThinking support vllm, deepseek, dashscope, openai, anthropic, kimi, and gemini strategies for disabling chain-of-thought

Try-It Path: From Clone to Running Plugin

  • Prerequisites: Node.js >= 22.16.0, npm or pnpm, OpenClaw >= 2026.3.13
  • Clone: git clone https://github.com/Tencent/TencentDB-Agent-Memory.git
  • Install dependencies: npm install (the postinstall script patches OpenClaw tool-call messages)
  • Register as local plugin: openclaw plugins install --link .
  • No build step needed for development — Node 22.16+ type stripping lets OpenClaw load .ts directly
  • Read captured memory: node ./bin/read-local-memory.mjs to inspect stored conversations and extracted layers
  • Run tests: npm test executes vitest run; npm run test:coverage adds coverage via @vitest/coverage-v8

Who should pay attention?

Good fit if

  • OpenClaw-based agent deployments where cross-session memory persistence directly reduces operational token costs
  • Privacy-sensitive or air-gapped environments that cannot send conversation data to external embedding or LLM APIs
  • Long-horizon agent workflows (50+ consecutive tasks) where context accumulation pressure degrades performance
  • Chinese-language agent applications — @node-rs/jieba tokenization and multi-language prompt adaptation are first-class features
  • Teams evaluating local LLM offloading via node-llama-cpp who need structured memory alongside inference

Skip for now if

  • Projects not using OpenClaw or Hermes as their agent framework — the plugin manifest and hooks are tightly coupled to these runtimes
  • Environments running Node.js below 22.16 — the engines field and type-stripping requirement are hard constraints
  • Use cases requiring only simple RAG retrieval without progressive layering — the four-tier pipeline adds complexity that flat-store solutions avoid
  • Teams that need production-grade stability guarantees — version 0.3.6 with an Unreleased section in the changelog indicates active churn

Risks and cautions

Medium

Functional and locally deployable today, but version 0.3.6 with an active Unreleased section, alpha-grade sqlite-vec dependency, and hard coupling to OpenClaw/Hermes runtimes create integration and stability uncertainty.

  • sqlite-vec 0.1.7-alpha.2 is an alpha-version dependency for the core vector search capability
  • The Unreleased section in CHANGELOG.md describes timezone, disableThinking, and backup-restore changes that may alter behavior before the next stable tag
  • OpenClaw >= 2026.3.13 is required for the plugin API; teams without OpenClaw cannot use the primary integration path
  • The postinstall script runs scripts/openclaw-after-tool-call-messages.patch.sh, which patches the OpenClaw runtime — non-trivial for CI/CD environments
  • L2 scene extraction data-loss bug (#88) was fixed in 0.3.6, indicating the scene layer had reliability issues in prior versions
  • MIT license with standard warranty disclaimer — confirmed in the LICENSE file
  • Gateway Bearer auth uses crypto.timingSafeEqual to prevent timing side-channel attacks on API key comparison
  • CORS whitelist defaults to disabled (empty list = no CORS headers sent), with explicit opt-in required for cross-origin access
  • Gateway startup prints a security posture summary and emits a WARN when bound to non-loopback addresses without an apiKey
  • All timestamps stored as UTC instants in SQLite/TCVDB regardless of configured timezone, preventing timezone-related data corruption

Alternatives to compare

ApproachWhen to useTrade-off
mem0
You need a hosted or self-hosted memory layer that works across multiple agent frameworks, not just OpenClaw/HermesOpen source (Apache 2.0) with hosted cloud tier
Letta (formerly MemGPT)
You want OS-level memory management with a REST API and don't need the four-tier progressive layering modelOpen source with managed cloud option
Zep
You need temporal knowledge graphs from conversation history and prefer a GraphRAG approach over persona/scene layeringOpen source (Apache 2.0) with cloud offering
LangGraph checkpointers with SQLite/Postgres
You already use LangGraph and need simpler state persistence without a dedicated memory abstraction layerFree, bundled with LangGraph

What this trend reveals

Air-gapped enterprise agent deployments

Government, healthcare, and financial institutions that cannot send conversation data to OpenAI or Anthropic embedding APIs can deploy this plugin with a local LLM via node-llama-cpp and SQLite storage. The zero-external-API design and UTC-instant storage model address common compliance requirements.

Check whether your security team approves of sqlite-vec alpha in production; verify node-llama-cpp model quality on your hardware for L1–L3 extraction prompts.

Chinese-language agent applications

The @node-rs/jieba dependency and automatic multi-language prompt adaptation (issue #38) make this plugin particularly suited for Chinese-language agent workflows, where tokenization quality directly affects L1 extraction and L2 scene quality.

Run a 50-conversation session in Chinese and inspect persona.md output via read-local-memory to verify extraction quality matches your domain vocabulary.

Token cost reduction at scale

The 61.38% token reduction on WideSearch translates directly to inference cost savings. For agents running millions of tokens per day, even a fraction of this reduction justifies the integration effort.

Reproduce the WideSearch or SWE-bench benchmark with your agent's actual workload to confirm token savings hold outside the reported test conditions.

Best next action

Install as a local OpenClaw plugin and run a 50-conversation test session

Clone the repository, link it into OpenClaw, run a realistic multi-turn conversation, then use read-local-memory to inspect what the L0→L3 pipeline captured. Compare token usage and recall quality against your baseline.

  1. Ensure Node.js >= 22.16.0 and OpenClaw >= 2026.3.13 are installed
  2. Run: git clone https://github.com/Tencent/TencentDB-Agent-Memory.git && cd TencentDB-Agent-Memory && npm install
  3. Run: openclaw plugins install --link .
  4. Start the Gateway and run a 50-message conversation session with your agent
  5. Run: node ./bin/read-local-memory.mjs to inspect captured layers and persona.md output
  6. Compare token consumption against the same session without the plugin

RepoDaily verdict

TencentDB Agent Memory offers a technically distinctive approach to agent memory — progressive four-tier layering with local SQLite vector search and zero external API dependencies. The benchmark numbers are compelling, the MIT license and TypeScript source lower adoption friction, and the security features (timing-safe auth, CORS control, UTC storage) show production awareness. The main caveats are the alpha sqlite-vec dependency, tight OpenClaw coupling, and the active Unreleased changelog. For OpenClaw-based teams who need persistent memory without external API calls, this is worth a focused evaluation session.

Sources