Repository navigation
Description
Summary
Allow contextTokens and compaction settings to be configured per agent in agents.list[], not just globally in agents.defaults.
Problem
Currently, contextTokens and compaction are only valid under agents.defaults, meaning every agent shares the same context window limit and compaction threshold. In a multi-agent deployment with agents of different roles, models, and cost profiles, this is a significant limitation.
Real-world scenario
We run 11 agents on a single OpenClaw instance:
| Agent | Model | Role | Ideal contextTokens |
|---|---|---|---|
| main (Gandalf) | Opus 4.6 | Personal assistant | 200K |
| toby | Sonnet 4 | Dev/tech lead | 120K (burns tokens on code, hits 167K and produces sloppy output) |
| pixel | Opus 4.6 | Design | 200K |
| pete-pm | Opus 4.6 | Project manager | 150K |
| beta-tester | Sonnet 4 | QA | 100K |
| devops | Sonnet 4 | Infrastructure | 120K |
| ernest | Sonnet 4 | Writer | 150K |
| ram-dass | Opus 4.6 | Spiritual guide | 200K |
| social-steven | Opus 4.6 | Social media | 150K |
| cron-agent | Sonnet 4 | Scheduled tasks | 100K |
| agent-creator | Sonnet 4 | Agent scaffolding | 100K |
Setting agents.defaults.contextTokens: 200000 means Toby (a code agent that degrades badly past ~150K) gets the same limit as Opus agents that handle 200K fine. Lowering the global default to help Toby would penalize the Opus agents that benefit from larger context.
The same applies to compaction — a coding agent that churns through tool calls benefits from more aggressive compaction than a conversational agent.
What we tried
- Setting
contextTokenson individual agent entries — fails config validation (not in per-agent schema) - Model aliases with different context settings — cannot register same model ID twice, and
modelsentries do not have context/compaction fields anyway - Workaround: operational controls in agent AGENTS.md (forced resets, smaller tasks) — works but is fragile and agent-dependent
Proposed Solution
Add contextTokens and compaction as optional per-agent overrides in agents.list[] items, inheriting from agents.defaults when not specified.
{
"agents": {
"defaults": {
"contextTokens": 200000,
"compaction": {
"mode": "default",
"memoryFlush": { "enabled": true, "softThresholdTokens": 25000 }
}
},
"list": [
{
"id": "toby",
"model": "anthropic/claude-sonnet-4-20250514",
"contextTokens": 120000,
"compaction": {
"mode": "default",
"memoryFlush": { "softThresholdTokens": 15000 }
}
}
]
}
}Bonus: contextPruning and bootstrapMaxChars per agent would also be useful, but contextTokens and compaction are the highest priority.
Deployment Details
- OpenClaw version: 2026.2.12 (beta channel)
- OS: Linux 6.17.0-14-generic (x64)
- Node: v22.22.0
- Gateway mode: local (loopback + Tailscale serve)
- Agents: 11 configured (mix of Opus 4.6, Sonnet 4, Haiku 4.5 heartbeats)
- Channels: Telegram + Discord
- Memory backend: qmd
Impact
This would allow operators of multi-agent deployments to:
- Prevent context bloat in code-heavy agents without penalizing conversational agents
- Reduce cost by capping cheaper models at lower context (Anthropic doubles price over 200K for Opus)
- Tune compaction aggressiveness per agent role
- Better match context limits to model capabilities (Sonnet does not need 200K the way Opus does)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
curtismercier commentedon Feb 17, 2026
Hey @coolmanns — PR #19329 covers the per-agent
compactionpart of your request (mode, reserveTokensFloor, maxHistoryShare, memoryFlush, contextPruning — all configurable per agent with deep merge against global defaults).Per-agent
contextTokensis a separate concern not included in this PR, but the compaction overrides should help with the multi-model scenario you described — e.g., setting a higher reserve floor for smaller-context models.If this is useful for you, a 👍 on the PR helps maintainers prioritize it. Feedback welcome!
fmangot commentedon Feb 21, 2026
+1 👍 Per-agent contextTokens would be hugely useful in multi-agent setups with mixed model roles.
fmangot commentedon Feb 21, 2026
Also +1 for extending this to provider/model-level context policies (or per-agent model profiles), not just per-agent static caps. In hybrid stacks, we need different context budgets by model/provider without constantly rewriting global contextTokens.
openclaw-barnacle commentedon Mar 13, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
openclaw-barnacle commentedon Mar 19, 2026
Closing due to inactivity.
If this is still an issue, please retry on the latest OpenClaw release and share updated details.
If you are absolutely sure it still happens on the latest release, open a new issue with fresh repro steps.