Repository navigation
feat: add per-agent compaction and context pruning overrides - #19329
curtismercier wants to merge 9 commits into
Conversation
bb79cf0 to
95334cd
Compare
coolmanns
left a comment
There was a problem hiding this comment.
This is exactly what we need. Running 14 agents across Opus 4.6, Sonnet 4.6, and Haiku heartbeats — all sharing one global compaction config today. Per-agent overrides would let us tune reserveTokensFloor for Haiku heartbeats, disable memoryFlush on utility agents, and give coding agents more history share. 👍 from a real multi-agent deployment.
|
👍 This is exactly what we need. Running 14 agents across Opus 4.6, Sonnet 4.6, and Haiku heartbeats — all sharing one global compaction config today. Per-agent overrides would let us tune |
8f23872 to
1490494
Compare
|
Rebased onto latest upstream/main (v2026.2.17) — no conflicts, all 38 tests passing, build clean. Also submitted a small formatting fix in #19659 found during the rebase. |
- Remove dead code in buildContextPruningExtension (redundant null check after mode guard) - Widen per-agent contextPruning type to include ttl and keepLastAssistants - Update Zod schema for AgentEntrySchema contextPruning accordingly - Use named AgentContextPruningConfig type for resolveAgentContextPruning return
a4d47dc to
12e52d9
Compare
|
+1 👍 Great step with per-agent compaction/context pruning. This will help immediately; looking forward to per-agent contextTokens next. |
|
One additional ask: it would be great to extend this pattern to support context limits per provider/model (or per-agent model profile), not only compaction/pruning. In mixed-model stacks this would let us tune context budgets cleanly (e.g., Codex vs GPT-5 vs Claude) without global cap tradeoffs. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
PR: Per-agent compaction and context pruning overrides
Title
feat: add per-agent compaction and context pruning overrides
Body
Summary
Adds per-agent
compactionandcontextPruningconfiguration toagents.list[]entries, allowing different agents to use different compaction behavior. Currently, all agents share the same globalagents.defaults.compactionsettings — this is a significant gap when running agents on models with different context windows or when agents have fundamentally different session lifetimes.Motivation
A multi-agent setup might include:
reserveTokensFloorto preserve more working contextToday, all of these agents share identical compaction behavior. This PR lets each agent override:
compaction.mode—"default","safeguard", or"off"(new)compaction.reserveTokensFloor— per-agent token reservecompaction.maxHistoryShare— per-agent history share limitcompaction.memoryFlush— per-agent flush prompt, system prompt, threshold, and enabled flagcontextPruning— per-agent pruning mode, TTL, and keepLastAssistantsExample config
What changed
Schema & types (commit 1):
CompactionSchemafromzod-schema.agent-defaults.tsintozod-schema.agent-runtime.tsfor reusecompactionandcontextPruningfields toAgentEntrySchema"off"toAgentCompactionModetypeResolvers (commit 2):
resolveAgentCompaction(cfg, agentId?)— deep merges per-agent overrides with global defaults;memoryFlushsub-object is shallow-merged one level deeper so partial overrides don't wipe sibling fieldsresolveAgentContextPruning(cfg, agentId?)— merges per-agent context pruning with global defaultsisCompactionEnabled(cfg, agentId?)— guard helper that encapsulates themode !== "off"checkCallsite wiring (commit 3, 6 files):
compact.ts— skipsensurePiCompactionReserveTokenswhen mode is"off"attempt.ts— same skip logic for run attemptsextensions.ts— uses resolved per-agent config for both compaction mode and context pruningpi-settings.ts—resolveCompactionReserveTokensFloornow takes optionalagentIdmemory-flush.ts—resolveMemoryFlushSettingsuses per-agent compaction config; returnsnullwhen mode is"off"agent-runner-memory.ts— extractsagentIdfrom session key and passes it throughTests (commit 4):
Review feedback (commit 5):
buildContextPruningExtensioncontextPruningtype to includettlandkeepLastAssistantsAgentContextPruningConfigtype instead of inline return typeIntegration tested
Tested on a live gateway with a dedicated test agent (
claude-haiku-4-5, 200k context):reserveTokensFloor: 80000mode: "off"Breaking changes
None. All new fields are optional. Agents without per-agent overrides behave exactly as before (global defaults apply).
Checklist
mode: "off"support with guard helperGreptile Summary
Adds per-agent
compactionandcontextPruningconfiguration overrides toagents.list[]entries, enabling different agents to use different compaction behaviors. The implementation introduces a new"off"mode for compaction, along with resolver functions that deep-merge per-agent settings with global defaults.Key changes:
CompactionSchemafor reuse betweenAgentDefaultsSchemaandAgentEntrySchemaresolveAgentCompaction(),resolveAgentContextPruning(), andisCompactionEnabled()helpers with proper deep-merge semantics formemoryFlushsub-objectcompact.ts,attempt.ts,extensions.ts,pi-settings.ts,memory-flush.ts,agent-runner-memory.ts)mode: "off"behavior)agent-scope.test.tsThe implementation follows the existing pattern for per-agent model overrides and maintains backward compatibility - all new fields are optional and default to global settings when not specified.
Confidence Score: 5/5
mode: "off"feature is correctly guarded at every integration point. All changes maintain backward compatibility.Last reviewed commit: 0a2dce7
(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!
Closes #13736
Closes #17735
Relates to #16546 (this PR adds per-agent compaction; contextTokens override is a separate concern)