feat(cli): add memory hook adapter#452
Conversation
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
|
Duplicate/scope cleanup triage for #235: This should not be reviewed as another standalone adapter foundation while the #235 lanes already have approved or narrower canonical PRs:
This PR adds a new Python CLI package with its own Gateway HTTP client, hook adapter, session/config helpers, examples, and tests. That overlaps the shared Gateway boundary from #316 and creates another runtime/package surface to maintain before the canonical base has landed. Recommendation: close this PR as a parallel #235 foundation. If a CLI hook adapter is still needed after #316/#372 land, please reopen it as a much narrower follow-up that reuses the approved Gateway/MCP boundary, explains why a CLI package is required in addition to the MCP bridge, and avoids carrying a second Gateway client abstraction. |
概述
本 PR 新增一个独立的 Python CLI adapter 包:
packages/tdai-memory-cli。它提供一组通用命令,让不同 agent runtime 可以通过命令行调用 TencentDB Agent Memory Gateway。CLI 本身不启动、不关闭、不 watch Gateway,只连接一个已经运行中的 TDAI Gateway,并通过 Gateway HTTP API 完成 recall、capture 和 session flush。
关联 Issue
Part of #235
提供的 CLI 能力
tdai-memory session-startGET /healthtdai-memory prefetchPOST /recalltdai-memory sync-turnPOST /capturetdai-memory end-sessionPOST /session/end同时提供一个可选的 stdin 事件适配入口,方便支持 command hook 的 agent runtime 将 hook event 转成 CLI 调用:
tdai-memory-hook session-starttdai-memory session-starttdai-memory-hook prefetchtdai-memory prefetchtdai-memory-hook sync-turntdai-memory sync-turntdai-memory-hook end-sessiontdai-memory end-session实现范围
本 PR 包含:
tdai-memory-cliexamples/skills/tdai-memory/设计说明
CLI 默认假设 Gateway 已经由用户或部署环境启动。
整体调用链路是:
不同 agent runtime 的 hook 注册方式并不相同,因此本 PR 只提供通用 CLI 命令和可选的 stdin 事件适配入口。Codex / Claude Code 的 hook JSON 放在
examples/下,仅作为注册方式示例。这样可以让 Codex、Claude Code 或其他支持命令调用的 agent runtime 通过 CLI 接入 TencentDB Agent Memory,同时保持 Gateway 生命周期管理和 CLI adapter 解耦。
examples/skills/tdai-memory/是 CLI 的使用示例 skill 目录,入口文件是SKILL.md,用于说明 agent 在什么场景下应该调用tdai-memory/tdai-memory-hook。它不负责安装,也不修改AGENTS.md或CLAUDE.md。Codex / Claude Code hooks 示例
本 PR 在
examples/下提供 Codex 和 Claude Code 的 hook JSON 示例,用于展示不同 agent runtime 如何把自身 hook event 接到通用 CLI 命令上。examples/codex/hooks.jsontdai-memory-hookexamples/claude-code/hooks.jsontdai-memory-hookexamples/hooks.jsonCodex 示例中的事件映射:
SessionStarttdai-memory-hook session-startUserPromptSubmittdai-memory-hook prefetchStoptdai-memory-hook sync-turnClaude Code 示例中的事件映射:
SessionStarttdai-memory-hook session-startUserPromptSubmittdai-memory-hook prefetchStoptdai-memory-hook sync-turn这些 JSON 只作为注册示例存在。不同 agent runtime 可以用自己的 hook 注册方式调用同一组
tdai-memory/tdai-memory-hook命令。自测结果
cd packages/tdai-memory-cli && python3 -m pytest tests/unit -q16 passedcd packages/tdai-memory-cli && python3 -m py_compile tdai_memory_cli/*.py可选 e2e 测试需要本地已经运行 TDAI Gateway,因此不作为默认自测要求。