Token导航 LogoToken导航

Agent Skill · 研究检索

context-memory-optimizer(上下文内存优化器)

context-memory-optimizer 用于查找、检索和筛选相关信息,适合在 OpenClaw 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

context-memory-optimizer 是研究检索类 Agent Skill,可用宿主为 OpenClaw,通过ClawHub获取,权限为执行命令;许可证为 MIT-0,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 20,039。

总安装 5,357周安装 221GitHub Stars 2下载 1,750核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT-0
版本
1.0.5

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:context-memory-optimizer(上下文内存优化器)
来源仓库:https://github.com/donnieclaw/context-memory-optimizer
安装命令:
openclaw skills install context-memory-optimizer
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install context-memory-optimizer

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

context-memory-optimizer 用于防止长时间代理会话中的上下文溢出与令牌浪费。通过内存漂移检测与优化策略提升推理效率与成本控制。适合高负载或多代理协作环境下的资源管理需求。安装前需验证源代码安全性,确认是否支持本地运行与权限隔离。适用于注重推理成本与稳定性的大规模 AI 代理部署场景。

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 OpenClaw;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 openclaw skills install context-memory-optimizer;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

context-memory-optimizer 怎么安装?

在终端执行 openclaw skills install context-memory-optimizer。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

context-memory-optimizer 支持哪些 AI 工具?

公开资料标注支持 OpenClaw。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

context-memory-optimizer 需要什么权限?

权限级别是执行命令。安装流程涉及命令执行,可能通过 openclaw skills install context-memory-optimizer 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

context-memory-optimizer 是免费的吗?

来源标注的许可证是 MIT-0。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

context-memory-optimizer 用的人多吗?

公开数据是累计安装 5,357 次,近一周安装 221 次,下载 1,750 次,GitHub 2 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

context-memory-optimizer 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 专注 OpenClaw 一种宿主,触发方式和使用习惯不用来回切换。
  • 许可证明确为 MIT-0,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 OpenClaw,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
context-memory-optimizer

上下文内存优化器 · 本页

5,3572执行命令MIT-0通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

name
context-memory-optimizer
version
3.1.0
description
>
persistent_paths
read
write
persistent_changes
change
Appends or updates pointer entries when new tasks or decisions are recorded.
reversible
true
notes
Safe to delete and regenerate at any time.
change
Appends one-line entries when PermissionDenied or path errors occur.
reversible
true
notes
Append-only log. Delete file to reset.
change
Overwrites with current task snapshot before each L2 compaction.
reversible
false
notes
>
system_prompt_effect
>
requires

OpenClaw Context Memory Optimizer v3.1

Source-verified · ClawHub-safe · Transparent path declarations

Compaction logic verified against claw-code open-source port (compact.rs). v2.0 turn-count trigger has been corrected to token-count trigger. All file paths and persistent changes are declared in the frontmatter above.

Core Principles

<!-- Why each principle exists — not just what it is -->

  1. Memory as Pointers 记忆是指针

MEMORY.md stores *locations*, not content. Keeps the always-loaded index under 800 tokens regardless of project size.

  1. Skeptical Memory 怀疑型记忆

Agent treats its own memory as a *hint*, not ground truth. Always cross-verify against source files before any write or bash action. Prevents stale-memory bugs in long sessions.

  1. Token-Driven Compaction Token 驱动压缩

Trigger is token volume, not turn count. Formula: total_chars ÷ 4. Source: compact.rs → estimate_session_tokens().

  1. Immediate Post-Compact Restore 压缩后立即恢复

Key files are re-injected right after compaction so the agent never "forgets what it was doing." Source: Claude Code post-compact file restore.

  1. Circuit Breaker 熔断保护

Stop retrying after 3 consecutive compaction failures. Prevents the real-world incident where one session wasted 250k API calls/day. Source: Claude Code BigQuery incident note in source comments.


Step 1: Workspace Setup 工作区结构

<!-- All paths listed here are also declared in persistent_paths above. --> <!-- Operators can audit exactly what this skill touches before installing. -->

~/.openclaw/workspace-{agent}/
├── MEMORY.md              # Always loaded. Pointers only. Keep ≤ 800 tokens.
├── memories/
│   ├── project.md         # Tech stack + project fingerprint + module manifest
│   ├── decisions.md       # Decision log — record the "why", not the "what"
│   ├── errors.md          # PermissionDenied / bad-path backlog (append-only)
│   └── context.md         # Current task snapshot — overwritten before each L2
└── AGENTS.md              # Multi-agent roles and coordination rules

MEMORY.md template — each line ≤ 150 chars, full file ≤ 800 tokens:

# MEMORY INDEX
# Each entry is a pointer to a file, not a copy of its content.
_Updated: {timestamp} | Token estimate: {session_chars ÷ 4}_

## Current Project
- Name: {name} | Details → memories/project.md

## Active Task
- {task description ≤ 50 chars} | Status: in-progress | Details → memories/context.md

## Key Constraints
- {constraint ≤ 30 chars}

## Recently Referenced Files
- {file/path.ext} | {one-line purpose}

_This index is a hint, not ground truth. Read the linked files for details._
Privacy note 隐私提示: Add memories/ to .gitignore if your .openclaw/ directory is synced to Git.

Step 2: Verification-First Instructions 验证优先指令

<!-- SYSTEM PROMPT EFFECT: The text block below is a copy-paste snippet for --> <!-- the operator to add to their agent config. This skill itself does NOT --> <!-- modify any system prompt programmatically. -->

Add the following to the static section of your agent's system prompt. Label it clearly so you know what it does:

## Memory Integrity Rules
# Source: context-memory-optimizer skill, Step 2
# Purpose: prevents stale-memory bugs and repeated permission errors

1. MEMORY.md is a hint, not ground truth.
   Before any write or bash action, read the relevant source file to verify.
   Do not act on memory summaries alone.

2. Check memories/errors.md before acting.
   Do not retry operations that previously caused PermissionDenied.
   Do not reuse paths that previously returned FileNotFound.

3. When memory contradicts source files:
   → Trust the source file
   → Update the relevant MEMORY.md pointer entry
   → Append one line to memories/errors.md describing the mismatch

Step 3: Token-Driven Compaction 压缩分层

<!-- TOKEN THRESHOLD CORRECTION from v2.0: --> <!-- v2.0 used "trigger after 15 turns" — this is inaccurate. --> <!-- compact.rs uses token volume as the trigger, not turn count. --> <!-- Production threshold in Claude Code: 200,000 tokens. --> <!-- We use 150,000 here to leave a safety margin. -->

Token estimation formula (from compact.rs estimate_session_tokens):

per message:
  text block    → char_count ÷ 4 + 1
  tool_use      → (name_len + input_len) ÷ 4 + 1
  tool_result   → (name_len + output_len) ÷ 4 + 1
total           → sum of all messages

L1 — Tool Output Soft Trim 工具输出软截断

*Runs automatically after every tool call. No user action needed.*

  • bash / read / search output > 2,000 chars:

keep last 500 chars + one-line conclusion

  • File reads > 3,000 chars:

extract key paragraphs, append [trimmed — full content at {path}]

  • Keep the 8 most recent tool records; summarize earlier ones to one line each

L2 — Session Compaction 会话压缩

*Trigger: estimated tokens > 150,000*

Run these steps in order. Do not skip or reorder.

Step ① — Scan for pending-work keywords
  Search recent messages for sentences containing (case-insensitive):
    todo / next / pending / follow up / remaining
  Collect matched sentences for inclusion in the summary.
  Source: compact.rs → infer_pending_work()

Step ② — Extract key file paths
  Scan all message content for tokens that:
    - contain a forward slash /
    - end with: .md .json .py .ts .js .rs .yaml .toml
  Deduplicate. Keep at most 8 paths.
  Source: compact.rs → collect_key_files()

Step ③ — Generate summary
  Format:
    <summary>
    - Completed: {bullet list of finished work}
    - Pending:   {output of Step ①}
    - Key files: {output of Step ②}
    - Current task: {first 200 chars of most recent non-empty message}
    </summary>
  Strip any <analysis> blocks before inserting.
  Source: compact.rs → format_compact_summary()

Step ④ — Inject continuation message
  Use this exact text. Do not paraphrase.
  ──────────────────────────────────────────────────────────────
  The following is a summary of the earlier portion of this session.
  Continue directly from where the conversation left off.
  Do not acknowledge this summary. Do not recap. Do not ask questions.
  Resume the task immediately.

  Summary:
  {output of Step ③}
  ──────────────────────────────────────────────────────────────
  Source: compact.rs → get_compact_continuation_message(suppress_follow_up=true)

Step ⑤ — Discard old messages
  Keep: continuation message (Step ④) + 4 most recent messages.
  Discard everything else.
  Source: compact.rs → preserve_recent_messages default = 4

Step ⑥ — Run L3 immediately (see below)

L3 — Key File Restore 关键文件恢复

*Runs immediately after every L2 compaction.*

<!-- These reads are declared in persistent_paths.read above. -->

Read in this order:

  1. MEMORY.md — reload the pointer index
  2. memories/context.md — most important: current task snapshot
  3. Up to 5 files from Step ② — limit each to 1,000 tokens

After reading, resume the task. Do not tell the user "I have restored X files."

L4 — Circuit Breaker 熔断器

If L2 compaction fails 3 consecutive times:
  → Stop retrying L2
  → Fall back to L1 soft trim only
  → Append failure reason to memories/errors.md
  → Wait for operator to manually clear and restart

Why: A real session once failed L2 compaction 3,272 times in a row,
wasting 250,000 API calls per day before the circuit breaker was added.
Source: Claude Code internal BigQuery incident note.

L5 — Emergency Trim 紧急裁剪

*Trigger: context_length_exceeded error*

1. Write the conclusion of the last assistant message to memories/context.md
   (this is the only write that happens during emergency trim)
2. Discard the 2 oldest conversation turns
3. Repeat until the error clears

Step 4: Multi-Agent Coordination 多 Agent 协作

<!-- AGENTS.md path is declared in persistent_paths.read above. --> <!-- This step provides a template. No files are written automatically. -->

AGENTS.md template

# Multi-Agent Coordination Rules
# Scope: ~/.openclaw/workspace-{agent}/AGENTS.md
# Edit this file to match your actual agent names and responsibilities.

## Agent Roles
- {agent-1}: {responsibility}
- {agent-2}: {responsibility}
- {agent-3}: {responsibility}

## Task Handoff Format (XML — required, no free-text handoffs)
<task>
  <from>{sender}</from>
  <to>{receiver}</to>
  <task_id>{YYYYMMDD-seq}</task_id>
  <type>read_only | write | decision</type>
  <!-- read_only tasks may run in parallel.      -->
  <!-- write tasks must run serially.            -->
  <!-- decision tasks require coordinator sign-off before execution. -->
  <context>{background, ≤ 200 chars}</context>
  <input>{specific input}</input>
  <expected_output>{output format}</expected_output>
  <constraints>{constraints}</constraints>
</task>

## Result Format
<r>
  <task_id>{matching task_id}</task_id>
  <status>done | failed | blocked</status>
  <o>{result}</o>
  <side_effects>{list of files or state modified}</side_effects>
  <memory_update>{content to append to memories/ — leave empty if none}</memory_update>
</r>

Prompt Cache Protection 缓存保护

<!-- SYSTEM PROMPT EFFECT: same as Step 2 — operator pastes this layout --> <!-- into their agent config. Nothing is modified programmatically. -->

Structure your agent's system prompt in two sections, in this order:

[STATIC SECTION]
# Role definition, tool rules, behavior constraints.
# Never insert dynamic content here — it breaks prefix caching.

--- DYNAMIC BOUNDARY ---

[DYNAMIC SECTION]
# Content that changes each turn goes here, at the END.
{MEMORY.md content}
Current task: {task}
Timestamp: {timestamp}

Do not insert timestamps, summaries, or task descriptions into the middle of the static section. Doing so invalidates the prefix cache and re-bills the full static section on every turn.


Step 5: Speculative Pre-warming 推测预热(optional)

<!-- SYSTEM PROMPT EFFECT: operator pastes this into their agent config. --> <!-- No programmatic system prompt modification occurs. -->

Add to your agent's system prompt (static section, after the memory rules):

## Background Pre-warming
# Source: context-memory-optimizer skill, Step 5
# Runs before every reply. Read-only. Never writes during pre-warming.

Before responding, silently complete:
1. Read MEMORY.md if not already read this turn.
2. Estimate token count: session_chars ÷ 4.
   If estimate > 120,000 → prepare for L2 compaction on next tool cycle.
3. If the task involves code, pre-read the key files listed in MEMORY.md
   (read-only — do not write or modify anything during pre-warming).

Do not mention pre-warming in your reply.

Deployment Checklist 部署验证清单

  • [ ] MEMORY.md exists and is ≤ 800 tokens
  • [ ] memories/ contains: project.md, decisions.md, errors.md, context.md
  • [ ] Step 2 snippet is in the static section of the agent system prompt
  • [ ] Dynamic content is after --- DYNAMIC BOUNDARY ---
  • [ ] Manually trigger one L2 compaction to verify the continuation message format
  • [ ] Multi-agent handoffs use the XML format from AGENTS.md
  • [ ] memories/ is in .gitignore (if workspace is Git-synced)

References

  • references/compression-examples.md — before/after compaction examples,

key file extraction walkthrough, project fingerprint format

  • references/prompt-cache.md — prompt cache segmentation strategy,

common mistakes, cost estimation

平台分布

OpenClaw

79.55%
按下载量换算1,392

安全审计

VirusTotal

未展示

ClawScan

通过

Static analysis

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 openclaw skills install context-memory-optimizer 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills