mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Three coordinated things:
1. Resolve the committed upstream/main merge conflicts. 94 files were
sitting with raw <<<<<<< HEAD ... >>>>>>> upstream/main blocks. Every
conflict had HanzoBot/Bot on HEAD and OpenClaw on upstream. Resolved
by keeping HEAD everywhere — 540 conflict blocks.
2. Rewrite remaining OpenClaw text refs.
OPENCLAW → HANZO_BOT
OpenClaw → HanzoBot (PascalCase type identifiers)
openclaw → bot (codebase convention — botToken,
botUsername etc.; avoids invalid
hyphenated JS identifiers)
openclaw[_]/openclaw[A-Z] → bot[_]/bot[A-Z] (compound)
ai.openclaw.x → ai.hanzo.bot.x (JVM package path)
3. Delete or rename openclaw-named file paths (116 of them). Dead
duplicates with a Bot-named canonical from the partial migration:
deleted. Otherwise renamed.
ai/openclaw/** → deleted (ai/hanzo/bot/** canonical)
Sources/OpenClaw*/ → deleted (Sources/Bot* canonical)
Tests/OpenClawIPCTests/ → deleted (Tests/BotIPCTests canonical)
OpenClawKit/ → deleted (BotKit canonical)
openclaw-tools.*.ts → deleted (bot-tools.*.ts canonical)
openclaw-root.ts etc. → deleted (bot-root.ts canonical)
types.openclaw.ts → deleted (types.bot.ts canonical)
extensions/*/openclaw.plugin.json → renamed hanzo-bot.plugin.json
docs/start/openclaw.md → renamed hanzo-bot.md (+ zh-CN)
docs/assets/openclaw-*.png, whatsapp-openclaw*.jpg → deleted
scripts/.../openclaw-* → deleted (bot/hanzo-bot parallels)
openclaw.mjs → deleted (hanzo-bot.mjs is package.bin)
Then patched 65 broken JS/TS import strings where hanzo-bot had ended
up inside an import path ('./types.hanzo-bot.js' → './types.bot.js'
etc., since the on-disk filename uses the brand-neutral bot- prefix).
Pre-existing lint debt cleaned up to get oxlint --type-aware to 0/0:
removed the dead i18n test that referenced a path no longer existing;
defined the missing DIDConfig and WalletConfig types in types.base.ts
(they were imported but never declared); dropped unused imports;
collapsed redundant type assertion and a tautological meta.bot lookup
that the openclaw→bot rename made redundant.
The a2ui.bundle.js generated artifact is kept at its pre-rebrand
contents — it gets regenerated by 'pnpm canvas:a2ui:bundle' from
sources I cannot rebuild in this commit; the source side is clean.
Verified: 0 occurrences of openclaw (case-insensitive) in tree source
content, 0 file or directory paths with openclaw in the name; oxlint
--type-aware src test reports 0/0.
4.4 KiB
4.4 KiB
read_when, summary, x-i18n
| read_when | summary | x-i18n | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
会话剪枝:工具结果修剪以减少上下文膨胀 |
|
会话剪枝
会话剪枝在每次 LLM 调用之前从内存上下文中修剪旧的工具结果。它不会重写磁盘上的会话历史(*.jsonl)。
运行时机
- 当启用
mode: "cache-ttl"且该会话的最后一次 Anthropic 调用早于ttl时。 - 仅影响该请求发送给模型的消息。
- 仅对 Anthropic API 调用(和 OpenRouter Anthropic 模型)生效。
- 为获得最佳效果,请将
ttl与你的模型cacheControlTtl匹配。 - 剪枝后,TTL 窗口会重置,因此后续请求会保持缓存直到
ttl再次过期。
智能默认值(Anthropic)
- OAuth 或 setup-token 配置文件:启用
cache-ttl剪枝并将心跳设置为1h。 - API 密钥配置文件:启用
cache-ttl剪枝,将心跳设置为30m,并将 Anthropic 模型的cacheControlTtl默认为1h。 - 如果你显式设置了这些值中的任何一个,HanzoBot 不会覆盖它们。
改进内容(成本 + 缓存行为)
- 为什么要剪枝: Anthropic 提示缓存仅在 TTL 内适用。如果会话空闲超过 TTL,下一个请求会重新缓存完整提示,除非你先修剪它。
- 什么变得更便宜: 剪枝减少了 TTL 过期后第一个请求的 cacheWrite 大小。
- 为什么 TTL 重置很重要: 一旦剪枝运行,缓存窗口会重置,因此后续请求可以重用新缓存的提示,而不是再次重新缓存完整历史。
- 它不做什么: 剪枝不会添加 token 或"双倍"成本;它只改变该 TTL 后第一个请求缓存的内容。
可以剪枝的内容
- 仅
toolResult消息。 - 用户 + 助手消息永远不会被修改。
- 最后
keepLastAssistants条助手消息受保护;该截止点之后的工具结果不会被剪枝。 - 如果没有足够的助手消息来确定截止点,则跳过剪枝。
- 包含图像块的工具结果会被跳过(永不修剪/清除)。
上下文窗口估算
剪枝使用估算的上下文窗口(字符 ≈ token × 4)。基础窗口按以下顺序解析:
models.providers.*.models[].contextWindow覆盖。- 模型定义
contextWindow(来自模型注册表)。 - 默认
200000token。
如果设置了 agents.defaults.contextTokens,它将被视为解析窗口的上限(最小值)。
模式
cache-ttl
- 仅当最后一次 Anthropic 调用早于
ttl(默认5m)时才运行剪枝。 - 运行时:与之前相同的软修剪 + 硬清除行为。
软剪枝 vs 硬剪枝
- 软修剪:仅用于过大的工具结果。
- 保留头部 + 尾部,插入
...,并附加一个包含原始大小的注释。 - 跳过包含图像块的结果。
- 保留头部 + 尾部,插入
- 硬清除:用
hardClear.placeholder替换整个工具结果。
工具选择
tools.allow/tools.deny支持*通配符。- 拒绝优先。
- 匹配不区分大小写。
- 允许列表为空 => 允许所有工具。
与其他限制的交互
- 内置工具已经截断自己的输出;会话剪枝是一个额外的层,防止长时间运行的聊天在模型上下文中累积过多的工具输出。
- 压缩是独立的:压缩进行总结并持久化,剪枝是每个请求的临时操作。参阅 /concepts/compaction。
默认值(启用时)
ttl:"5m"keepLastAssistants:3softTrimRatio:0.3hardClearRatio:0.5minPrunableToolChars:50000softTrim:{ maxChars: 4000, headChars: 1500, tailChars: 1500 }hardClear:{ enabled: true, placeholder: "[Old tool result content cleared]" }
示例
默认(关闭):
{
agent: {
contextPruning: { mode: "off" },
},
}
启用 TTL 感知剪枝:
{
agent: {
contextPruning: { mode: "cache-ttl", ttl: "5m" },
},
}
限制剪枝到特定工具:
{
agent: {
contextPruning: {
mode: "cache-ttl",
tools: { allow: ["exec", "read"], deny: ["*image*"] },
},
},
}
参阅配置参考:Gateway 网关配置