Replies: 1 comment
-
|
The injection format question is worth thinking through carefully. When retrieved memories land alongside the system prompt, the model needs to distinguish "this is long-term memory" vs "this is active task constraints" vs "this is current input." If it's all prose in one block, the model has to infer those boundaries and can conflate them. Typed XML blocks (like I've been building flompt for exactly this kind of structured prompt construction, a visual builder that decomposes prompts into typed semantic blocks and compiles to XML. Same principle applies to context injection design. Open-source: github.com/Nyrok/flompt |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
OpenClaw Context Engine Integration Design / OpenClaw 上下文引擎集成方案设计
Context / 背景
本方案讨论在 OpenViking 中集成 OpenClaw Context Engine 的扩展机制,以及围绕新引擎的记忆管理、查询、注入等完整设计。
This proposal discusses the extension mechanism for integrating OpenClaw Context Engine into OpenViking, along with the complete design for memory management, retrieval, and injection around the new engine.
Component 1: Memory Write Mechanism / 组件 1:记忆写入机制
Compact-Triggered Automatic Write / compact 触发的自动写入
当 compact 时一次性把对话上传到 ov。
Upload conversation to OpenViking in one batch when compact is triggered.
可选项:compact 时,可以把一些工作记忆(比如 TODO,摘要),留在压缩后的上下文里面(如果有的话),避免断档。
Optional: During compact, keep some working memories (e.g., TODOs, summaries) in the compressed context (if available) to avoid discontinuity.
由于涉及 agent 记忆的提取,建议把 system prompt 和工具调用也一起上传。
Since agent memory extraction is involved, it is recommended to also upload the system prompt and tool calls together.
相比于之前模式(每条消息都写入),一次性的写入可以减少记忆提取阶段的 token 消耗,带来的缺点是跨 session 的记忆同步会变慢(不敏感)。
Compared to the previous mode (writing every message), one-time writing reduces token consumption during memory extraction. The downside is that cross-session memory synchronization will be slower (not sensitive).
compact 一般在 /new 或消息达到一定长度时触发,消息未达长度的部分不会触发记忆提取。这部分未来可以加入 timeout 触发提取的机制(当前可以不要)。
Compact is typically triggered by /new or when messages reach a certain length. Messages that don't reach the length threshold won't trigger memory extraction. A timeout-based extraction mechanism can be added in the future (not needed currently).
Active Memory (Tool-based) / 主动记忆(基于工具)(可选)
这允许 agent 通过
commit_memory工具(或ov cli)主动记录记忆,支持用户请求如:This allows the agent to actively record memories via a
commit_memorytool (or ov cli), supporting user requests like:commit_memory Tool / 工具:
memory_content,memory_type,priority,categoryComponent 2: Memory Retrieval / 组件 2:记忆查询/召回
记忆查询分为三部分:
Memory retrieval has three parts:
Part 1: User Profile Injection / 第一部分:用户画像注入
在会话开始时一次性注入到 system prompt。
Injected once at session start into the system prompt.
Profile Sources / 画像来源:
profile.md- User's main profile file (always included) / 用户主画像文件(总是包含)Part 2: Per-turn Memory Retrieval / 第二部分:每轮记忆召回
为每条用户消息召回,仅用于该次 LLM 调用。
Retrieved for each user message, only used for that single LLM call.
Query Construction / 查询构建: Use last N user messages (default: 5) concatenated as the search query / 使用最近 N 条用户消息(默认:5条)拼接作为搜索查询
Lightweight Intent Detection / 轻量级意图检测(TODO 可选模块,可基于轻量模型实现 / TODO optional module, can be implemented with lightweight models):
将自动召回的记忆作为模拟的 function call 结果注入,而不是直接注入到 prompt 中
Inject auto-retrieved memories as simulated function call results instead of directly injecting into the prompt. This is a continuation of Part 2.
Benefits / 好处:
Example Flow / 示例流程:
Retrieval Flow / 召回流程:
Component 3: Agentic Memory Query / 组件 3:Agent 通过工具主动记忆查询
除了每轮自动注入之外,还提供 Agent 发起的查询机制,以满足更复杂的检索需求。这是一种"测试时扩展"的方法,用于解决单轮回召可能遗漏的多跳和多背景检索问题。
In addition to per-turn auto-injection, provide an agent-initiated query mechanism to meet more complex retrieval needs. This is a "test-time scale" approach to solve multi-hop and multi-context retrieval problems that single-round retrieval may miss.
Pre-inject Directory Structure / 预先注入目录结构
为了让主动记忆的路径尽可能短,可以默认把
ov ls viking://的结果预先注入到 system prompt 里面,让 agent 预先知道 ov 里有哪些数据可以用。如果能模拟成是 agent 主动调用的,效果可能更好。To make the path to active memory as short as possible, pre-inject the results of
ov ls viking://into the system prompt by default, so the agent knows in advance what data is available in OpenViking. Effect may be better if simulated as an agent-initiated call.Design / 设计:
ov ls viking://(or equivalent) / 运行ov ls viking://(或等效操作)Example / 示例:
When to Use / 何时使用
Component 4: Skill Memory Injection / 组件 4:Skill 记忆注入
Skill 记忆是Agent记忆的一种,区别点在于他锚定一个确定性的Skill
因此可以通过拦截工具调用中的
read skills/xxx/SKILL.md文件调用,在返回结果中添加 skill 记忆的方式注入。Skill memories are a type of agent memory, with the key distinction that they are anchored to a specific skill.
Therefore, they can be injected by intercepting
read skills/xxx/SKILL.mdfile calls in tool calls, and adding skill memories to the returned results.Design / 设计:
Intercept skill file reads / 拦截 skill 文件读取
skills/<skill_name>/SKILL.md/ 当 agent 读取skills/<skill_name>/SKILL.md时Augment skill content / 增强 skill 内容
Skill memory structure / Skill 记忆结构
Example / 示例:
Component 5: Tool Memory Injection / 组件 5:工具记忆注入
工具记忆可以通过 system prompt 方式注入。
Tool memories can be injected via system prompt.
Design / 设计:
Inject into system prompt / 注入到 system prompt
Tool memory content / 工具记忆内容
Format / 格式
Example / 示例:
Appendix: OpenViking Tool Injection / 附录:OpenViking 工具注入
本节讨论如何将 OpenViking 能力注入到 Agent 中。提出了两种方案,都避免了基于 skill 的注入模式。
This section discusses how to inject OpenViking capabilities into the agent. Two options are proposed, both avoiding the skill-based injection pattern.
Problem with Skill-based Injection / 基于 Skill 注入的问题
Option 1: System Prompt + Bash CLI (Recommended if CLI is LLM-friendly) / 方案 1:System Prompt + Bash CLI(如果 CLI 对 LLM 友好,推荐此方案)
直接将 OpenViking CLI 用法说明注入到 system prompt 中。Agent 使用内置的 bash 工具调用
ov命令。Inject OpenViking CLI usage instructions directly into the system prompt. The agent uses the built-in bash tool to call
ovcommands.Advantages / 优势:
Requirements / 要求:
Example Commands / 示例命令:
Option 2: Tool Definition Injection / 方案 2:工具定义注入
将 OpenViking 能力定义为显式的工具定义(function calling)。
Define OpenViking capabilities as explicit tool definitions (function calling).
Advantages / 优势:
Disadvantages / 劣势:
Comparison / 对比
Recommendation / 建议
Primary Recommendation: Option 1 (CLI + Bash) if CLI can be made LLM-friendly
主要建议:如果 CLI 能做到对 LLM 友好,选择方案 1(CLI + Bash)
Why / 为什么:
Fallback: Option 2 (Tool Definition) if CLI can't be simplified enough
备选方案:如果 CLI 无法足够简化,选择方案 2(工具定义)
Beta Was this translation helpful? Give feedback.
All reactions