# 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>
7.9 KiB
title, description
| title | description |
|---|---|
| Agent Settings - Zed | Map the AI settings pages to Zed AI setup for LLM providers, External Agents, MCP servers, and related settings. |
Agent Settings
Agent Settings live in the AI section of the Settings Editor, which configures model providers, External Agents, and MCP servers. Open it with {#action agent::OpenSettings} (also available from the top-right menu in the Agent Panel), which takes you straight to the AI page. You can also reach the same page with {#action zed::OpenSettings} and selecting AI in the sidebar.
Within the AI page, LLM Providers, External Agents, and MCP Servers each open as their own sub-page under the General section.
| Surface | Opens with | Use it for |
|---|---|---|
| Settings Editor | {#action agent::OpenSettings} | AI settings: LLM providers, External Agents, MCP servers, and related pages |
| Settings file | {#action zed::OpenSettingsFile} | Direct JSON edits and settings not exposed in UI |
For general settings mechanics, see Configuring Zed.
LLM Providers
The LLM Providers section configures model providers for Zed AI features, including Zed Agent, Inline Assistant, Git commit generation, thread summaries, and similar model-backed features.
Use this section to:
- sign in to supported subscription-backed providers
- enter provider API keys
- add OpenAI-compatible providers
- remove providers
For the model-access paths and provider-specific setup, see LLM Providers.
Feature-Specific Settings
Some Zed AI features have their own model or prompt settings in settings.json, including:
agent.inline_assistant_modelagent.commit_message_modelagent.thread_summary_modelagent.compaction_modelagent.subagent_modelagent.commit_message_instructionsagent.inline_alternatives
Use agent.commit_message_instructions for instructions that apply only to generated Git commit messages:
{
"agent": {
"commit_message_instructions": "Use the Conventional Commits format: <type>(<scope>): <description>."
}
}
For feature-specific model examples, see Feature-specific Models.
Automatic Compaction
Zed Agent can automatically compact long threads before they reach the selected model's context window. Compaction summarizes earlier messages and keeps the conversation usable without starting a new thread.
Automatic compaction is enabled by default and runs when the thread reaches 90% of the model's context window. You can change the threshold or disable automatic compaction in settings.json:
{
"agent": {
"auto_compact": {
"enabled": true,
"threshold": "90%"
}
}
}
The threshold value can be one of:
| Value | Meaning |
|---|---|
Percentage string, like 90% |
Compact when the thread uses that percentage of the model's context window. |
Positive integer, like 100000 |
Compact after that many tokens have been used. |
Negative integer, like -20000 |
Compact once fewer than that many tokens remain in the model's context window. |
0 is not a valid threshold. If the threshold is invalid, Zed falls back to 90%.
You can compact a Zed Agent thread manually at any time by typing /compact in the Agent Panel message editor. For more on thread token usage and compaction behavior, see Token Usage and Compaction.
Compaction Model
By default, context compaction (both /compact and auto-compaction) uses the thread's currently selected model. Set agent.compaction_model to use a different model:
{
"agent": {
"default_model": {
"provider": "anthropic",
"model": "claude-opus-4-6"
},
"compaction_model": {
"provider": "anthropic",
"model": "claude-sonnet-4-5"
}
}
}
Notes:
- The configured model should have a context window at least as large as the thread's primary model for predictable behavior.
External Agents
The External Agents section configures ACP-integrated agents.
Use Add Agent to:
Install from RegistryAdd Custom Agent
For setup details and support boundaries, see External Agents.
MCP Servers
The MCP Servers page configures Model Context Protocol servers connected to Zed.
Use Add Server (in the page header) to:
Add Local ServerAdd Remote ServerInstall from Extensions
Each configured server row exposes:
- a
Configure(gear) button to edit the server - an
Uninstall(trash) button to remove it - a toggle to enable or disable it
For MCP setup, auth, server status, and agent-path boundaries, see MCP.
Related Configuration
Some AI settings are not configured on the AI settings pages:
| Task | Go to |
|---|---|
| Choose which tools are available in a Zed Agent thread | Agent Profiles |
| Control whether tool calls are allowed, denied, or confirmed | Tool Permissions |
| Configure reusable task instructions | Skills |
| Configure always-on personal or project instructions | Instructions |
| Configure edit prediction providers | Edit Prediction |
| Turn AI off | AI Quick Start |
| Edit raw settings JSON | Configuring Zed |
Feature-Specific Models
Zed supports feature-specific model settings for Inline Assistant, Git commit generation, thread summaries, and subagents. Configure these in settings when you need a different model for a specific workflow.
See LLM Providers for model access, and All Settings for the complete settings reference.
Model Temperature
Most Zed AI features use the selected model's default generation behavior.
Use agent.model_parameters when you need to set a temperature for a provider,
a model, or a specific provider/model pair.
{
"agent": {
"model_parameters": [
{
"provider": "anthropic",
"model": "claude-sonnet-4-5",
"temperature": 0.2
}
]
}
}
Zed checks matching entries from last to first. An entry can omit provider or
model to apply more broadly. For provider-specific model configuration such as
custom model entries, context windows, or gateway routing, see
LLM Providers and the provider setup pages.
Rules, Skills, and Instructions
Reusable Rules have been replaced by Skills. Always-on Rules have moved to Instructions, including personal AGENTS.md and project instruction files.
Older builds or transitional UI may still refer to Rules. Use Skills for reusable task instructions and Instructions for always-on context.