$ ssh clawdbot.space --loading...
$ ssh clawdbot.space --loading...
掌握 Token 预算管理,让你的代理更快、更准、更省钱。
每个 LLM 都有上下文窗口限制。当代理超出限制时,响应质量下降——幻觉增加、指令被遗忘、成本飙升。本指南教你像专家一样管理上下文:保留什么、压缩什么、卸载什么。
上下文中的每个 Token 在每次 API 调用时都要花钱。膨胀的 100K 上下文按 $15/M Token = 每次请求 $1.50。
LLM 在无关上下文中表现更差。研究表明,上下文中充满无关信息时准确率下降 20-30%。
更大的上下文 = 更慢的响应。首 Token 延迟与上下文大小成正比。
| Component | Tokens | Priority | Notes |
|---|---|---|---|
| SOUL.md | ~500-2K | 始终加载 | 代理身份和核心指令。保持简洁。 |
| AGENTS.md | ~300-1K | 始终加载 | 角色定义。多代理时增长。 |
| memory.md | ~1K-10K | 始终加载 | 膨胀的最大元凶。必须主动管理。 |
| 活跃对话 | ~2K-50K | 动态 | 当前聊天历史。通过滑动窗口自动管理。 |
| 工具结果 | ~1K-20K | 每次调用 | 网页抓取、文件读取、搜索结果。可能迅速膨胀。 |
每周审查 memory.md。删除过时事实、合并重复项、将结构化数据移至 SQLite。目标:低于 2K Token。
openclaw memory status # 检查当前 Token 数
不是所有内容都需要始终在上下文中。使用 @include 指令根据当前任务条件加载。
# 在 SOUL.md 中: @include(coding-rules.md) when task.type == 'code' @include(writing-style.md) when task.type == 'write'
网页抓取可能 10K+ Token。使用内置总结器在注入上下文前压缩结果。
openclaw config set tools.web.summarize true openclaw config set tools.web.max_tokens 2000
限制多少条之前的消息保留在上下文中。旧消息自动被总结。
openclaw config set context.sliding_window 20 openclaw config set context.summary_after 10
大型知识库使用 SQLite 或向量数据库。按需查询而非全部保留在上下文中。
openclaw memory index --to sqlite
| Component | Budget | Tip |
|---|---|---|
| SOUL.md | 800 | 最多一页。每个词都要有存在的意义。 |
| AGENTS.md | 500 | 简短角色描述。详情放在单独文件。 |
| memory.md | 1,500 | 只保留前 30 个事实。结构化数据→SQLite。 |
| 对话历史 | 8,000 | 20 条消息滑动窗口 + 自动总结。 |
| 工具结果 | 3,000 | 总结所有网页/文件结果。限制每工具输出。 |
| 响应预留 | 4,000 | 始终为模型思考和响应留出空间。 |