v1.3.114
v1.3.114
Tool-Result Clearing — Proactive Context Management
Implemented the "tool-result clearing" context engineering technique (Anthropic, 2025-2026). Before triggering expensive LLM-based compaction, the agent now mechanically replaces old re-fetchable tool outputs with short placeholders.
How it works
When token count reaches 75% of the compaction threshold, ClearOldToolResults walks through old messages and replaces large tool_result outputs (read_file, grep, search_files, etc.) with short placeholders like [cleared: output was 5000 chars — re-run tool to see full result], keeping the 6 most recent results intact.
This often delays or entirely avoids the need for full LLM-based compaction — saving an API call and preserving more conversation context.
Safety properties
- Only touches
tool_resultOutput — never user messages, assistant reasoning, ortool_userecords - Skips error results (kept visible for debugging)
- Skips small results under 500 chars (not worth the overhead)
- Idempotent: safe to call multiple times
- If clearing doesn't free enough tokens, falls through to normal compaction
Files changed
internal/context/manager.go—ClearOldToolResults(keepN int) intmethodinternal/agent/agent_precompact.go— integration intoStartPreCompact()internal/context/manager_test.go— 6 tests covering all edge cases