Add `idle_seconds` to `ClearToolResults` to clear old tool results once the prompt cache has expired
Adds an opt-in idle_seconds trigger to ClearToolResults. When the history's last model response is at least that many seconds old, the capability clears old tool results before the next request, just as it does when a size trigger fires.
- No linked issue: found while auditing converge-ai-labs/agent-foundation against the harness. Its
ColdStartFilterCapability(a13n_harness/filters/cold_start.py) is the first item on the "what to copy" list in our 2026-09-16 notes write-up of a13n-harness.
Why
ClearToolResults already documents the cache tradeoff: clearing rewrites history, so the next request pays a cache write. When a conversation resumes after a pause longer than the provider's prompt-cache lifetime (Anthropic's default is 5 minutes; OpenAI's in-memory cache lasts 5 to 10), that request re-writes the cache anyway. Clearing at that moment costs no cache hit, and it shrinks every later request in the resumed thread. So it's the one moment where clearing is free.
Behavior
ClearToolResults(idle_seconds=3600, keep_pairs=3), which can combine withmax_messages/max_tokens/max_fraction. Any trigger firing clears. Everything else (keep_pairs,exclude_tools,clear_tool_inputs,min_clear_tokens, spans, receipts) is unchanged.- It clears once. The compacted history persists (existing
before_model_requestbehavior), and the response to that request is fresh, so later requests in the thread don't trigger it again. - A naive
ModelResponse.timestamp(hand-built history) is read as UTC. A history with no response doesn't trigger. - It defaults to
None, so existing users see no change. The only visible difference is that the "no trigger"ValueErrornow listsidle_secondsamong the options.0, negative,infandnanare rejected.
Tests
These are in tests/harness/compaction/test_compaction.py: validation; stale vs fresh vs naive timestamps; no response in history; and an Agent + FunctionModel round trip that resumes a stale history, checks the model saw the cleared result, and checks the clear persisted into the next run.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (none)
- PR title is fit for the release changelog.