← Back to PRs

#15515: agents: add always mode for context pruning

by TsekaLuk open 2026-02-13 15:11 View on GitHub →
stale
## Summary - add `agents.defaults.contextPruning.mode: "always"` as a provider-agnostic mode - keep existing `cache-ttl` behavior unchanged (still Anthropic/OpenRouter Anthropic scoped) - wire the new mode through runtime settings, config types, and zod schema - document the new mode in session pruning + configuration reference + Pi docs ## Why `cache-ttl` is optimized for Anthropic cache semantics. For providers that do not share those semantics (for example MiniMax/OpenAI-compatible endpoints), operators still need steady context pressure control. `always` enables the same pruning logic on every request without changing `cache-ttl` defaults. ## Tests - `pnpm vitest src/agents/pi-extensions/context-pruning.test.ts src/config/config.pruning-defaults.test.ts --run` - `pnpm check` <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR introduces a new provider-agnostic context pruning mode (`agents.defaults.contextPruning.mode: "always"`) that runs the existing pruning logic before every LLM call, while keeping the existing `cache-ttl` behavior scoped to Anthropic/OpenRouter Anthropic. The change is wired through config types + zod schema, the embedded runner’s extension activation logic, and updated docs describing the new mode and its semantics (including `ttl` being ignored in always mode). <h3>Confidence Score: 4/5</h3> - This PR looks safe to merge after fixing a small test fixture mismatch. - Core runtime wiring for the new `always` mode is consistent (extension activates for always/cache-ttl, cache-ttl eligibility gating remains, and TTL checks run only in cache-ttl mode). The only issue found is in tests: the always-mode test passes `lastCacheTouchAt` even though production does not, which can hide regressions. - src/agents/pi-extensions/context-pruning.test.ts <sub>Last reviewed commit: 4b27cef</sub> <!-- greptile_other_comments_section --> <sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs