Skip to content

fix(memory): align extraction, tool outcomes and bounded recall - #752

Open
openjiuwen-sync-bot[bot] wants to merge 1 commit into
openJiuwen-ai:mem2.0from
openjiuwenai:sync/pr-534
Open

openjiuwen-sync-bot[bot] wants to merge 1 commit into
openJiuwen-ai:mem2.0from
openjiuwenai:sync/pr-534

Conversation

@openjiuwen-sync-bot

@openjiuwen-sync-bot openjiuwen-sync-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Paired: GitHub #752 ↔ GitCode !534

What type of PR is this?

/kind

Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)

    • 设计:PR对应的方案是否已经经过Maintainer评审,方案检视意见是否均已答复并完成方案修改
    • 测试:PR中的代码是否已有UT/ST测试用例进行充分的覆盖,新增测试用例是否随本PR一并上库或已经上库
    • 验证:PR描述信息中是否已包含对该PR对应的Feature、Refactor、Bugfix的预期目标达成情况的详细验证结果描述
    • 接口:是否涉及对外接口变更,相应变更已得到接口评审组织的通过,API对应的注释信息已经刷新正确
    • 文档:是否涉及官网文档修改,如果涉及请及时提交资料到Doc仓

Linked Closing Issues:

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zhengpeng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zhengpeng seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 00a482fa4cbf87df895746d6824fbc08866c2d60

变更摘要

本 PR 围绕记忆子系统的一致性做修正:统一记忆工具返回结构为 {"success": true|false, ...},并区分「显式工具调用透出错误」与「后台预取降级」两类语义;为团队记忆抽取补充语言、label/kind 归一化与丢弃原因统计;在 BaseDocumentScene 中集中引入注入预算与超时控制(tail_within_budget、_bounded(timeout=...)),并把团队、工作、代码三个场景的预取切换到有界召回;同时收敛各场景工具描述与系统提示,明确 write/edit/conclude 仅在用户显式要求时调用。

主要改动

  • 统一工具返回协议: work_memory.py、coding_memory.py、team_memory.py、memory_tools.py 及 agent_memory_provider.py 中的 {"error": ...}、{"stored": ...}、{"item_id": ...}、{"result": ...} 全部改为 {"success": true/false, ...} 结构,并新增 _tool_error_json 辅助函数统一生成失败结果。
  • 错误透传与响应校验: _HttpClient._post_verb 的 raise_on_write_error 参数改为 raise_on_error,未初始化、熔断、4xx/5xx 与传输/JSON 解析异常均按读写语义映射为 AgentMemoryClientError;新增 _validated_units 校验 add、read_md_file、edit_md_file 的返回单元结构,search 由返回空列表改为在响应结构非法时抛错。
  • 有界召回与注入预算: base_document_scene.py 新增 tail_within_budget(默认 DEFAULT_INJECT_MAX_ITEMS=20、DEFAULT_INJECT_MAX_CHARS=2000,保留最新非凭据条目),_bounded 支持自定义 timeout;work_memory.py、coding_memory.py、team_memory.py 的预取改为 asyncio.gather 并行并按预算截断,项目检索为空时回退到 MEMORY.md 文档条目。
  • 团队抽取对齐: team_llm_extractor.py 明确内容与标题需与来源片段同语言且不翻译、收紧 user_fact 判定、新增 _MAX_CANDIDATES=32 上限、label/kind 归一化(非 user_profile 时把合法标签提升为 label 并置 kind="experience")、用 _strip_source_id_shell 解析 source_id,并以 Counter 输出脱敏的丢弃原因计数。
  • 集体写入与场景召回: collective_ops.py 通过 set_request_id/reset_request_id 透传 request_id 并记录 accepted/written/deduplicated/skipped_member/skipped_destination 计数;team_memory.py 新增 _can_recall_ordinary_project 与 _search_ordinary_project,配合客户端新增的 ordinary_request(),使无会话隔离的 main_agent 能合并集体结果与普通项目记忆并按分数去重排序。

注: 本次仅按要求做变更摘要,未执行任何代码审查或仓库探查。

@openjiuwen-collaboration-bot

openjiuwen-collaboration-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

head_sha: 00a482fa4cbf87df895746d6824fbc08866c2d60

代码审查

审查结论

  • [建议] jiuwen_memory_adapter/jiuwenswarm/team_memory.py:213 fix: team_memory_write 在未落盘任何记忆时仍返回 success
  • [建议] tests/unit/construction/test_team_llm_extractor.py:72 fix: caplog 指定的 logger 名与模块实际 logger 不一致
类型 数量
🔴 阻塞 0
🟡 建议 2

💬 仅评论

caplog.set_level(
logging.INFO,
logger="agent_memory.construction.extractor_impl.team_llm_extractor",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

head_sha: 00a482fa4cbf87df895746d6824fbc08866c2d60

🟡 Medium Priority

变更行(test_team_llm_extractor.py:72-75)用 caplog.set_level(logging.INFO, logger="agent_memory.construction.extractor_impl.team_llm_extractor") 打开日志捕获,但被测符号来自 jiuwen_memory.construction.extractor_impl.team_llm_extractor(第 7 行 import)。同目录既有测试全部按模块真实路径命名:test_extractor.py:574-575 用 get_logger("jiuwen_memory.construction.extractor_impl.llm_extractor")、test_entity_linker.py:613-614 用 logger="jiuwen_memory.construction.index_builder_impl.entity_index_builder"、test_extractor_title.py:149 用 logger=logger.name(即 __name__)。说明这些 construction 模块的 logger 名以 jiuwen_memory. 前缀派生,agent_memory. 前缀的 set_level 只会作用到一个并不存在的同名 logger。失败路径:模块 logger 的有效级别仍为默认 WARNING,logger.info("... raw=%d accepted=%d ...") 在记录时被级别过滤,caplog.text 里没有对应文本,第 78-82 行的 raw=33 accepted=1、'bad_source_id': 31 断言直接失败;即使环境把级别放宽到 INFO,该断言也已退化为「捕获到任意日志」而不再真正校验目标 logger,脱敏断言(80-82 行)同样可能落在空文本上而恒真。修复方向:改为从被测模块导入 logger 并用 logger.name 设置级别(与 test_extractor_title.py 一致),或直接写 jiuwen_memory.construction.extractor_impl.team_llm_extractor。

建议:用模块自身 logger 的名字设置 caplog 级别:from jiuwen_memory.construction.extractor_impl import team_llm_extractor 后 caplog.set_level(logging.INFO, logger=team_llm_extractor.logger.name),避免前缀写错导致断言落空或失败。

return json.dumps({"error": "Memory write failed", "stored": False})
return json.dumps({"stored": bool(result.item_id), "item_id": result.item_id})
return json.dumps({"success": False, "error": "Memory write failed"})
return json.dumps({"success": True})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

head_sha: 00a482fa4cbf87df895746d6824fbc08866c2d60

🟡 Medium Priority

改动行(jiuwen_memory_adapter/jiuwenswarm/team_memory.py:213-215)把 team_memory_write 的返回从 {"stored": bool(result.item_id), "item_id": result.item_id} 改成常量 {"success": True},只要 result is not None 就报成功。
契约 1:同仓库 work_memory.py:367-377 明确写着「add 返回 item_id=None:extractor 产空(LLM 返回不可解析/未产出候选)→ 未持久化任何记忆。不可报成功(false success)」;本改动把这条已经写在同族实现的规则在 team 写入路径上去掉了。
契约 2:tests/unit/jiuwen_memory_adapter/test_agent_memory_provider_unit.py 的 ("empty", "", 0) 用例(HTTP 200 空响应)现在断言 {"success": True},即空抽取也被判成功。
失败模式:infer=True 的抽取在 LLM 返回不可解析/空候选(或去重后无新单元)时,客户端拿到的仍是非 None 结果但 item_id 为 None,工具回 {"success": True};宿主/LLM 会认为「已记住」,而实际没有任何条目落盘——这正是本 PR(#​367「记忆工具调用失败无法被感知」)要修的那类不可感知失败,只是方向从「失败不可感知」变成「空写不可感知」。

建议:在 result.item_id 为空时不要无条件返回 success:区分「去重(已有记忆)」与「抽取为空(未落盘)」两种情形,前者可回 success+deduped,后者应回 {"success": False, "error": ...},与 work_memory.py 中 _procedural 已标注的「不可报成功(false success)」口径一致;必要时同步修正 test_agent_memory_provider_unit.py 的 "empty" 用例期望。

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 00a482fa4cbf87df895746d6824fbc08866c2d60

任务名称 结果 日志操作
静态检查 ❌FAILED 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 ✅SUCCESS N/A
pr size检查 N/A N/A

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: jiuwenswarm记忆工具调用失败无法被感知

1 participant