mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 09:10:46 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
92
openclaw/docs/concepts/session-pruning.md
Normal file
92
openclaw/docs/concepts/session-pruning.md
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
---
|
||||
title: "Session Pruning"
|
||||
summary: "Trimming old tool results to keep context lean and caching efficient"
|
||||
read_when:
|
||||
- You want to reduce context growth from tool outputs
|
||||
- You want to understand Anthropic prompt cache optimization
|
||||
---
|
||||
|
||||
# Session Pruning
|
||||
|
||||
Session pruning trims **old tool results** from the context before each LLM
|
||||
call. It reduces context bloat from accumulated tool outputs (exec results, file
|
||||
reads, search results) without rewriting normal conversation text.
|
||||
|
||||
<Info>
|
||||
Pruning is in-memory only -- it does not modify the on-disk session transcript.
|
||||
Your full history is always preserved.
|
||||
</Info>
|
||||
|
||||
## Why it matters
|
||||
|
||||
Long sessions accumulate tool output that inflates the context window. This
|
||||
increases cost and can force [compaction](/concepts/compaction) sooner than
|
||||
necessary.
|
||||
|
||||
Pruning is especially valuable for **Anthropic prompt caching**. After the cache
|
||||
TTL expires, the next request re-caches the full prompt. Pruning reduces the
|
||||
cache-write size, directly lowering cost.
|
||||
|
||||
## How it works
|
||||
|
||||
1. Wait for the cache TTL to expire (default 5 minutes).
|
||||
2. Find old tool results for normal pruning (conversation text is left alone).
|
||||
3. **Soft-trim** oversized results -- keep the head and tail, insert `...`.
|
||||
4. **Hard-clear** the rest -- replace with a placeholder.
|
||||
5. Reset the TTL so follow-up requests reuse the fresh cache.
|
||||
|
||||
## Legacy image cleanup
|
||||
|
||||
OpenClaw also runs a separate idempotent cleanup for older legacy sessions that
|
||||
persisted raw image blocks in history.
|
||||
|
||||
- It preserves the **3 most recent completed turns** byte-for-byte so prompt
|
||||
cache prefixes for recent follow-ups stay stable.
|
||||
- Older already-processed image blocks in `user` or `toolResult` history can be
|
||||
replaced with `[image data removed - already processed by model]`.
|
||||
- This is separate from normal cache-TTL pruning. It exists to stop repeated
|
||||
image payloads from busting prompt caches on later turns.
|
||||
|
||||
## Smart defaults
|
||||
|
||||
OpenClaw auto-enables pruning for Anthropic profiles:
|
||||
|
||||
| Profile type | Pruning enabled | Heartbeat |
|
||||
| ------------------------------------------------------- | --------------- | --------- |
|
||||
| Anthropic OAuth/token auth (including Claude CLI reuse) | Yes | 1 hour |
|
||||
| API key | Yes | 30 min |
|
||||
|
||||
If you set explicit values, OpenClaw does not override them.
|
||||
|
||||
## Enable or disable
|
||||
|
||||
Pruning is off by default for non-Anthropic providers. To enable:
|
||||
|
||||
```json5
|
||||
{
|
||||
agents: {
|
||||
defaults: {
|
||||
contextPruning: { mode: "cache-ttl", ttl: "5m" },
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
To disable: set `mode: "off"`.
|
||||
|
||||
## Pruning vs compaction
|
||||
|
||||
| | Pruning | Compaction |
|
||||
| ---------- | ------------------ | ----------------------- |
|
||||
| **What** | Trims tool results | Summarizes conversation |
|
||||
| **Saved?** | No (per-request) | Yes (in transcript) |
|
||||
| **Scope** | Tool results only | Entire conversation |
|
||||
|
||||
They complement each other -- pruning keeps tool output lean between
|
||||
compaction cycles.
|
||||
|
||||
## Further reading
|
||||
|
||||
- [Compaction](/concepts/compaction) -- summarization-based context reduction
|
||||
- [Gateway Configuration](/gateway/configuration) -- all pruning config knobs
|
||||
(`contextPruning.*`)
|
||||
Loading…
Add table
Add a link
Reference in a new issue