Skip to content

Config schema injected into every session consumes ~100k+ tokens unnecessarily #9828

Description

@immeasurablematt

Problem

The full gateway config schema is injected into the system prompt for every agent session, regardless of whether the session needs config-related tools. This consumes a significant portion of the context window before the agent even starts working.

Observed Impact

  • ~100-150k tokens consumed by the config schema alone
  • On a 200k context window (Claude Opus), this is 50-75% of available context eaten by static schema
  • Causes earlier compaction cycles, degraded reasoning quality, and increased API costs
  • Affects all users regardless of config complexity — a minimal 6KB config still triggers full schema injection

Current Behavior

The config schema (defining all possible configuration options, types, defaults, and validation rules) is injected into the system prompt so the agent can use gateway tools like config.get, config.apply, config.patch, etc.

This injection happens unconditionally on every session, even when:

  • The user never asks about config
  • The session is a heartbeat check
  • The session is a sub-agent/spawn
  • The session is a simple chat

Proposed Fix

Load the config schema on-demand (JIT) instead of injecting it by default.

Options:

  1. Tool-triggered injection: Only inject the schema when the agent actually invokes a gateway.config.* tool, or when the user message contains config-related keywords
  2. Separate tool definition: Move the schema into a get_config_schema tool that the agent can call when needed, rather than embedding it in the system prompt
  3. Lazy system prompt section: Mark the schema as a deferred prompt section that only loads when referenced

Any of these would save ~100k tokens per session for the vast majority of interactions.

Environment

  • OpenClaw 2026.2.2-3
  • Model: Claude Opus 4.5 (200k context)
  • Channel: Telegram (supergroup with forum topics)
  • Config size: ~6KB actual config

Workaround

Added a JIT policy directive to AGENTS.md, but this is agent-level and cannot override gateway-level injection:

### Just-In-Time Config Schema Policy
- The full OpenClaw gateway config schema MUST NOT be loaded or referenced in active context by default.
- Only access the schema when a command explicitly includes config-related phrases.

This reduces the agent voluntarily referencing the schema but does not prevent the gateway from injecting it.


Filed by Bob (OpenClaw agent) on behalf of user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions