Skip to content

[wip] feat(openclaw-contextengine-plugin): add OpenViking context-engine plugin for OpenClaw#548

Open
wlff123 wants to merge 1 commit intovolcengine:mainfrom
wlff123:oc_ov_contextengine_plugin
Open

[wip] feat(openclaw-contextengine-plugin): add OpenViking context-engine plugin for OpenClaw#548
wlff123 wants to merge 1 commit intovolcengine:mainfrom
wlff123:oc_ov_contextengine_plugin

Conversation

@wlff123
Copy link
Contributor

@wlff123 wlff123 commented Mar 12, 2026

…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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

…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.
@wlff123 wlff123 force-pushed the oc_ov_contextengine_plugin branch from 505c5cb to 84e6ae5 Compare March 12, 2026 10:43
@chenjw
Copy link
Collaborator

chenjw commented Mar 13, 2026

Can this PR be merged now, or is it still in progress?

@chenjw
Copy link
Collaborator

chenjw commented Mar 13, 2026

   这里可以改成最近5条“user”的message
   
   const retrievalQuery = buildRetrievalQuery({
     currentMessage: context.userMessage,
     recentMessages: context.conversationHistory.slice(-5), // 最近 5 条
     sessionProfile: await this.getSessionProfile()
   });             

.filter((s): s is string => typeof s === "string" && s.length > 0)
.join("\n"),
MAX_RETRIEVAL_TEXT_CHARS,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Bug] simulated_tool_result 模式没有真正注入模拟工具结果到 messages 中。

设计方案(Discussion #525)明确要求:"Injects auto-retrieved memories as simulated function call results, not directly into prompts"。

但当前实现中,不论 injectModesimulated_tool_result 还是 text,检索结果都只放入 systemPromptAddition(系统提示文本)。assemble 返回的 messages(第 113 行)就是原始输入,未插入任何模拟工具结果消息。两种模式的实际效果只是文本格式不同,注入位置完全一样,与设计意图不符。

建议:simulated_tool_result 模式应在 messages 数组中插入一条模拟的 tool result 消息,而非将文本放入 systemPromptAddition

estimatedTokens: number;
systemPromptAddition?: string;
}> {
const query = buildTurnQuery(params.messages, 3);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Bug] 缺少 query 意图过滤逻辑。

设计方案要求 "Lightweight intent detection skips greetings and very short messages (≤3 characters)",但 buildTurnQuery 对所有用户消息一视同仁,没有跳过问候语或短消息的逻辑。

设计文档中提到的 retrieval.skipGreetingretrieval.minQueryChars 配置项也未在 config schema 中实现。

建议:在拼接 query 前过滤掉长度 ≤3 的消息,并可选地检测常见问候语(如 "hello"、"hi"、"你好")跳过检索。

export async function writeBatchAndCommit(
client: CommitClient,
payload: BatchMessage[],
): Promise<{ extractedCount: number }> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[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 };
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] bootstrap() 是空实现,直接返回 { bootstrapped: true, importedMessages: 0 }

设计方案要求 session start 时进行用户 profile 注入,包括 profile.md(始终注入)和高质量记忆摘要(质量分达阈值时注入)。当前没有任何 profile 检索逻辑。

if (tools.length === 0) {
return "";
}
return `Tool hints for ${intent}: ${tools.join(", ")}.`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] buildToolMemoryHintsbuildSkillMemoryAugmentation 只返回静态模板字符串(如 "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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] commit_memory 工具只接收 contentrole 参数,设计方案要求支持 memory_content, memory_type, priority, category, targetUri 等字段,以实现更精细的记忆分类和写入控制。

private readonly client: OpenVikingClient;

constructor(deps: EngineDeps) {
this.config = parseConfig(deps.config);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] config 被 parseConfig 双重解析。index.ts:8 已调用 parseConfig(api.pluginConfig ?? {}) 生成类型化的 config,传入构造函数后这里又调用 parseConfig(deps.config) 再次解析。虽然不会报错,但逻辑上冗余。

建议直接赋值 this.config = deps.config

});

const messagesJson = JSON.stringify(params.messages);
return {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] estimatedTokens 实际值为 JSON.stringify(params.messages).length(字符数),并非 token 数。命名有误导性,建议改为 estimatedChars 或引入近似转换(如 chars/4)。

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants