← Back to PRs

#14487: feat(config): support per-agent compaction overrides (#14446)

by lailoo open 2026-02-12 06:41 View on GitHub →
agents stale size: S trusted-contributor
## Summary Fixes #14446 ## Problem `agents.defaults.compaction.maxHistoryShare` applies globally to all agents. In multi-agent systems, coordinator agents benefit from higher retention while execution agents benefit from earlier compaction. There is no way to set per-agent compaction overrides. ## Fix Add optional `compaction` field to per-agent config (`agents.list[].compaction`), following the same pattern as existing per-agent overrides (`humanDelay`, `heartbeat`, `memorySearch`). ### Config example ```yaml agents: defaults: compaction: mode: safeguard maxHistoryShare: 0.5 list: - id: coordinator compaction: maxHistoryShare: 0.8 # retain more history - id: worker # inherits defaults (0.5) ``` ### Resolution order ``` agents.list[].compaction.{field} ?? agents.defaults.compaction.{field} ``` ### Changes 1. **Type definition** (`src/config/types.agents.ts`): add `compaction?: AgentCompactionConfig` to `AgentConfig` 2. **Zod schema** (`src/config/zod-schema.agent-runtime.ts`): add compaction validation to `AgentEntrySchema` 3. **Agent resolution** (`src/agents/agent-scope.ts`): add `compaction` to `ResolvedAgentConfig` and `resolveAgentConfig` 4. **Runtime** (`src/agents/pi-embedded-runner/extensions.ts`): new `resolveCompactionConfig()` merges defaults with per-agent overrides; `buildEmbeddedExtensionPaths` accepts optional `agentId` 5. **Callers** (`attempt.ts`, `compact.ts`): pass `agentId` to `buildEmbeddedExtensionPaths` ## Reproduction & Verification ### Before fix (main branch): - `agents.list[].compaction` is not a valid config field (Zod rejects it). - `buildEmbeddedExtensionPaths` reads only `cfg.agents.defaults.compaction` — no per-agent override path. - `resolveAgentConfig` does not return `compaction`. ### After fix — All verified: ``` ✓ should return undefined when no agents config exists ✓ should return undefined when agent id does not exist ✓ should return basic agent config ✓ returns per-agent compaction overrides (#14446) ✓ supports per-agent model primary+fallbacks ✓ should return agent-specific sandbox config ✓ should return agent-specific tools config ✓ should return both sandbox and tools config ✓ should normalize agent id ✓ uses OPENCLAW_HOME for default agent workspace ✓ uses OPENCLAW_HOME for default agentDir 11 tests pass (pnpm vitest run src/agents/agent-scope.test.ts) ``` ## Testing - ✅ 11 tests pass (`pnpm vitest run src/agents/agent-scope.test.ts`) - ✅ 7 config validation tests pass - ✅ Lint passes

Most Similar PRs