Skip to content

feat: implement powermem langchain middleware - #1171

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

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

Conversation

@sallyjinx

Copy link
Copy Markdown

Summary

Solution Description

Copilot AI review requested due to automatic review settings July 14, 2026 06:22
@CLAassistant

CLAassistant commented Jul 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements a functional PowerMemMiddleware for LangChain agents, enabling long-term memory retrieval before model calls and optional interaction write-back after agent runs, aligning the package with its contract tests and example usage.

Changes:

  • Added PowerMem search + context formatting and injected retrieved memories into the model request.
  • Implemented sync/async middleware hooks (before_agent/abefore_agent, wrap_model_call/awrap_model_call, after_agent/aafter_agent) with fail-open behavior.
  • Added helper utilities for extracting latest user/assistant text and safely calling sync/async memory backends.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

point. Students are expected to replace this placeholder with a LangChain
middleware implementation that satisfies the package contract tests.
"""
"""为LangChain agent提供PowerMem长期记忆能力的中间件"""
Comment on lines +146 to +157
try:
result = self.memory.search(
query,
user_id=self.user_id,
limit=self.search_limit,
)
if inspect.isawaitable(result):
result = asyncio.run(result)
return {"powermem_context": _format_search_result(result)}
except Exception:
logger.warning("PowerMem search failed; continuing without memory", exc_info=True)
return {"powermem_context": ""}
Comment on lines +234 to +244
try:
result = self.memory.add(
interaction,
user_id=self.user_id,
infer=False,
)
if inspect.isawaitable(result):
asyncio.run(result)
except Exception:
logger.warning("PowerMem write-back failed; agent result is unchanged", exc_info=True)
return None
Comment on lines +45 to +47
if isinstance(block, str): # 普通字符串
parts.append(block)
elif isinstance(block, Mapping): # 列表
@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=6/6, failures=0, errors=0, skipped=0
py312: passed=6/6, 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

@PsiACE PsiACE added the vldb 2026 VLDB 2026 contributions label Jul 14, 2026 — with ChatGPT Codex Connector
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.

5 participants