token-optimizer by d4kooo/openclaw-token-memory-optimizer
npx skills add https://github.com/d4kooo/openclaw-token-memory-optimizer --skill token-optimizer此技能提供程序性知识,帮助您保持 OpenClaw 实例的精简和高效。
| 问题 | 解决方案 |
|---|---|
| 后台任务导致上下文臃肿 | 定时任务隔离 (sessionTarget: "isolated") |
| 每轮对话都读取整个历史记录 | 使用 memory_search 进行本地 RAG |
| 上下文超过 10 万令牌 | 重置与总结协议 |
| 查找旧对话 | 会话记录索引 |
为防止后台任务使您的主要对话上下文变得臃肿,请始终将它们隔离运行。
openclaw.json 配置文件。cron.jobs 数组中,为任何不需要成为主聊天历史记录一部分的任务设置 。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
sessionTarget: "isolated"message 工具。{
"cron": {
"jobs": [
{
"name": "Background Check",
"schedule": { "kind": "every", "everyMs": 1800000 },
"sessionTarget": "isolated",
"payload": {
"kind": "agentTurn",
"message": "Check for updates. If found, use message tool to notify user.",
"deliver": true
}
}
]
}
}
sessionTarget: "isolated" 会在一个独立的临时会话中运行任务deliver: true 将结果发送回主频道当您的上下文使用量(可通过 📊 session_status 查看)超过 10 万令牌时,执行手动整合。
📊 session_status 查看当前令牌使用情况memory/YYYY-MM-DD.md 已更新了今天的事件openclaw gateway restart 以清除活动历史记录为了在不消耗令牌的情况下高效回忆,请配置本地嵌入。
openclaw.json){
"memorySearch": {
"embedding": {
"provider": "local",
"model": "hf:second-state/All-MiniLM-L6-v2-Embedding-GGUF"
},
"store": "sqlite",
"paths": ["memory/", "MEMORY.md"],
"extraPaths": []
}
}
使用 memory_search 从日志中检索上下文,而不是加载所有内容:
memory_search(query="what did we decide about the API design")
该工具会返回带有文件路径和行号的相关片段。使用 memory_get 来拉取特定部分。
为您的会话记录(.jsonl 文件)建立索引,以实现可搜索的对话历史。
OpenClaw 将会话记录存储在 ~/.openclaw/sessions/ 中。这些记录可以进行语义搜索索引,使您无需将它们加载到上下文中即可找到旧对话。
将会话记录路径添加到 memorySearch.extraPaths:
{
"memorySearch": {
"extraPaths": [
"~/.openclaw/sessions/*.jsonl"
]
}
}
将语义搜索与关键词匹配相结合,以实现更准确的检索。
| 搜索类型 | 优势 | 劣势 |
|---|---|---|
| 向量(语义) | 查找概念上相似的内容 | 可能错过确切术语 |
| BM25(关键词) | 查找精确匹配 | 错过同义词/转述 |
| 混合 | 两全其美 | 计算量稍大 |
当 memory_search 返回低置信度结果时:
OpenClaw 的 RAG 系统可能在未来的版本中支持原生混合搜索。目前,在需要高精度时,请运行多个查询。
openclaw.json 中已配置 memorySearch重启会清除会话历史记录,但是:
为 OpenClaw 社区构建。 🦦😸
每周安装量
248
代码仓库
GitHub 星标数
20
首次出现
2026年2月18日
安全审计
安装于
gemini-cli246
kimi-cli246
github-copilot246
amp246
cursor246
opencode246
This skill provides the procedural knowledge to keep your OpenClaw instance lean and efficient.
| Problem | Solution |
|---|---|
| Background tasks bloating context | Cron isolation (sessionTarget: "isolated") |
| Reading entire history every turn | Local RAG with memory_search |
| Context exceeds 100k tokens | Reset & Summarize protocol |
| Finding old conversations | Session transcript indexing |
To prevent background tasks from bloating your main conversation context, always isolate them.
openclaw.json config.cron.jobs array, set sessionTarget: "isolated" for any task that doesn't need to be part of the main chat history.message tool within the task's payload if human intervention is required.{
"cron": {
"jobs": [
{
"name": "Background Check",
"schedule": { "kind": "every", "everyMs": 1800000 },
"sessionTarget": "isolated",
"payload": {
"kind": "agentTurn",
"message": "Check for updates. If found, use message tool to notify user.",
"deliver": true
}
}
]
}
}
sessionTarget: "isolated" runs the task in a separate, transient sessiondeliver: true to send results back to the main channelWhen your context usage (visible via 📊 session_status) exceeds 100k tokens, perform a manual consolidation.
📊 session_status to see current token usagememory/YYYY-MM-DD.md is up to date with today's eventsopenclaw gateway restart to clear the active historyFor efficient recall without token burn, configure local embeddings.
openclaw.json){
"memorySearch": {
"embedding": {
"provider": "local",
"model": "hf:second-state/All-MiniLM-L6-v2-Embedding-GGUF"
},
"store": "sqlite",
"paths": ["memory/", "MEMORY.md"],
"extraPaths": []
}
}
Use memory_search to retrieve context from your logs instead of loading everything:
memory_search(query="what did we decide about the API design")
The tool returns relevant snippets with file paths and line numbers. Use memory_get to pull specific sections.
Index your session transcripts (.jsonl files) for searchable conversation history.
OpenClaw stores session transcripts in ~/.openclaw/sessions/. These can be indexed for semantic search, allowing you to find old conversations without loading them into context.
Add transcript paths to memorySearch.extraPaths:
{
"memorySearch": {
"extraPaths": [
"~/.openclaw/sessions/*.jsonl"
]
}
}
Combine semantic search with keyword matching for more accurate retrieval.
| Search Type | Strengths | Weaknesses |
|---|---|---|
| Vector (semantic) | Finds conceptually similar content | May miss exact terms |
| BM25 (keyword) | Finds exact matches | Misses synonyms/paraphrases |
| Hybrid | Best of both worlds | Slightly more compute |
When memory_search returns low-confidence results:
OpenClaw's RAG system may support native hybrid search in future versions. For now, run multiple queries when precision matters.
memorySearch is configured in openclaw.jsonThe restart clears the session history, but:
Built for the OpenClaw community. 🦦😸
Weekly Installs
248
Repository
GitHub Stars
20
First Seen
Feb 18, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli246
kimi-cli246
github-copilot246
amp246
cursor246
opencode246
AI Elements:基于shadcn/ui的AI原生应用组件库,快速构建对话界面
56,200 周安装