DR Context Pipeline (retrieval + compression + lint)
Use this skill to standardize how an agent loads memory into its prompt for correctness.
Prerequisites
- - A file-based memory layout that includes
memory/always_on.md (policy header + topic catalog) and topic files under memory/topics/. - Recommended: install dr-memory-foundation (or implement an equivalent structure).
Quick install commands (copy/paste)
These commands work from anywhere because they set
$WORKSPACE (defaults to
~/.openclaw/workspace). Rerun them whenever you need to re-apply the pipeline:
export WORKSPACE=${WORKSPACE:-~/.openclaw/workspace}
cd "$WORKSPACE"
clawhub install dr-context-pipeline --version X.Y.Z --dir skills
python3 ./skills/dr-context-pipeline/scripts/install_pipeline.py --target "$WORKSPACE/context_pipeline"
ls -1 "$WORKSPACE/context_pipeline"
git -C "$WORKSPACE" diff -U20 AGENTS.md | cat
python3 ./skills/dr-context-pipeline/scripts/validate_pipeline.py --context-root "$WORKSPACE/context_pipeline"
python3 ./skills/dr-context-pipeline/scripts/memory_watchdog.py --freshness-minutes 240 --min-bytes 200
git -C "$WORKSPACE" status -sb context_pipeline AGENTS.md
echo "CONTEXT PIPELINE APPLY COMPLETE"
Paste every command’s output. If any step fails or the watchdog reports a gap, stop and reply
NOT EXECUTED: <reason>.
Apply to this workspace
When the user asks to
apply this skill (for example:
Apply dr-context-pipeline as default behavior), follow this exact order and paste the evidence for every step:
All commands assume you’ve set
WORKSPACE=${WORKSPACE:-~/.openclaw/workspace} and are running from that directory.
- 1. Lay down the files — run
python3 ./skills/dr-context-pipeline/scripts/install_pipeline.py --target context_pipeline (adds/updates the workspace copy from assets/context_pipeline/). Keep the script output in the transcript (hash summary + file count). - Show the tree —
ls -1 context_pipeline so the user sees which files are now present. - Patch
AGENTS.md — read the file, insert/refresh the “Context Pipeline” instructions, and include a git diff -U20 AGENTS.md (or equivalent) snippet in your reply. Preserve everything else. - Validate — run
python3 ./skills/dr-context-pipeline/scripts/validate_pipeline.py --context-root context_pipeline and paste the PASS/FAIL summary. If it fails, stop and report NOT EXECUTED with the error. - Run the memory watchdog —
python3 ./skills/dr-context-pipeline/scripts/memory_watchdog.py --freshness-minutes 240 --min-bytes 200 (tune as needed). Paste the JSON output; if status ≠ OK, stop and reply NOT EXECUTED: memory gap after quoting the issues. - Final state — show
git status -sb context_pipeline AGENTS.md (or git status -sb if cleaner) so the user can see what changed. - Success banner —
echo "CONTEXT PIPELINE APPLY COMPLETE" so the transcript clearly shows the run finished cleanly.
This apply flow must be idempotent: if the files already match and AGENTS.md already contains the section, the diff should be empty but you still run the installer + validator and show their outputs.
Memory commit / continue workflow
- - When Daniel says “memorize this” (or similar), run the checklist in
references/MEMORY_COMMIT.md (daily log, now, open-loops, topic file, MEMORY.md) and confirm which files changed. - When he says “let’s continue” after a reset, reload
memory/now.md, open-loops, and the relevant topic files so you can summarize where things left off before acting.
Runtime evidence contract (non-optional)
Every single task must follow the Runtime Evidence Checklist in
references/RUNTIME_CHECKLIST.md:
- - Emit the Retrieval Bundle JSON that conforms to
references/schemas/retrieval_bundle.schema.json. - Emit the Context Pack JSON that conforms to
references/schemas/context_pack.schema.json (or explicitly state the lint failure and fall back to raw snippets). - List which snippet IDs are being passed forward.
- Only then provide the user-facing reasoning/result.
- If any step fails, reply
NOT EXECUTED: <reason> and stop.
Casual prompts (“go for it”, “review it”, etc.) do not suspend this contract. If the user wants a lighter interaction they can explicitly waive it.
Operating procedure (default)
1) Load the always-on policy + topic catalog (your
memory/always_on.md).
2) Route the message deterministically (task type + caps) using
references/router.yml.
3) Retrieve top relevant snippets from your memory store; emit a
Retrieval Bundle JSON (see schema).
4) Compress Retrieval Bundle →
Context Pack JSON using
references/compressor_prompt.txt.
-
IMPORTANT: Context Pack
sources MUST be
snippet IDs only (
S1,
S2, …).
5) Lint the Context Pack. If lint fails,
skip compression and fall back to raw retrieved snippets.
6) Call the main reasoning model with: always-on policy header + Context Pack (+ raw snippets for high-stakes tasks) + user message.
What to read / use
- - Router + caps: INLINECODE33
- Compressor prompt: INLINECODE34
- Retrieval Bundle schema: INLINECODE35
- Context Pack schema: INLINECODE36
- Runtime checklist: INLINECODE37
- Golden tests starter suite: INLINECODE38
- Installer/validator/watchdog scripts:
scripts/install_pipeline.py, scripts/validate_pipeline.py, INLINECODE41
Notes
- - Keep “always-on policy header” tiny (invariants only). Put everything else behind retrieval.
- If you need deterministic snippet IDs, follow the stable ordering guidance in
references/deterministic_ids.md.
DR 上下文管道(检索 + 压缩 + 检查)
使用此技能标准化智能体将记忆加载到其提示中的方式,以确保正确性。
前置条件
- - 基于文件的记忆布局,包含 memory/always_on.md(策略头 + 主题目录)以及 memory/topics/ 下的主题文件。
- 推荐:安装 dr-memory-foundation(或实现等效结构)。
快速安装命令(复制/粘贴)
这些命令可在任意位置运行,因为它们设置了 $WORKSPACE(默认为 ~/.openclaw/workspace)。每当需要重新应用管道时,重新运行它们:
bash
export WORKSPACE=${WORKSPACE:-~/.openclaw/workspace}
cd $WORKSPACE
clawhub install dr-context-pipeline --version X.Y.Z --dir skills
python3 ./skills/dr-context-pipeline/scripts/install
pipeline.py --target $WORKSPACE/contextpipeline
ls -1 $WORKSPACE/context_pipeline
git -C $WORKSPACE diff -U20 AGENTS.md | cat
python3 ./skills/dr-context-pipeline/scripts/validate
pipeline.py --context-root $WORKSPACE/contextpipeline
python3 ./skills/dr-context-pipeline/scripts/memory_watchdog.py --freshness-minutes 240 --min-bytes 200
git -C $WORKSPACE status -sb context_pipeline AGENTS.md
echo 上下文管道应用完成
粘贴每个命令的输出。如果任何步骤失败或看门狗报告缺口,停止并回复 未执行:<原因>。
应用于此工作区
当用户要求
应用 此技能时(例如:将 dr-context-pipeline 设为默认行为),请按以下确切顺序操作,并粘贴每个步骤的证据:
所有命令均假设您已设置 WORKSPACE=${WORKSPACE:-~/.openclaw/workspace} 并从该目录运行。
- 1. 放置文件 — 运行 python3 ./skills/dr-context-pipeline/scripts/installpipeline.py --target contextpipeline(从 assets/contextpipeline/ 添加/更新工作区副本)。在记录中保留脚本输出(哈希摘要 + 文件计数)。
- 显示树结构 — ls -1 contextpipeline,以便用户查看现在存在的文件。
- 修补 AGENTS.md — 读取文件,插入/刷新“上下文管道”说明,并在回复中包含 git diff -U20 AGENTS.md(或等效内容)片段。保留其他所有内容。
- 验证 — 运行 python3 ./skills/dr-context-pipeline/scripts/validatepipeline.py --context-root contextpipeline 并粘贴通过/失败摘要。如果失败,停止并报告 未执行 及错误信息。
- 运行记忆看门狗 — python3 ./skills/dr-context-pipeline/scripts/memorywatchdog.py --freshness-minutes 240 --min-bytes 200(根据需要调整)。粘贴 JSON 输出;如果状态 ≠ 正常,在引用问题后停止并回复 未执行:记忆缺口。
- 最终状态 — 显示 git status -sb contextpipeline AGENTS.md(如果更清晰,可使用 git status -sb),以便用户查看更改内容。
- 成功横幅 — echo 上下文管道应用完成,以便记录清晰地显示运行已干净完成。
此应用流程必须是幂等的:如果文件已匹配且 AGENTS.md 已包含该部分,差异应为空,但您仍需运行安装程序和验证程序并显示其输出。
记忆提交/继续工作流
- - 当 Daniel 说“记住这个”(或类似内容)时,运行 references/MEMORY_COMMIT.md 中的检查清单(每日日志、当前状态、未完成任务、主题文件、MEMORY.md)并确认哪些文件已更改。
- 当他在重置后说“让我们继续”时,重新加载 memory/now.md、未完成任务 和相关主题文件,以便在行动前总结上次中断的位置。
运行时证据契约(非可选)
每个任务都必须遵循 references/RUNTIME_CHECKLIST.md 中的运行时证据检查清单:
- - 输出符合 references/schemas/retrievalbundle.schema.json 的 检索包 JSON。
- 输出符合 references/schemas/contextpack.schema.json 的 上下文包 JSON(或明确说明检查失败并回退到原始片段)。
- 列出哪些片段 ID 正在向前传递。
- 只有在此之后才提供面向用户的推理/结果。
- 如果任何步骤失败,回复 未执行:<原因> 并停止。
随意提示(“开始吧”、“审查它”等)不会暂停此契约。如果用户希望进行更轻量的交互,他们可以明确放弃。
操作流程(默认)
1) 加载始终在线策略 + 主题目录(您的 memory/always_on.md)。
2) 使用 references/router.yml 确定性地路由消息(任务类型 + 能力)。
3) 从您的记忆存储中检索最相关的片段;输出
检索包 JSON(参见模式)。
4) 使用 references/compressor_prompt.txt 将检索包压缩为 →
上下文包 JSON。
-
重要: 上下文包 sources 必须仅为
片段 ID(S1、S2、…)。
5) 检查上下文包。如果检查失败,
跳过压缩并回退到原始检索片段。
6) 使用以下内容调用主要推理模型:始终在线策略头 + 上下文包(+ 高风险任务的原始片段)+ 用户消息。
要阅读/使用的内容
- - 路由器 + 能力:references/router.yml
- 压缩器提示:references/compressorprompt.txt
- 检索包模式:references/schemas/retrievalbundle.schema.json
- 上下文包模式:references/schemas/contextpack.schema.json
- 运行时检查清单:references/RUNTIMECHECKLIST.md
- 黄金测试入门套件:references/tests/golden.json
- 安装程序/验证程序/看门狗脚本:scripts/installpipeline.py、scripts/validatepipeline.py、scripts/memory_watchdog.py
备注
- - 保持“始终在线策略头”简短(仅限不变项)。将所有其他内容放在检索之后。
- 如果需要确定性片段 ID,请遵循 references/deterministic_ids.md 中的稳定排序指南。