openclaw - ✅(Solved) Fix Allow contextWindow/maxTokens overrides in agents.defaults.models [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#44468Fetched 2026-04-08 00:46:32
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
1
Timeline (top)
commented ×2referenced ×2cross-referenced ×1
  • DEFAULT_CONTEXT_TOKENS = 200_000 (src/agents/defaults.ts:6)
  • gpt-5.4 actually supports 1M tokens but Codex CLI reports context_window: 272000 in its models.json
  • Users wanting to push context limits have no simple config path today

Root Cause

This is unintuitive because:

  • agents.defaults.models."openai-codex/gpt-5.4" is the natural place users look to configure per-model settings
  • That path already supports params (pass-through API params like reasoning_effort), alias, and streaming
  • But it does not accept contextWindow, maxTokens, reasoning, or input — forcing users into the provider-level config

Fix Action

Fixed

PR fix notes

PR #44475: config: allow passthrough fields in agents.defaults.models entries

Description (problem / solution / changelog)

Summary

  • Change the per-model entry schema in agents.defaults.models from .strict() to .passthrough(), allowing users to set provider-level model properties (e.g. contextWindow, maxTokens) directly without creating a full models.providers entry.
  • Passthrough fields (everything except alias/params/streaming) are extracted and merged into the corresponding provider model definition during applyModelDefaults(), before default resolution runs.
  • Forward-compatible: new upstream model properties are accepted without schema changes; errors propagate naturally at the consumption layer.

Before (verbose — requires full provider entry)

{
  "models": {
    "providers": {
      "openai-codex": {
        "baseUrl": "https://api.openai.com/v1",
        "api": "openai-responses",
        "models": [{
          "id": "gpt-5.4",
          "name": "GPT-5.4",
          "contextWindow": 1000000,
          "maxTokens": 100000,
          "reasoning": true,
          "input": ["text", "image", "pdf"]
        }]
      }
    }
  }
}

After (concise — passthrough from agent defaults)

{
  "agents": {
    "defaults": {
      "models": {
        "openai-codex/gpt-5.4": { "contextWindow": 1000000 }
      }
    }
  }
}

Test plan

  • Added test: merges contextWindow from passthrough fields
  • Added test: merges maxTokens from passthrough fields
  • Added test: known keys (alias/params/streaming) are NOT forwarded to provider models
  • Existing alias and model-defaults tests still pass
  • pnpm test src/config/model-alias-defaults.test.ts
  • pnpm build (type-check)

Closes #44468

Changed files

  • src/config/defaults.ts (modified, +41/-1)
  • src/config/model-alias-defaults.test.ts (modified, +163/-0)
  • src/config/types.agent-defaults.ts (modified, +2/-0)
  • src/config/zod-schema.agent-defaults.ts (modified, +1/-1)

Code Example

// agents.defaults.models — only 3 fields
z.object({
  alias: z.string().optional(),
  params: z.record(z.string(), z.unknown()).optional(),
  streaming: z.boolean().optional(),
}).strict()

// models.providers[].models[] — has contextWindow but requires full provider setup
z.object({
  id: z.string().min(1),
  name: z.string().min(1),       // required
  contextWindow: z.number().positive().optional(),
  maxTokens: z.number().positive().optional(),
  // ...
}).strict()

---

z.object({
  alias: z.string().optional(),
  params: z.record(z.string(), z.unknown()).optional(),
  streaming: z.boolean().optional(),
  contextWindow: z.number().positive().optional(),  // new
  maxTokens: z.number().positive().optional(),       // new
}).strict()

---

{
  "models": {
    "providers": {
      "openai-codex": {
        "models": [{ "id": "gpt-5.4", "contextWindow": 1000000 }]
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Problem

When users want to override contextWindow for a model (e.g. setting openai-codex/gpt-5.4 to 1M tokens), the only path is:

  1. Add a full provider entry in models.providers.openai-codex
  2. Include baseUrl, api, name (all required by schema validation) even though the built-in provider already defines them
  3. Define the model with the desired contextWindow

This is unintuitive because:

  • agents.defaults.models."openai-codex/gpt-5.4" is the natural place users look to configure per-model settings
  • That path already supports params (pass-through API params like reasoning_effort), alias, and streaming
  • But it does not accept contextWindow, maxTokens, reasoning, or input — forcing users into the provider-level config

Current schema

// agents.defaults.models — only 3 fields
z.object({
  alias: z.string().optional(),
  params: z.record(z.string(), z.unknown()).optional(),
  streaming: z.boolean().optional(),
}).strict()

// models.providers[].models[] — has contextWindow but requires full provider setup
z.object({
  id: z.string().min(1),
  name: z.string().min(1),       // required
  contextWindow: z.number().positive().optional(),
  maxTokens: z.number().positive().optional(),
  // ...
}).strict()

Proposal

Add contextWindow and maxTokens to agents.defaults.models schema:

z.object({
  alias: z.string().optional(),
  params: z.record(z.string(), z.unknown()).optional(),
  streaming: z.boolean().optional(),
  contextWindow: z.number().positive().optional(),  // new
  maxTokens: z.number().positive().optional(),       // new
}).strict()

These values should override the provider-level or default values during model resolution (in src/config/defaults.ts).

Secondary issue

When a user adds an explicit provider entry that matches a built-in provider (e.g. openai-codex), schema validation still requires baseUrl and models[].name even though the built-in already provides them. The merge logic in mergeProviderModels() already handles this correctly at runtime, but validation rejects the config before merging happens.

Relaxing required fields when the provider key matches a known built-in would make overrides much simpler:

{
  "models": {
    "providers": {
      "openai-codex": {
        "models": [{ "id": "gpt-5.4", "contextWindow": 1000000 }]
      }
    }
  }
}

Context

  • DEFAULT_CONTEXT_TOKENS = 200_000 (src/agents/defaults.ts:6)
  • gpt-5.4 actually supports 1M tokens but Codex CLI reports context_window: 272000 in its models.json
  • Users wanting to push context limits have no simple config path today

extent analysis

Fix Plan

To address the issue, we need to update the agents.defaults.models schema to include contextWindow and maxTokens. We also need to relax the required fields for provider entries that match built-in providers.

Step-by-Step Solution

  • Update the agents.defaults.models schema:
z.object({
  alias: z.string().optional(),
  params: z.record(z.string(), z.unknown()).optional(),
  streaming: z.boolean().optional(),
  contextWindow: z.number().positive().optional(),
  maxTokens: z.number().positive().optional(),
}).strict()
  • Relax the required fields for provider entries that match built-in providers:
// In mergeProviderModels() function
if (providerKey in builtInProviders) {
  // Remove required fields for built-in providers
  delete schema.required['baseUrl'];
  delete schema.required['models[].name'];
}
  • Update the mergeProviderModels() function to merge the user-provided config with the built-in provider config:
// In mergeProviderModels() function
const mergedModels = builtInProvider.models.map((model) => {
  const userProvidedModel = userConfig.models.providers[providerKey].models.find((m) => m.id === model.id);
  if (userProvidedModel) {
    return { ...model, ...userProvidedModel };
  }
  return model;
});

Verification

To verify the fix, create a test config with the updated agents.defaults.models schema and a provider entry that matches a built-in provider. Check that the contextWindow and maxTokens values are correctly overridden.

Extra Tips

  • Make sure to update the documentation to reflect the changes to the agents.defaults.models schema.
  • Consider adding additional validation to ensure that the contextWindow and maxTokens values are valid and consistent with the provider's capabilities.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Allow contextWindow/maxTokens overrides in agents.defaults.models [1 pull requests, 2 comments, 2 participants]