Skip to content

feat(adapters): add LangChain memory middleware - #466

Open
March-77 wants to merge 19 commits into
TencentCloud:mainfrom
March-77:feat/235-langchain-memory-middleware
Open

March-77 wants to merge 19 commits into
TencentCloud:mainfrom
March-77:feat/235-langchain-memory-middleware

Conversation

@March-77

Copy link
Copy Markdown

Description | 描述

Adds a focused LangChain v1 / LangGraph middleware adapter on top of the shared Gateway adapter kit from #316.

  • maps beforeAgent to Gateway /recall
  • maps afterAgent to Gateway /capture
  • resolves a stable LangGraph thread/session identity through host runtime context
  • normalizes LangChain BaseMessage values to JSON-safe { role, content } messages
  • fails open by default when the Gateway is unavailable, with an opt-in fail-closed mode
  • adds focused unit tests and a Mermaid data-flow/usage guide
  • does not add LangChain as a core dependency; the host injects its installed createMiddleware

Related Issue | 关联 Issue

Related to #235
Depends on #316

Change Type | 修改类型

  • Bug fix | Bug 修复
  • New feature | 新功能
  • Documentation update | 文档更新
  • Code optimization | 代码优化

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过
  • No existing features affected | 无影响现有功能

Verification:

  • npm.cmd exec vitest run src/adapters/langchain/langchain.test.ts src/adapters/gateway-client/gateway-client.test.ts: 8 passed
  • npm.cmd test: 75 passed
  • npm.cmd run build:plugin: passed
  • git diff --check: passed

Additional Notes | 其他说明

This is intentionally a small platform-specific follow-up. It reuses #316 instead of introducing another Gateway client or adapter SDK. The PR is opened as draft while #316 is pending; once #316 lands, this branch can be rebased so the review diff contains only the LangChain middleware commit.

RerankerGuo and others added 4 commits June 30, 2026 20:40
Signed-off-by: Ziyang Guo <121015044+RerankerGuo@users.noreply.github.com>
Signed-off-by: Ziyang Guo <121015044+RerankerGuo@users.noreply.github.com>
Signed-off-by: Ziyang Guo <121015044+RerankerGuo@users.noreply.github.com>
Signed-off-by: zhangzherui <jerry_@whut.edu.cn>
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program!
We have successfully received your submission. The program is currently in full swing, and we will complete the Code Review for you as soon as possible. Please keep an eye on the status notifications for this PR so you can follow up promptly once the review feedback is provided.
Thanks again for your contribution and open-source spirit! 🚀

@March-77
March-77 marked this pull request as ready for review July 14, 2026 16:16
PorunC and others added 13 commits July 17, 2026 11:07
…tCloud#151)

* feat(hermes): support Windows native setup

Closes TencentCloud#113

Signed-off-by: misaka <09982.misaka@gmail.com>

* test(postinstall): cover cross-platform behavior

* Delete __tests__/postinstall.test.ts

* Delete hermes-plugin/memory/memory_tencentdb/tests/test_memory_tencentdb_recovery.py

---------

Signed-off-by: misaka <09982.misaka@gmail.com>
Co-authored-by: 十五便士 <95488710+Maxwell-Code07@users.noreply.github.com>
Add unit tests for memory-tencentdb provider self-healing functionality, including watchdog behavior and request path recovery.
* Update README.md

* Update README_CN.md
* docs: add Star History chart to README

* docs: replace Star History chart with GitHub badges

* docs: use real Star History chart image in README
…solves TencentCloud#160) (TencentCloud#529)

* fix(store): sanitize FTS5 query tokens to prevent MATCH injection#160

问题
buildFtsQuery() 把用户输入拼成 FTS5 MATCH 表达式,含 FTS5 操作符(`" ' * ( ) AND OR NOT NEAR : ^`)的输入会篡改查询语义或触发语法错误(注入)。

方案
- `sanitizeFtsToken()`:双引号包字面 phrase,内部 `"` 转义为 `""`(修正旧实现"删除双引号"导致的 recall 损伤)
- `sanitizeFtsWhitelist()`:字符级白名单(defence-in-depth)
- `buildFtsQuery` 复用 `sanitizeFtsToken`
- 与项目已有的 `MATCH ?` 参数化(SQL 防注入)组成三层防御

测试
新增 38 个:单元(21)+ 真实 FTS5 召回对比(4)+ 白名单(13)。本地全量 **105 passed**,零回归。

 验收对照
issue 四档全覆盖:基础 / 进阶 / 深入(真实 FTS5 recall 实证)/ 拓展(白名单 + 参数化三层防御)。

* Delete src/core/store/buildFtsQuery.recall.test.ts

* Delete src/core/store/buildFtsQuery.test.ts

* Delete src/core/store/buildFtsQuery.whitelist.test.ts

---------

Co-authored-by: 十五便士 <95488710+Maxwell-Code07@users.noreply.github.com>
…ounters after cleanup (TencentCloud#337)

* fix(data): add CheckpointManager.recalculate() to reconcile drifted counters after cleanup

After cleanup operations (memory-cleaner, manual JSONL pruning, or
pipeline state deletion), checkpoint counters (l0_conversations_count,
total_memories_extracted) can drift from actual data — they only
increment, never decrease.

Add recalculate() to CheckpointManager that accepts actual counts and
overwrites drifted counters under the file lock. Call it once at startup
in wirePipelineRunners() after vector store is initialized.

Closes TencentCloud#157

Signed-off-by: xiyue1753 <xiyuekl@qq.com>

* Delete src/utils/checkpoint.test.ts

---------

Signed-off-by: xiyue1753 <xiyuekl@qq.com>
Co-authored-by: 十五便士 <95488710+Maxwell-Code07@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants