Skip to content

feat: implement powermem langchain middleware - #1177

Closed
guojunyuan2004 wants to merge 1 commit into
oceanbase:vldb_2026from
guojunyuan2004:feat/powermem-langchain-middleware
Closed

guojunyuan2004 wants to merge 1 commit into
oceanbase:vldb_2026from
guojunyuan2004:feat/powermem-langchain-middleware

Conversation

@guojunyuan2004

Copy link
Copy Markdown

Team

旅游凑一队

Summary

Implement PowerMemMiddleware for the VLDB 2026 summer school Task 1: integrate PowerMem as long-term memory for LangChain v1 agents via the middleware API.

Solution Description

Wire PowerMem into LangChain v1 agents via three middleware hooks: before_agent retrieves memories for the latest user message, wrap_model_call injects them into the system prompt, and after_agent writes the exchange back when save_interactions=True. Both sync and async paths are supported; retrieval and write-back are fail-open.

Design notes worth keeping for future readers:

  • powermem_context is overwritten on every run (including None) so a checkpointer cannot leak a previous run's memory into the next.
  • An AsyncMemory in the sync hooks raises TypeError rather than silently doing nothing.
  • user_id comes only from the constructor; no global or implicit identity.

Tests: 20 functions; the six names required by the scoring contract are present verbatim. See packages/powermem-langchain/ for details.

Wire PowerMem into LangChain v1 agents via three middleware hooks:
before_agent retrieves memories for the latest user message,
wrap_model_call injects them into the system prompt, after_agent
writes the exchange back when save_interactions=True. Both sync and
async paths are supported; retrieval/write-back are fail-open.

Design notes worth keeping for future readers:
- powermem_context is overwritten on every run (including None) so a
  checkpointer cannot leak a previous run's memory into the next.
- An AsyncMemory in the sync hooks raises TypeError rather than
  silently doing nothing.
- user_id comes only from the constructor; no global/implicit identity.

Tests: 20 functions; the six names required by the scoring contract
are present verbatim. See packages/powermem-langchain/ for details.
@PsiACE PsiACE added the vldb 2026 VLDB 2026 contributions label Jul 14, 2026
@LINxiansheng

Copy link
Copy Markdown
Member

LangChain Contract Score

LangChain Contract Score
========================
score: 100.00 / 100
suites: 2
rule: A weighted capability receives credit only when it passes on every configured Python suite and all declared prerequisite capabilities also receive credit. Gate tests are reported but do not add points.

Public import contract: PASS (gate)
  py311: passed
  py312: passed
Retrieve memory before model call: PASS (35/35)
  py311: passed
  py312: passed
Persist interaction after agent run: PASS (25/25)
  py311: passed
  py312: passed
Disable interaction persistence: PASS (10/10)
  py311: passed
  py312: passed
Fail-open on search error: PASS (15/15)
  py311: passed
  py312: passed
Async memory injection: PASS (15/15)
  py311: passed
  py312: passed

LangChain Contract Report

LangChain Contract Report
=========================
score: 100.00 / 100
rule: A weighted capability receives credit only when it passes on every configured Python suite and all declared prerequisite capabilities also receive credit. Gate tests are reported but do not add points.

Suite Summary
-------------
py311: passed=25/25, failures=0, errors=0, skipped=0
py312: passed=25/25, failures=0, errors=0, skipped=0

Gate Checks
-----------
Public import contract [gate] PASS
  - py311: passed
  - py312: passed

Weighted Breakdown
------------------
Retrieve memory before model call [35/35] PASS
  - py311: passed
  - py312: passed
Persist interaction after agent run [25/25] PASS
  - py311: passed
  - py312: passed
Disable interaction persistence [10/10] PASS
  - py311: passed
  - py312: passed
Fail-open on search error [15/15] PASS
  - py311: passed
  - py312: passed
Async memory injection [15/15] PASS
  - py311: passed
  - py312: passed

Workflow run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vldb 2026 VLDB 2026 contributions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants