← 返回 Skills 市场
hasakyi

Session Memory Flush

作者 Kang Li · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
28
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install session-memory-flush
功能描述
在 OpenClaw session 即将因 idle/reset 释放前,扫描 `openclaw sessions --json` 可见会话,读取 transcript,提炼高价值上下文并写入 workspace memory 文件,降低新 session 的失忆感。用于 main、native subage...
使用说明 (SKILL.md)

session-memory-flush

目标

在 OpenClaw session 因 idle 自动释放前,读取当前 session transcript,优先调用 openclaw.jsonagents.defaults.model.primary 对应提供者做 LLM 摘要,并把值得后续继续工作的上下文写入短期记忆文件。

默认写入 ~/.openclaw/workspace/memory/YYYY-MM-DD.md;也可用 SESSION_MEMORY_OUTPUT_DIRopenclaw.json > sessionMemoryFlush.outputDir 覆盖输出目录。

能保证什么,不能保证什么

这个 skill 能保证的

  • 扫描 openclaw sessions --json 当前可见的 session
  • 在 transcript 可定位时,回收 main / native subagent / cron / dreaming 等 session 的摘要
  • 当前版本会按 session.agentId 感知 transcript 与模型配置,不再把所有 session 偷偷当成 main
  • 摘要写入 memory markdown,供共享同一 workspace / 同一记忆文件加载链路的新 session 继续读取

这个 skill 不能单独保证的

  • 不能保证不同 agentId 天然共享 builtin memory
  • OpenClaw builtin memory index 是 per-agent SQLite database,路径类似 ~/.openclaw/memory/\x3CagentId>.sqlite
  • 所以“其他 agent 也一样”是否成立,取决于它们是否共享:
    • 同一 workspace
    • 同一 memory/*.md 读取链路
    • 同一 memory search / index 配置范围
  • 如果是完全独立的 agentId / workspace,这个 skill 只能保证“成功 flush 到某个 memory 文件”,不能替 OpenClaw 保证“所有 agent 后续都会天然读到同一份记忆”

当前环境如何判断

如果 openclaw sessions --json 里看到的 session 都是同一个 agentId(比如全是 main),那你的实际运行效果通常可以近似理解为:

  • main session:可以受益
  • native subagent:通常也可以受益
  • dreaming / cron:只要 transcript 可见,也可以被回收

但这依然是因为它们实际落在同一个 agent scope,不是因为这个 skill 神奇地跨 agent 统一了 builtin memory。

不处理的场景

  • /new
  • /reset
  • 用户明确要求清空上下文

这些场景视为用户主动重置,不做旧会话回收。

处理的场景

  • 私聊超过 idle 阈值前
  • 群聊超过 idle 阈值前
  • 运维手动指定 sessionId 强制 flush

摘要输出格式

## YYYY-MM-DD HH:mm 会话摘要

来源:agent=\x3CagentId> / channel / type / sessionId=xxx

- 本轮目标:
- 已完成事项:
- 重要决策:
- 用户偏好:
- 待办事项:
- 风险和未完成上下文:

摘要规则

  • 不保留完整聊天原文
  • 不写临时寒暄
  • 只保留后续任务真正需要的信息
  • 单个 session 摘要控制在 300-800 字
  • 敏感信息按公司安全规则脱敏
  • 去重键按 agentId:sessionId 记录,避免不同 agent 误判为同一条 session
  • LLM 调用失败时,允许降级为本地规则摘要,保证任务不中断

运行方式

定时运行:

bash install.sh

默认行为不再写死在 skill 里,而是按下面顺序取值:

  1. 环境变量(最高优先级)
  2. openclaw.json > sessionMemoryFlush
  3. OpenClaw 自身的 openclaw.json > session.reset/session.resetByType
  4. 最后才回退到保底值

其中:

  • 私聊 idle 优先复用 session.resetByType.direct.idleMinutes
  • 群聊 idle 优先复用 session.resetByType.group.idleMinutes
  • 轮询频率优先读 sessionMemoryFlush.timerMinutes
  • scan window 优先读 sessionMemoryFlush.scanWindowMinutes

推荐在 openclaw.json 里显式加一段:

{
  "sessionMemoryFlush": {
    "timerMinutes": 1,
    "idleMinutes": {
      "direct": 5,
      "group": 30
    },
    "scanWindowMinutes": {
      "direct": 1,
      "group": 5
    },
    "outputDir": "$HOME/.openclaw/workspace/memory"
  }
}

仍可通过环境变量覆盖:

SESSION_MEMORY_TIMER_MINUTES=1 \
SESSION_MEMORY_DM_IDLE_MINUTES=5 \
SESSION_MEMORY_GROUP_IDLE_MINUTES=30 \
SESSION_MEMORY_SCAN_WINDOW_DM=1 \
SESSION_MEMORY_SCAN_WINDOW_GROUP=5 \
SESSION_MEMORY_OUTPUT_DIR="$HOME/.openclaw/workspace/memory" \
bash install.sh

如果什么都不传,install.sh 会直接读 ~/.openclaw/openclaw.json 生成 timer/service。

手动试跑:

python3 watcher.py --once --dry-run

强制处理指定 session:

python3 watcher.py --once --force-session \x3CsessionId>

交付建议

安全与隐私边界

  • 发布前应保持 state/flushed_sessions.json 为空状态:{"flushed_sessions": {}}
  • 不要随 skill 一起发布真实的 openclaw.json、session jsonl、memory markdown、SQLite 数据库、日志、缓存目录或任何本地运行产物。
  • 该 skill 会读取本机 OpenClaw session transcript,并优先使用当前用户 openclaw.json 中配置的模型提供商生成摘要;这意味着 transcript 可能会发送给用户自己配置的 LLM provider。
  • watcher.py 只在运行时读取本机 openclaw.json 或环境变量中的 API key 用于请求模型,不会把 API key 写入 state、memory markdown 或日志。
  • 如果部署环境不允许 transcript 出网,应通过内网模型、专用 SESSION_MEMORY_LLM_* 配置,或依赖本地规则摘要兜底。

如果要做成更稳的标准交付,建议把外部描述统一写成下面这句:

该 skill 会在 session 即将 idle/reset 释放前,把 transcript 摘要写入 memory 文件,降低后续新 session 的失忆感;它对当前 openclaw sessions --json 可见的 session 普遍适用,但不同 agentId 是否能共享后续记忆效果,仍取决于 workspace、memory 文件加载链路以及 builtin memory 的 per-agent 索引边界。

安全使用建议
Only install this if you are comfortable with automatic background summarization of OpenClaw transcripts. Prefer an internal or local LLM for sensitive work, review the memory output files, restrict the output directory, and disable or uninstall the timer when you no longer want continuous flushing.
功能分析
Type: OpenClaw Skill Name: session-memory-flush Version: 1.0.0 The session-memory-flush skill is a utility designed to summarize idle OpenClaw sessions and persist high-value context to a workspace memory file. The bundle includes an installation script (install.sh) that sets up a systemd user timer or crontab to run a Python watcher (watcher.py), which reads session transcripts and calls the user's configured LLM provider for summarization. The code follows standard practices, lacks obfuscation, and includes explicit security documentation regarding the handling of transcripts and API keys, ensuring data is only sent to the user's own configured endpoints.
能力标签
requires-sensitive-credentials
能力评估
Purpose & Capability
The behavior is coherent with the stated memory-flush purpose, but the purpose itself requires sensitive transcript access, model-provider use, and persistent memory writes.
Instruction Scope
The watcher scans visible sessions across agents and is intended to run automatically; the artifacts do not show per-session approval before transcript summarization or provider submission.
Install Mechanism
Registry metadata says there is no install spec and no required binaries, but SKILL.md instructs users to run install.sh, which requires python3/openclaw and installs a user-level systemd timer or cron job. This is disclosed and user-directed, but under-declared.
Credentials
The skill reads local OpenClaw transcripts and API-key-bearing configuration/environment variables, then may transmit transcript content to an LLM provider and write summaries into shared memory.
Persistence & Privilege
install.sh creates a recurring user-level timer or cron entry that continues processing sessions after installation; uninstall.sh is provided, but the default installed behavior is persistent background execution.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install session-memory-flush
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /session-memory-flush 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
- Initial release of session-memory-flush skill for OpenClaw. - Automatically scans active sessions before idle/reset, summarizes valuable transcript context, and writes it to workspace memory files. - Ensures recent context is available for new sessions within the same workspace, reducing context loss. - Supports main, native subagent, cron, and dreaming sessions; detects session agentId for proper processing. - Output directory and timing can be configured via environment variables or openclaw.json. - Summaries follow a structured markdown format; avoids redundant context across agents with distinct agentIds. - Sensitive data is sanitized per company policy, and fallback to local summarization is provided if LLM is unavailable.
元数据
Slug session-memory-flush
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Session Memory Flush 是什么?

在 OpenClaw session 即将因 idle/reset 释放前,扫描 `openclaw sessions --json` 可见会话,读取 transcript,提炼高价值上下文并写入 workspace memory 文件,降低新 session 的失忆感。用于 main、native subage... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 28 次。

如何安装 Session Memory Flush?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install session-memory-flush」即可一键安装,无需额外配置。

Session Memory Flush 是免费的吗?

是的,Session Memory Flush 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Session Memory Flush 支持哪些平台?

Session Memory Flush 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Session Memory Flush?

由 Kang Li(@hasakyi)开发并维护,当前版本 v1.0.0。

💬 留言讨论