Skip to content

Commit cfc4ff4

Browse files
committed
feat(compaction): add per-agent compaction overrides
1 parent 26913e6 commit cfc4ff4

82 files changed

Lines changed: 3613 additions & 398 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/macos/Sources/OpenClaw/VoiceWakeSettings.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ struct VoiceWakeSettings: View {
122122
SettingsCardGroup("Activation") {
123123
SettingsCardToggleRow(
124124
title: "Enable Voice Wake",
125-
subtitle: "Listen for a wake phrase before running voice commands. Recognition runs fully on-device.",
125+
subtitle: "Listen for a wake phrase before running voice commands. " +
126+
"Recognition runs fully on-device.",
126127
binding: self.voiceWakeBinding)
127128
.disabled(!voiceWakeSupported)
128129

@@ -150,7 +151,8 @@ struct VoiceWakeSettings: View {
150151

151152
SettingsCardToggleRow(
152153
title: "Play phase-transition sounds",
153-
subtitle: "Play short sounds when Talk Mode switches between listening, thinking, and speaking.",
154+
subtitle: "Play short sounds when Talk Mode switches between listening, " +
155+
"thinking, and speaking.",
154156
binding: self.$state.talkPhaseSoundsEnabled)
155157
.disabled(!voiceWakeSupported)
156158

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
370da2e3a4253f00c3963a3ad8b57707ea3f67a8d0d394b7d2b96db4f3413d32 config-baseline.json
2-
6a66c70d36dacf5fd1a8b7e157d1ff4812e97f518c13ebc3190509df4c269f29 config-baseline.core.json
3-
a9102c0611b8170fac37853cc31771810f31757a9e3b2c6796bbd9625f9b9206 config-baseline.channel.json
4-
923a8cac695c752e51751cc2dea185a3fbe19d0015722f7ea1909f897dfbb898 config-baseline.plugin.json
1+
81f2b9f156c0c591b99e170c7ba551deb8c6faa6143c084ee306136d6e2f523c config-baseline.json
2+
d13dcf3c6d07fe3973e6bea55d585188fd316becbac886d13b855698c0d5f7b5 config-baseline.core.json
3+
685834d8c40544948a27fe3de248b7689461c5e06c4ba75aed2470737419d937 config-baseline.channel.json
4+
1b763a5524aca2d7ecf1eea38f845ad1ffed5c1b37e85e62f6a7902a3ee0f920 config-baseline.plugin.json
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
3cc84cf3d30697d541ba98a5c1835784a4254a9193e51b009372e1620948e430 plugin-sdk-api-baseline.json
2-
515c9e2972f0d79dbed27ffae815a96d432a341005046d603a82a235c4108340 plugin-sdk-api-baseline.jsonl
1+
ddd7a4aee0eb8dde4ccaffd9073ad1b4bb697a49f5a4f6f1a61e26067e9a7665 plugin-sdk-api-baseline.json
2+
d688f18ee695c04efa0db3a7bbaaf9620fff38def5af7b82734898b22312dcce plugin-sdk-api-baseline.jsonl

docs/concepts/compaction.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ This works with local models too, for example a second Ollama model dedicated to
9191
```
9292

9393
When unset, compaction starts with the active session model. If summarization fails with a model-fallback-eligible provider error, OpenClaw retries that compaction attempt through the session's existing model fallback chain. The fallback choice is temporary and is not written back to session state. An explicit `agents.defaults.compaction.model` override remains exact and does not inherit the session fallback chain.
94+
Per-agent `agents.list[].compaction.model` overrides are also supported. Omit `agents.list[].compaction` to inherit `agents.defaults.compaction`; set only the per-agent fields that should differ. Per-agent `agents.list[].compaction` deep-merges over `agents.defaults.compaction`, so unspecified fields continue to inherit the defaults.
95+
96+
### Thinking level
97+
98+
By default, compaction uses the active session thinking level. Set `agents.defaults.compaction.thinkingLevel` to use a fixed reasoning budget for compaction summarization, such as `"off"` for cheaper summaries or `"high"` for stronger retention audits. Per-agent `agents.list[].compaction.thinkingLevel` overrides are also supported and deep-merge over the default compaction block.
9499

95100
### Identifier preservation
96101

@@ -150,6 +155,7 @@ Before compaction, OpenClaw can run a **silent memory flush** turn to store dura
150155
```
151156

152157
The memory-flush model override is exact and does not inherit the active session fallback chain. See [Memory](/concepts/memory) for details and config.
158+
Per-agent `agents.list[].compaction.memoryFlush.model` overrides are supported through the same merge semantics: omit `agents.list[].compaction` to inherit the default block, or set only the nested `memoryFlush` fields that should differ for that agent.
153159

154160
## Pluggable compaction providers
155161

docs/gateway/config-agents.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ Periodic heartbeat runs.
643643
midTurnPrecheck: { enabled: false }, // optional tool-loop pressure check
644644
postCompactionSections: ["Session Startup", "Red Lines"], // opt in to AGENTS.md section reinjection
645645
model: "openrouter/anthropic/claude-sonnet-4-6", // optional compaction-only model override
646+
thinkingLevel: "off", // optional compaction-only thinking level override
646647
truncateAfterCompaction: true, // rotate to a smaller successor JSONL after compaction
647648
maxActiveTranscriptBytes: "20mb", // optional preflight local compaction trigger
648649
notifyUser: true, // send brief notices when compaction starts and completes (default: false)
@@ -669,10 +670,13 @@ Periodic heartbeat runs.
669670
- `midTurnPrecheck`: optional tool-loop pressure check. When `enabled: true`, OpenClaw checks context pressure after tool results are appended and before the next model call. If the context no longer fits, it aborts the current attempt before submitting the prompt and reuses the existing precheck recovery path to truncate tool results or compact and retry. Works with both `default` and `safeguard` compaction modes. Default: disabled.
670671
- `postCompactionSections`: optional AGENTS.md H2/H3 section names to re-inject after compaction. Reinjection is disabled when unset or set to `[]`. Explicitly setting `["Session Startup", "Red Lines"]` enables that pair and preserves the legacy `Every Session`/`Safety` fallback. Enable this only when the extra context is worth the risk of duplicating project guidance already captured in the compaction summary.
671672
- `model`: optional `provider/model-id` override for compaction summarization only. Use this when the main session should keep one model but compaction summaries should run on another; when unset, compaction uses the session's primary model.
673+
- `thinkingLevel`: optional compaction-only thinking level (`off | minimal | low | medium | high | xhigh | adaptive | max`). When unset, compaction uses the active session thinking level; set `off` to disable reasoning for compaction.
672674
- `maxActiveTranscriptBytes`: optional byte threshold (`number` or strings like `"20mb"`) that triggers normal local compaction before a run when the active JSONL grows past the threshold. Requires `truncateAfterCompaction` so successful compaction can rotate to a smaller successor transcript. Disabled when unset or `0`.
673675
- `notifyUser`: when `true`, sends brief notices to the user when compaction starts and when it completes (for example, "Compacting context..." and "Compaction complete"). Disabled by default to keep compaction silent.
674676
- `memoryFlush`: silent agentic turn before auto-compaction to store durable memories. Set `model` to an exact provider/model such as `ollama/qwen3:8b` when this housekeeping turn should stay on a local model; the override does not inherit the active session fallback chain. Skipped when workspace is read-only.
675677

678+
Per-agent `agents.list[].compaction` blocks are supported. Omit the block to inherit `agents.defaults.compaction`. Set only the fields that should differ for an agent; per-agent compaction blocks deep-merge over the default block.
679+
676680
### `agents.defaults.runRetries`
677681

678682
Outer run loop retry iteration boundaries for the embedded agent runtime to prevent infinite execution loops during failure recovery. Note that this setting currently only applies to the embedded agent runtime, not ACP or CLI runtimes.
@@ -1099,6 +1103,7 @@ for provider examples and precedence.
10991103
- `thinkingDefault`: optional per-agent default thinking level (`off | minimal | low | medium | high | xhigh | adaptive | max`). Overrides `agents.defaults.thinkingDefault` for this agent when no per-message or session override is set. The selected provider/model profile controls which values are valid; for Google Gemini, `adaptive` keeps provider-owned dynamic thinking (`thinkingLevel` omitted on Gemini 3/3.1, `thinkingBudget: -1` on Gemini 2.5).
11001104
- `reasoningDefault`: optional per-agent default reasoning visibility (`on | off | stream`). Overrides `agents.defaults.reasoningDefault` for this agent when no per-message or session reasoning override is set.
11011105
- `fastModeDefault`: optional per-agent default for fast mode (`true | false`). Applies when no per-message or session fast-mode override is set.
1106+
- `compaction`: optional per-agent compaction policy. If omitted, the agent inherits `agents.defaults.compaction`. If set, the block deep-merges over the default for that agent, including nested `qualityGuard`, `midTurnPrecheck`, and `memoryFlush` fields.
11021107
- `models`: optional per-agent model catalog/runtime overrides keyed by full `provider/model` ids. Use `models["provider/model"].agentRuntime` for per-agent runtime exceptions.
11031108
- `runtime`: optional per-agent runtime descriptor. Use `type: "acp"` with `runtime.acp` defaults (`agent`, `backend`, `mode`, `cwd`) when the agent should default to ACP harness sessions.
11041109
- `identity.avatar`: workspace-relative path, `http(s)` URL, or `data:` URI.

docs/reference/session-management-compaction.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ OpenClaw also enforces a safety floor for embedded runs:
345345
and keeps OpenClaw runtime's recent-tail cut point. Without an explicit keep budget,
346346
manual compaction remains a hard checkpoint and rebuilt context starts from
347347
the new summary.
348+
- Set `agents.defaults.compaction.thinkingLevel` to pin the reasoning budget used
349+
by compaction summarization. When unset, compaction uses the active session
350+
thinking level. Per-agent `agents.list[].compaction.thinkingLevel` deep-merges
351+
over the default compaction block.
348352
- Set `agents.defaults.compaction.midTurnPrecheck.enabled: true` to run the
349353
optional tool-loop precheck after new tool results and before the next model
350354
call. This is a trigger only; summary generation still uses the configured

extensions/codex/src/app-server/attempt-startup.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export type StartCodexAttemptThreadResult = {
6666
executionCwd: string;
6767
sandboxPolicy: CodexSandboxPolicy | undefined;
6868
releaseSharedClientLease: () => void;
69-
restartContextEngineCodexThread: () => Promise<CodexAppServerThreadLifecycleBinding>;
69+
restartContextEngineCodexThread: (
70+
contextEngineProjection?: CodexContextEngineThreadBootstrapProjection,
71+
) => Promise<CodexAppServerThreadLifecycleBinding>;
7072
};
7173

7274
export async function startCodexAttemptThread(params: {
@@ -300,8 +302,14 @@ export async function startCodexAttemptThread(params: {
300302
environmentSelection: startupEnvironmentSelection,
301303
executionCwd: startupExecutionCwd,
302304
sandboxPolicy: startupSandboxPolicy,
303-
restartContextEngineCodexThread: () =>
304-
startOrResumeThread(buildThreadLifecycleParams()),
305+
restartContextEngineCodexThread: (
306+
contextEngineProjection?: CodexContextEngineThreadBootstrapProjection,
307+
) =>
308+
startOrResumeThread({
309+
...buildThreadLifecycleParams(),
310+
contextEngineProjection:
311+
contextEngineProjection ?? params.contextEngineProjection,
312+
}),
305313
};
306314
} catch (error) {
307315
await releaseStartupSandboxEnvironment();

0 commit comments

Comments
 (0)