feat(config): make the auto-compaction threshold configurable (compaction_threshold)#3448
Merged
Merged
Conversation
Replace the hardcoded contextThreshold constant in pkg/compaction with an exported DefaultThreshold and thread the threshold value through ShouldCompact. Add a compaction_threshold config key (range (0, 1], default 0.9) on agents, with a per-model override next to compaction_model; the model-level value takes precedence. Surface an explicit session_compaction knob on agents that disables the proactive threshold trigger and the post-overflow auto-recovery while keeping manual /compact available. Closes #3433
dgageot
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3433
Summary
The proactive auto-compaction trigger was a hardcoded
contextThreshold = 0.9constant inpkg/compaction. It is now configurable through a newcompaction_thresholdconfig key (per agent, with a per-model override), and an explicitsession_compactionon/off knob is surfaced in YAML. Behavior is unchanged unless the new keys are set.Issue expectations vs implementation
compaction_thresholdkey, range0 < x <= 1, default0.9AgentConfig.CompactionThreshold *float64, validated at config load (validateCompactionThreshold); default lives incompaction.DefaultThresholdcompaction_modelModelConfig.CompactionThreshold;compactionThresholdForAgentin teamloader mirrorsgetCompactionModelForAgent(first of the agent's models that sets it wins, agent value is the fallback)session_compaction: falseknob mapping toWithSessionCompactionsemanticsAgentConfig.SessionCompaction *bool(tri-state, default on) wired to a newagent.WithSessionCompaction; runtime gates automatic triggers onr.sessionCompaction && a.SessionCompaction()ShouldCompactShouldCompact(..., threshold float64); values outside(0, 1](including 0 for "not configured") fall back toDefaultThresholdloop.go),compactIfNeeded(loop.go), post-overflow recovery (loop_steps.go)pkg/config/latest+ schema + examplelatest/types.go+latest/validate.goonly (v0 to v11 untouched),agent-schema.json, newexamples/compaction_threshold.yamlcompaction_trigger_test.goTestCompactIfNeeded_CustomThreshold(3 subcases) andTestCompactIfNeeded_AgentSessionCompactionDisabledValue flow
Behavior notes
agents.<name>/models.<name>contextfirst_availablecombined withcompaction_thresholdcompaction_model/title_modelsession_compaction: false/compactstill workscompaction_modelcompaction_threshold: 1*float64(strict goccy decoding verified)Validation
go build ./...,go vetgolangci-lint run+go run ./lint .Docs updated:
docs/configuration/agents/index.md,docs/configuration/models/index.md, new exampleexamples/compaction_threshold.yaml.