[wip] feat(openclaw-contextengine-plugin): add OpenViking context-engine plugin for OpenClaw#548
[wip] feat(openclaw-contextengine-plugin): add OpenViking context-engine plugin for OpenClaw#548wlff123 wants to merge 1 commit intovolcengine:mainfrom
Conversation
f019811 to
505c5cb
Compare
…ugin Add the OpenViking context-engine plugin, including envelope response handling and a gated real-online integration test path for end-to-end retrieval/assemble verification.
505c5cb to
84e6ae5
Compare
|
Can this PR be merged now, or is it still in progress? |
|
| .filter((s): s is string => typeof s === "string" && s.length > 0) | ||
| .join("\n"), | ||
| MAX_RETRIEVAL_TEXT_CHARS, | ||
| ); |
There was a problem hiding this comment.
[Bug] simulated_tool_result 模式没有真正注入模拟工具结果到 messages 中。
设计方案(Discussion #525)明确要求:"Injects auto-retrieved memories as simulated function call results, not directly into prompts"。
但当前实现中,不论 injectMode 是 simulated_tool_result 还是 text,检索结果都只放入 systemPromptAddition(系统提示文本)。assemble 返回的 messages(第 113 行)就是原始输入,未插入任何模拟工具结果消息。两种模式的实际效果只是文本格式不同,注入位置完全一样,与设计意图不符。
建议:simulated_tool_result 模式应在 messages 数组中插入一条模拟的 tool result 消息,而非将文本放入 systemPromptAddition。
| estimatedTokens: number; | ||
| systemPromptAddition?: string; | ||
| }> { | ||
| const query = buildTurnQuery(params.messages, 3); |
There was a problem hiding this comment.
[Bug] maxUserTurns 硬编码为 3,与设计方案不符。
设计方案要求 "Use last N user messages (default: 5) concatenated as the search query",且该值应通过配置控制。当前既不可配置也不符合设计默认值。
建议:将此值提取为 config.retrieval.lastNUserMessages(默认 5),并加入 config schema。
| if (message?.role !== "user") { | ||
| continue; | ||
| } | ||
| const text = normalizeContent(message.content); |
There was a problem hiding this comment.
[Bug] 缺少 query 意图过滤逻辑。
设计方案要求 "Lightweight intent detection skips greetings and very short messages (≤3 characters)",但 buildTurnQuery 对所有用户消息一视同仁,没有跳过问候语或短消息的逻辑。
设计文档中提到的 retrieval.skipGreeting 和 retrieval.minQueryChars 配置项也未在 config schema 中实现。
建议:在拼接 query 前过滤掉长度 ≤3 的消息,并可选地检测常见问候语(如 "hello"、"hi"、"你好")跳过检索。
| export async function writeBatchAndCommit( | ||
| client: CommitClient, | ||
| payload: BatchMessage[], | ||
| ): Promise<{ extractedCount: number }> { |
There was a problem hiding this comment.
[Bug] finally 块中 deleteSession 若抛出异常,会覆盖 try 块中的原始错误。
例如 commitSession 失败抛出 Error A,接着 deleteSession 也失败抛出 Error B,JavaScript 只会传播 Error B,Error A 丢失。tools.ts 第 51 行有同样的问题。
建议修改为:
finally {
try {
await client.deleteSession(sessionId);
} catch {
// log but don't mask the original error
}
}| } | ||
|
|
||
| async bootstrap(): Promise<{ bootstrapped: boolean; importedMessages: number }> { | ||
| return { bootstrapped: true, importedMessages: 0 }; |
There was a problem hiding this comment.
[Suggestion] bootstrap() 是空实现,直接返回 { bootstrapped: true, importedMessages: 0 }。
设计方案要求 session start 时进行用户 profile 注入,包括 profile.md(始终注入)和高质量记忆摘要(质量分达阈值时注入)。当前没有任何 profile 检索逻辑。
| if (tools.length === 0) { | ||
| return ""; | ||
| } | ||
| return `Tool hints for ${intent}: ${tools.join(", ")}.`; |
There was a problem hiding this comment.
[Suggestion] buildToolMemoryHints 和 buildSkillMemoryAugmentation 只返回静态模板字符串(如 "Tool hints for {intent}: {tools}"),没有查询实际使用统计数据。
设计方案要求注入调用次数、成功率、常见参数模式、错误模式等。当前实现与设计的 Skill/Tool Memory 注入能力差距较大。
| const sessionId = await deps.client.createSession(); | ||
| try { | ||
| await deps.client.addSessionMessage(sessionId, params.role ?? "user", params.content); | ||
| const committed = await deps.client.commitSession(sessionId); |
There was a problem hiding this comment.
[Suggestion] commit_memory 工具只接收 content 和 role 参数,设计方案要求支持 memory_content, memory_type, priority, category, targetUri 等字段,以实现更精细的记忆分类和写入控制。
| private readonly client: OpenVikingClient; | ||
|
|
||
| constructor(deps: EngineDeps) { | ||
| this.config = parseConfig(deps.config); |
There was a problem hiding this comment.
[Suggestion] config 被 parseConfig 双重解析。index.ts:8 已调用 parseConfig(api.pluginConfig ?? {}) 生成类型化的 config,传入构造函数后这里又调用 parseConfig(deps.config) 再次解析。虽然不会报错,但逻辑上冗余。
建议直接赋值 this.config = deps.config。
| }); | ||
|
|
||
| const messagesJson = JSON.stringify(params.messages); | ||
| return { |
There was a problem hiding this comment.
[Suggestion] estimatedTokens 实际值为 JSON.stringify(params.messages).length(字符数),并非 token 数。命名有误导性,建议改为 estimatedChars 或引入近似转换(如 chars/4)。
…ample
Add a complete context-engine plugin example with retrieval, ingestion, fallback handling, tool exposure, and archived design/implementation plans for reproducible setup and extension.
Description
Related Issue
Type of Change
Changes Made
Testing
Checklist
Screenshots (if applicable)
Additional Notes