agent: Add agent.compaction_model setting for context compaction - #60012
Merged
bennetbo merged 6 commits intoJul 24, 2026
Merged
Conversation
- Add compaction_model support across registry, thread, UI, and settings - Resolve compaction model with fallback to the thread model; warn if unresolved - Use the compaction_model for telemetry and for compaction requests - Propagate compaction_model through settings and UI
agent.compaction_model setting for context compaction
mdz-axo
added a commit
to mdz-axo/zed-kask
that referenced
this pull request
Jul 25, 2026
Upstream changes (zed-industries/zed main, 27 commits): - agent: Add agent.compaction_model setting for context compaction (zed-industries#60012) - agent: Show effort selector for anthropic compatible providers (zed-industries#61579) - acp: Update agent-client-protocol SDK to 2.0.0 (zed-industries#61570) - client: Extract proxy handshakes into new proxy_handshake crate (zed-industries#61427) - collab: Fix multiworkspace location out of sync bugs (zed-industries#61598) - editor: Fix sticky header drag cancels autoscroll (zed-industries#53592) - editor: Fix crash when copying and pasting using multiple cursors (zed-industries#61545) - editor: Skip untitled buffers when saving a multi-buffer (zed-industries#61380) - gpui: Fix images not being drawn with rounded corners with ObjectFit::Cover (zed-industries#61383) - gpui: Fix deadlock in performance profiler and reenable it (zed-industries#61584) - git_ui: Prevent Git panel bindings in repository selector (zed-industries#61282) - language_model: Add explicit OpenAI conversation compaction and fix Anthropic compaction (zed-industries#61370) - markdown: Fix squashed Mermaid diagrams in markdown preview (zed-industries#61260) - Opus 5 BYOK Support (zed-industries#61596) - repl: Show add-cell controls in empty notebooks (zed-industries#61329) - search: Escape seeded buffer search query in regex mode (zed-industries#57748) - settings: Fix VS Code import appending duplicate file associations (zed-industries#61355) - settings: Split VSCode and Zed keymap files (zed-industries#61532) - Treat blank spawn_agent session IDs as absent (zed-industries#60893) - worktree: Reload git state when a watcher rescan covers a repository (zed-industries#61541) - Plus 7 more minor fixes. Merge fixes: - crates/agent/src/thread.rs: replay_tool_call used 'message_ix' (undefined) after auto-merge; renamed to 'owning_message_ix' (the parameter name). - Cargo.toml: Removed stale workspace members hkask-wallet and hkask-git-cas (both directories deleted in prior commits but workspace entries remained). - kask/crates/hkask-regulation/src/wallet_manager.rs: Stubbed consume() and settle_rjoules() on WalletBudgetPort — these were API-key encumbrance operations from the deleted hkask-wallet crate; regulation tracks per-agent gas balances, not per-key encumbrances. - kask/crates/hkask-regulation/src/wallet_gas_calibrator.rs: Fixed test to use crate::agent_wallet_store::WalletStore instead of hkask_storage::WalletStore. - kask/crates/hkask-regulation/Cargo.toml: Added tokio macros feature to dev-dependencies for #[tokio::test]. - kask/crates/kask_bridge/Cargo.toml: Added futures dependency (needed by context_injector.rs for futures::executor::block_on). - kask/crates/kask_bridge/src/context_injector.rs: Fixed futures_util::executor to futures::executor (futures-util doesn't include executor module). Release Notes: - N/A
9 tasks
0arm
pushed a commit
to 0arm/zed
that referenced
this pull request
Jul 26, 2026
…ed-industries#60012) # Objective Add a new `agent.compaction_model` setting that lets users specify a separate language model for context compaction (`/compact` and auto-compaction), independent of the thread's active conversation model. Compaction is just summarization — there's no reason to pay Opus prices for it when a cheaper model does the job faster. We've also seen reasoning models misbehave on this task (empty responses, repetition loops at high effort), so picking a dedicated non-reasoning model for compaction is useful. ## Solution - New `compaction_model: Option<LanguageModelSelection>` field in `AgentSettingsContent` and `AgentSettings`, mirroring `thread_summary_model`. - New `compaction_model: Option<ConfiguredModel>` slot on `LanguageModelRegistry` with `select_/set_/compaction_model()` trio, mirroring the existing pattern. The setter deliberately does **not** emit a registry event in v1; callers read the slot lazily at compaction time. - New `Thread::compaction_model(&self, cx: &App)` helper that returns the configured model or falls back to `self.model()`. Two call sites — `Thread::compact` and `perform_compaction_if_needed` — now go through this helper instead of reading `self.model()` directly. - `build_compaction_telemetry` accepts the compaction model explicitly so the `model` field reflects the model that actually streamed the request. `max_tokens` still derives from `thread.model()` (threshold semantics are unchanged). - Documentation updated at `docs/src/ai/agent-settings.md` (new user-facing setting). **Example:** ```json { "agent": { "default_model": { "provider": "anthropic", "model": "claude-opus-4-6" }, "compaction_model": { "provider": "anthropic", "model": "claude-sonnet-4-5" } } } ``` **Resolution chain:** ``` agent.compaction_model (if set & available) → thread.model() (always available, current behavior) ``` **Behavior change:** | Trigger | Before | After | | --- | --- | --- | | Manual `/compact` | Uses `thread.model()` | Uses `agent.compaction_model` if set & available; else `thread.model()` | | Auto-compaction | Uses `thread.model()` | Same as above | | `/compact` when thread has no model | `NoModelConfiguredError` | Succeeds if `compaction_model` resolves | | `compaction_model` configured but provider missing / model id unknown | n/a | Falls back to `thread.model()` and logs a one-time warning | **Explicit non-goals:** - No `Event::CompactionModelChanged`(no consumer; the `_cx` parameter on `set_compaction_model` is intentionally accepted for future use). - No GUI selector (consistent with all other feature-specific models). - No per-profile override. - No runtime API-error fallback — only config-time failure (provider not registered, model id not in `provided_models`) triggers fallback. This matches every other feature-specific model. - No change to threshold calculation, auto-compact trigger, or `COMPACTION_PROMPT`. - No propagation to subagent threads. ## Testing 3 new unit tests in `crates/agent/src/thread.rs::tests`: - `test_compaction_uses_configured_compaction_model` — manual `/compact` routes to the configured model; thread's primary model receives no request; telemetry reflects the configured model. - `test_compaction_falls_back_when_compaction_model_unavailable` — configured-but-unresolvable falls back to `thread.model()`; telemetry reflects the fallback model. - `test_auto_compaction_uses_compaction_model` — auto-compaction triggered by threshold honors the same setting. All 14 existing compaction tests still pass. Test suites in `crates/agent_settings`, `crates/language_model`, `crates/settings_content`, `crates/agent_ui` unchanged. `cargo clippy` clean on the changed crates. **How reviewers can test:** 1. Add `agent.compaction_model` to `settings.json` with a cheaper model than the thread's primary model, run `/compact`, observe the cheaper model receives the request. 2. Set `agent.compaction_model` to a non-existent provider/model id, run `/compact`, observe fallback to thread model and a `log::warn!` line. 3. Trigger auto-compaction by reaching the threshold, observe it uses `compaction_model`. **Platforms tested:** local Linux (cargo check + cargo test on agent / agent_settings / language_model / settings_content / agent_ui crates). ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments — no `unsafe` blocks introduced - [x] The content adheres to Zed's UI standards — N/A: settings-only change, no UI touched - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable — model resolution is an O(1) registry lookup, not on any hot path; no new work in the streaming loop Release Notes: - agent: Add support for specifying which model is used for compaction (`agent.compaction_model`) --------- Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de> Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
…ed-industries#60012) # Objective Add a new `agent.compaction_model` setting that lets users specify a separate language model for context compaction (`/compact` and auto-compaction), independent of the thread's active conversation model. Compaction is just summarization — there's no reason to pay Opus prices for it when a cheaper model does the job faster. We've also seen reasoning models misbehave on this task (empty responses, repetition loops at high effort), so picking a dedicated non-reasoning model for compaction is useful. ## Solution - New `compaction_model: Option<LanguageModelSelection>` field in `AgentSettingsContent` and `AgentSettings`, mirroring `thread_summary_model`. - New `compaction_model: Option<ConfiguredModel>` slot on `LanguageModelRegistry` with `select_/set_/compaction_model()` trio, mirroring the existing pattern. The setter deliberately does **not** emit a registry event in v1; callers read the slot lazily at compaction time. - New `Thread::compaction_model(&self, cx: &App)` helper that returns the configured model or falls back to `self.model()`. Two call sites — `Thread::compact` and `perform_compaction_if_needed` — now go through this helper instead of reading `self.model()` directly. - `build_compaction_telemetry` accepts the compaction model explicitly so the `model` field reflects the model that actually streamed the request. `max_tokens` still derives from `thread.model()` (threshold semantics are unchanged). - Documentation updated at `docs/src/ai/agent-settings.md` (new user-facing setting). **Example:** ```json { "agent": { "default_model": { "provider": "anthropic", "model": "claude-opus-4-6" }, "compaction_model": { "provider": "anthropic", "model": "claude-sonnet-4-5" } } } ``` **Resolution chain:** ``` agent.compaction_model (if set & available) → thread.model() (always available, current behavior) ``` **Behavior change:** | Trigger | Before | After | | --- | --- | --- | | Manual `/compact` | Uses `thread.model()` | Uses `agent.compaction_model` if set & available; else `thread.model()` | | Auto-compaction | Uses `thread.model()` | Same as above | | `/compact` when thread has no model | `NoModelConfiguredError` | Succeeds if `compaction_model` resolves | | `compaction_model` configured but provider missing / model id unknown | n/a | Falls back to `thread.model()` and logs a one-time warning | **Explicit non-goals:** - No `Event::CompactionModelChanged`(no consumer; the `_cx` parameter on `set_compaction_model` is intentionally accepted for future use). - No GUI selector (consistent with all other feature-specific models). - No per-profile override. - No runtime API-error fallback — only config-time failure (provider not registered, model id not in `provided_models`) triggers fallback. This matches every other feature-specific model. - No change to threshold calculation, auto-compact trigger, or `COMPACTION_PROMPT`. - No propagation to subagent threads. ## Testing 3 new unit tests in `crates/agent/src/thread.rs::tests`: - `test_compaction_uses_configured_compaction_model` — manual `/compact` routes to the configured model; thread's primary model receives no request; telemetry reflects the configured model. - `test_compaction_falls_back_when_compaction_model_unavailable` — configured-but-unresolvable falls back to `thread.model()`; telemetry reflects the fallback model. - `test_auto_compaction_uses_compaction_model` — auto-compaction triggered by threshold honors the same setting. All 14 existing compaction tests still pass. Test suites in `crates/agent_settings`, `crates/language_model`, `crates/settings_content`, `crates/agent_ui` unchanged. `cargo clippy` clean on the changed crates. **How reviewers can test:** 1. Add `agent.compaction_model` to `settings.json` with a cheaper model than the thread's primary model, run `/compact`, observe the cheaper model receives the request. 2. Set `agent.compaction_model` to a non-existent provider/model id, run `/compact`, observe fallback to thread model and a `log::warn!` line. 3. Trigger auto-compaction by reaching the threshold, observe it uses `compaction_model`. **Platforms tested:** local Linux (cargo check + cargo test on agent / agent_settings / language_model / settings_content / agent_ui crates). ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments — no `unsafe` blocks introduced - [x] The content adheres to Zed's UI standards — N/A: settings-only change, no UI touched - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable — model resolution is an O(1) registry lookup, not on any hot path; no new work in the streaming loop Release Notes: - agent: Add support for specifying which model is used for compaction (`agent.compaction_model`) --------- Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de> Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
playdohface
pushed a commit
to playdohface/zed
that referenced
this pull request
Aug 29, 2026
…ed-industries#60012) # Objective Add a new `agent.compaction_model` setting that lets users specify a separate language model for context compaction (`/compact` and auto-compaction), independent of the thread's active conversation model. Compaction is just summarization — there's no reason to pay Opus prices for it when a cheaper model does the job faster. We've also seen reasoning models misbehave on this task (empty responses, repetition loops at high effort), so picking a dedicated non-reasoning model for compaction is useful. ## Solution - New `compaction_model: Option<LanguageModelSelection>` field in `AgentSettingsContent` and `AgentSettings`, mirroring `thread_summary_model`. - New `compaction_model: Option<ConfiguredModel>` slot on `LanguageModelRegistry` with `select_/set_/compaction_model()` trio, mirroring the existing pattern. The setter deliberately does **not** emit a registry event in v1; callers read the slot lazily at compaction time. - New `Thread::compaction_model(&self, cx: &App)` helper that returns the configured model or falls back to `self.model()`. Two call sites — `Thread::compact` and `perform_compaction_if_needed` — now go through this helper instead of reading `self.model()` directly. - `build_compaction_telemetry` accepts the compaction model explicitly so the `model` field reflects the model that actually streamed the request. `max_tokens` still derives from `thread.model()` (threshold semantics are unchanged). - Documentation updated at `docs/src/ai/agent-settings.md` (new user-facing setting). **Example:** ```json { "agent": { "default_model": { "provider": "anthropic", "model": "claude-opus-4-6" }, "compaction_model": { "provider": "anthropic", "model": "claude-sonnet-4-5" } } } ``` **Resolution chain:** ``` agent.compaction_model (if set & available) → thread.model() (always available, current behavior) ``` **Behavior change:** | Trigger | Before | After | | --- | --- | --- | | Manual `/compact` | Uses `thread.model()` | Uses `agent.compaction_model` if set & available; else `thread.model()` | | Auto-compaction | Uses `thread.model()` | Same as above | | `/compact` when thread has no model | `NoModelConfiguredError` | Succeeds if `compaction_model` resolves | | `compaction_model` configured but provider missing / model id unknown | n/a | Falls back to `thread.model()` and logs a one-time warning | **Explicit non-goals:** - No `Event::CompactionModelChanged`(no consumer; the `_cx` parameter on `set_compaction_model` is intentionally accepted for future use). - No GUI selector (consistent with all other feature-specific models). - No per-profile override. - No runtime API-error fallback — only config-time failure (provider not registered, model id not in `provided_models`) triggers fallback. This matches every other feature-specific model. - No change to threshold calculation, auto-compact trigger, or `COMPACTION_PROMPT`. - No propagation to subagent threads. ## Testing 3 new unit tests in `crates/agent/src/thread.rs::tests`: - `test_compaction_uses_configured_compaction_model` — manual `/compact` routes to the configured model; thread's primary model receives no request; telemetry reflects the configured model. - `test_compaction_falls_back_when_compaction_model_unavailable` — configured-but-unresolvable falls back to `thread.model()`; telemetry reflects the fallback model. - `test_auto_compaction_uses_compaction_model` — auto-compaction triggered by threshold honors the same setting. All 14 existing compaction tests still pass. Test suites in `crates/agent_settings`, `crates/language_model`, `crates/settings_content`, `crates/agent_ui` unchanged. `cargo clippy` clean on the changed crates. **How reviewers can test:** 1. Add `agent.compaction_model` to `settings.json` with a cheaper model than the thread's primary model, run `/compact`, observe the cheaper model receives the request. 2. Set `agent.compaction_model` to a non-existent provider/model id, run `/compact`, observe fallback to thread model and a `log::warn!` line. 3. Trigger auto-compaction by reaching the threshold, observe it uses `compaction_model`. **Platforms tested:** local Linux (cargo check + cargo test on agent / agent_settings / language_model / settings_content / agent_ui crates). ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments — no `unsafe` blocks introduced - [x] The content adheres to Zed's UI standards — N/A: settings-only change, no UI touched - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable — model resolution is an O(1) registry lookup, not on any hot path; no new work in the streaming loop Release Notes: - agent: Add support for specifying which model is used for compaction (`agent.compaction_model`) --------- Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de> Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
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.
Objective
Add a new
agent.compaction_modelsetting that lets users specify a separate language model for context compaction (/compactand auto-compaction), independent of the thread's active conversation model.Compaction is just summarization — there's no reason to pay Opus prices for it when a cheaper model does the job faster. We've also seen reasoning models misbehave on this task (empty responses, repetition
loops at high effort), so picking a dedicated non-reasoning model for compaction is useful.
Solution
compaction_model: Option<LanguageModelSelection>field inAgentSettingsContentandAgentSettings, mirroringthread_summary_model.compaction_model: Option<ConfiguredModel>slot onLanguageModelRegistrywithselect_/set_/compaction_model()trio, mirroring the existing pattern. The setter deliberately does not emit a registry event in v1; callers read the slot lazily at compaction time.Thread::compaction_model(&self, cx: &App)helper that returns the configured model or falls back toself.model(). Two call sites —Thread::compactandperform_compaction_if_needed— now go through this helper instead of readingself.model()directly.build_compaction_telemetryaccepts the compaction model explicitly so themodelfield reflects the model that actually streamed the request.max_tokensstill derives fromthread.model()(threshold semantics are unchanged).docs/src/ai/agent-settings.md(new user-facing setting).Example:
{ "agent": { "default_model": { "provider": "anthropic", "model": "claude-opus-4-6" }, "compaction_model": { "provider": "anthropic", "model": "claude-sonnet-4-5" } } }Resolution chain:
Behavior change:
/compactthread.model()agent.compaction_modelif set & available; elsethread.model()thread.model()/compactwhen thread has no modelNoModelConfiguredErrorcompaction_modelresolvescompaction_modelconfigured but provider missing / model id unknownthread.model()and logs a one-time warningExplicit non-goals:
Event::CompactionModelChanged(no consumer; the_cxparameter onset_compaction_modelis intentionally accepted for future use).provided_models) triggers fallback. This matches every other feature-specific model.COMPACTION_PROMPT.Testing
3 new unit tests in
crates/agent/src/thread.rs::tests:test_compaction_uses_configured_compaction_model— manual/compactroutes to the configured model; thread's primary model receives no request; telemetry reflects the configured model.test_compaction_falls_back_when_compaction_model_unavailable— configured-but-unresolvable falls back tothread.model(); telemetry reflects the fallback model.test_auto_compaction_uses_compaction_model— auto-compaction triggered by threshold honors the same setting.All 14 existing compaction tests still pass. Test suites in
crates/agent_settings,crates/language_model,crates/settings_content,crates/agent_uiunchanged.cargo clippyclean on the changed crates.How reviewers can test:
agent.compaction_modeltosettings.jsonwith a cheaper model than the thread's primary model, run/compact, observe the cheaper model receives the request.agent.compaction_modelto a non-existent provider/model id, run/compact, observe fallback to thread model and alog::warn!line.compaction_model.Platforms tested: local Linux (cargo check + cargo test on agent / agent_settings / language_model / settings_content / agent_ui crates).
Self-Review Checklist:
unsafeblocks introducedRelease Notes:
agent.compaction_model)