VictorTaelin/OptMem
GitHub: VictorTaelin/OptMem
一个用 426 token prompt 加单个 Python 脚本为 AI agent 提供跨会话永久记忆的即插即用工具。
Stars: 686 | Forks: 36
# OptMem
为 AI agents 提供的永久记忆。包含一个 426-token 的 prompt、一个脚本,即插即用。

## 安装
```
curl -fsSL https://raw.githubusercontent.com/VictorTaelin/OptMem/main/install.sh | sh
```
它会打印出一个 `## Memory` 块。将其粘贴到你的 agent 的
`AGENTS.md`(或 `CLAUDE.md`)顶部,就大功告成了。再次运行同一行命令即可
更新。
该工具位于 `~/.optmem/memo`;将 `~/.optmem` 添加到 `PATH` 中即可直接输入 `memo`。
## 命令
| | |
|---|---|
| `memo wake` | 读取记忆 —— 每个会话的第一条命令 |
| `memo note "..."` | 记录一条记忆:单行,最多 280 个字符 |
| `memo nap` | 处理已到期的合并 |
| `memo recall ` | 逐字搜索以往记录的每一条记忆 |
| `memo zoom -
` | 将一个树节点展开为两部分 | | `memo forget-
` | 丢弃糟糕的摘要;下一次 nap 会重新构建它 | 合并任务会在 `note` 的输出中逐个出现。没有任何操作会在后台运行。 ## 文件 ``` ~/.optmem/ memo the tool: one file of Python 3, no dependencies memory/ LOG.txt every memory, one per line, append-only, never edited TREE/ the summaries: a cache, rebuildable from the log alone config the sizes, written by `memo config` ``` ``` memo config # show the sizes memo config WAKE_LINES=300 # how many lines wake prints (208 ≈ 16k tokens) memo config WAKE_LINES= # back to the default ``` `WAKE_LINES` 是唯一值得调整的大小参数,而且它是一个读取预算,而不是 存储预算:随时可以更改它,无论是调大还是调小,都不需要 重新计算。 记录是固定宽度的,因此位置*即是*标识,每次查询都只需一次 seek。在拥有一百万条记忆(608 MB)时,`wake` 仅需 0.03 秒。 设置 `$MEMORY_DIR` 可以将 `memory/` 存放在其他位置 —— 例如同步文件夹或 git repo。 ## Prompt 这是安装程序打印出的内容,也是全部的集成步骤。 ``` ## Memory Your memory is OptMem: - The tool is `~/.optmem/memo` - Your memories are in `~/.optmem/memory` OptMem outlives every session, compaction, model and vendor change. Without it you do not know who you are, or what was decided and tried. ### 启动时:激活 OptMem(强制) Run `~/.optmem/memo wake` before any other tool call, in every session, and then do exactly what it prints, to the end of its output. ### 工作时:注册 memory(强制) Call `~/.optmem/memo note "<1 line, max 280 chars>"` whenever you learn something new, or something worth keeping happens. That covers a task worth real effort, a fact or insight the user teaches you, anything you learn about their life (even indirectly), any event of lasting effect. Do not register redundant memories. If `~/.optmem/memo note` asks a compression: do it before your next action. Never edit or delete anything under `~/.optmem/memory`: the tool manages it. ### 当你需要旧的 memory 时:搜索或导航 `~/.optmem/memo recall` searches every memory, word for word.
Your memories also form a binary tree: #0-1, #2-3 ... exist as one-line
summaries, pairs of those as #0-3, and so on -- every `#a-b` line wake
prints is one node of it. `~/.optmem/memo zoom ` opens a node into its
two halves, down to the raw memories.
### 如果你是 subagent:跳过以上所有内容
Parallel sessions on this machine are all you, and may all write memories.
A subagent is not: it must never run `memo`, because it cannot judge what
is already known, and its notes would arrive duplicated and incorrectly.
When you spawn one, write: `You are a subagent. Don't run memo.`
```
标签:AI代理, Cutter, Python, SOC Prime, 人工智能, 开发工具, 无后门, 用户模式Hook绕过, 记忆系统