Skip to content

Feature Request: Per-Agent contextTokens and compaction Overrides #16546

Closed as not planned

Description

@coolmanns

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

  1. Setting contextTokens on individual agent entries — fails config validation (not in per-agent schema)
  2. Model aliases with different context settings — cannot register same model ID twice, and models entries do not have context/compaction fields anyway
  3. 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)

Activity

  1. curtismercier commented on Feb 17, 2026

    @curtismercier

    Hey @coolmanns — PR #19329 covers the per-agent compaction part of your request (mode, reserveTokensFloor, maxHistoryShare, memoryFlush, contextPruning — all configurable per agent with deep merge against global defaults).

    Per-agent contextTokens is 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!

  2. fmangot commented on Feb 21, 2026

    @fmangot

    +1 👍 Per-agent contextTokens would be hugely useful in multi-agent setups with mixed model roles.

  3. fmangot commented on Feb 21, 2026

    @fmangot

    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.

  4. openclaw-barnacle commented on Mar 13, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  5. added
    stale
    on Mar 13, 2026
  6. openclaw-barnacle commented on Mar 19, 2026

    @openclaw-barnacle

    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.

  7. locked as resolved and limited conversation to collaborators on Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions