长会话防膨胀:两层截断 + excludeFromContext,把工具大输出变成可控上下文
场景:exec/web_fetch/read 返回超长文本导致上下文膨胀、压缩失败或响应变慢。前置:可调整工具参数并允许保存产物文件。步骤:先给工具输出设硬上限,再对会话持久化做 head+tail 裁剪,对超长结果使用 excludeFromContext 只保留预览。关键配置:safeLimit/excludeFromContext。验证:长任务后上下文大小稳定且不会触发 compaction 失败。风险:截断过度会丢排障细节,需保留原始产物。
GITHUBDiscovered 2026-02-15Author ProgramCaiCai
Prerequisites
- You run long sessions with heavy tool outputs (exec/read/web_fetch/browser).
- You can update tool usage strategy and keep artifact files for full logs.
Steps
- Identify top context bloat sources by checking sessions that frequently hit slowdowns/compaction warnings.
- Apply hard output caps (byte/line) at tool emission time for noisy commands/pages.
- For long outputs, use `excludeFromContext` and store full content as artifacts while keeping only previews in history.
- Set/verify session history `safeLimit` and keep head+tail segments to preserve key diagnostics.
- Run the same long workflow again and compare latency and failure rate.
Commands
openclaw gateway statusopenclaw helpopenclaw gateway restartVerify
After repeated long tool calls, replies remain stable and no context-compaction failure appears.
Caveats
- Always retain a retrievable raw artifact path; preview-only context is not enough for deep debugging.
- Exact truncation thresholds are environment-dependent and should be tuned with real workload(需验证).
Source attribution
This tip is aggregated from community/public sources and preserved with attribution.
Open original source ↗