Skip to content

v1.3.114

Choose a tag to compare

@topcheer topcheer released this 03 Jul 20:59
· 4106 commits to main since this release

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_result Output — never user messages, assistant reasoning, or tool_use records
  • 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.goClearOldToolResults(keepN int) int method
  • internal/agent/agent_precompact.go — integration into StartPreCompact()
  • internal/context/manager_test.go — 6 tests covering all edge cases