feat(cli): add memory hook adapter#452
Open
soongao wants to merge 1 commit into
Open
Conversation
Collaborator
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
本 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,因此不作为默认自测要求。