← Back to PRs

#12425: feat(core): Native Token Optimization Defaults (Pruning, Compaction, Cache & Local Search)

by oneles open 2026-02-09 07:21 View on GitHub →
agents stale
## Description\nThis PR moves core token optimization strategies directly into the configuration defaults layer. By enforcing these settings natively, OpenClaw becomes significantly more cost-efficient out-of-the-box without requiring manual user configuration.\n\n## Core Optimizations:\n1. **Aggressive Context Pruning**: Default mode set to `cache-ttl` with a 5m TTL and 0.5 hard-clear ratio.\n2. **Enhanced Compaction**: Default `reserveTokensFloor` set to 20,000 and enabled `memoryFlush` (memory persistence) by default.\n3. **Optimized Cache Retention**: Default heartbeat set to 55m and enforced Anthropic `cacheRetention: "long"` to maximize prompt caching benefits.\n4. **Local Memory Search**: Default `memorySearch.provider` to `local` to eliminate remote embedding API costs.\n\nThese defaults ensure a better balance between cost and performance for all users. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates `src/config/defaults.ts` to enforce more aggressive “token optimization” defaults in the config layer: context pruning defaults (`cache-ttl` with 5m TTL + trim ratios), a fixed 55m heartbeat interval, defaulting memory search to local, and switching Anthropic model `cacheRetention` defaults from `short` to `long`. It also extends compaction defaults to force `mode: "safeguard"`, enable `memoryFlush`, and raise `reserveTokensFloor`. These changes run as part of config normalization in `src/config/io.ts`, so they affect every config load (including the empty-config bootstrap path). <h3>Confidence Score: 3/5</h3> - This PR is likely mergeable but has a real config-merging bug that can silently drop memorySearch settings. - Most changes are straightforward default tweaks, but the `memorySearch` defaulting logic currently spreads `defaults.memorySearch` where `defaults` is the agent defaults object, causing existing `agents.defaults.memorySearch` fields to be lost when provider is defaulted. The rest is behavior changes that need confirmation (heartbeat/auth-mode coupling). - src/config/defaults.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs