openclaw - 💡(How to fix) Fix Agent-level model field ignored during session creation — falls back to global default [4 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#71571Fetched 2026-04-26 05:11:20
View on GitHub
Comments
4
Participants
2
Timeline
5
Reactions
0
Participants
Timeline (top)
commented ×4closed ×1

The model field on agent definitions in agents.list[] is being ignored during session creation. Sessions always resolve to agents.defaults.model.primary (the global default) instead of the agent-specific model.

Root Cause

The model field on agent definitions in agents.list[] is being ignored during session creation. Sessions always resolve to agents.defaults.model.primary (the global default) instead of the agent-specific model.

Fix Action

Fix / Workaround

Workarounds attempted (none permanent)

Code Example

{
  "id": "tars-v4flash",
  "name": "Tars",
  "workspace": "/Users/example/v4flash-agent",
  "model": "deepseek-v4-openrouter/deepseek/deepseek-v4-flash",
  "thinkingDefault": "off"
}

---

{
  "agentId": "tars-v4flash",
  "match": {
    "channel": "discord",
    "peer": { "kind": "channel", "id": "CHANNEL_ID" }
  }
}

---

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "anthropic/claude-opus-4-6"
      }
    }
  }
}

---

{
  "models": {
    "providers": {
      "deepseek-v4-openrouter": {
        "baseUrl": "https://openrouter.ai/api/v1",
        "api": "openai-completions",
        "models": [{
          "id": "deepseek/deepseek-v4-flash",
          "name": "DeepSeek V4-Flash (OpenRouter)"
        }]
      }
    }
  }
}

---

resolveAgentEffectiveModelPrimary(cfg, agentId) {
  return resolveAgentExplicitModelPrimary(cfg, agentId) 
    ?? resolvePrimaryStringValue(cfg.agents?.defaults?.model);
}
RAW_BUFFERClick to expand / collapse

Summary

The model field on agent definitions in agents.list[] is being ignored during session creation. Sessions always resolve to agents.defaults.model.primary (the global default) instead of the agent-specific model.

Environment

  • OpenClaw version: 2026.4.20
  • OS: macOS (Apple Silicon)
  • Channel: Discord

Config (relevant parts)

Agent definition

{
  "id": "tars-v4flash",
  "name": "Tars",
  "workspace": "/Users/example/v4flash-agent",
  "model": "deepseek-v4-openrouter/deepseek/deepseek-v4-flash",
  "thinkingDefault": "off"
}

Channel binding

{
  "agentId": "tars-v4flash",
  "match": {
    "channel": "discord",
    "peer": { "kind": "channel", "id": "CHANNEL_ID" }
  }
}

Global default

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "anthropic/claude-opus-4-6"
      }
    }
  }
}

Custom model provider

{
  "models": {
    "providers": {
      "deepseek-v4-openrouter": {
        "baseUrl": "https://openrouter.ai/api/v1",
        "api": "openai-completions",
        "models": [{
          "id": "deepseek/deepseek-v4-flash",
          "name": "DeepSeek V4-Flash (OpenRouter)"
        }]
      }
    }
  }
}

Expected behavior

When a message arrives in the bound Discord channel, the gateway should:

  1. Route to agent tars-v4flash via the binding ✅ (this works)
  2. Create a session using the agent's model field (deepseek-v4-openrouter/deepseek/deepseek-v4-flash) ❌ (this fails)

Actual behavior

  • The binding correctly routes to tars-v4flash
  • The session name correctly shows agent:tars-v4flash:discord:channel:CHANNEL_ID
  • The workspace is correctly set to the agent's workspace
  • BUT the model resolves to anthropic/claude-opus-4-6 (global default)

Workarounds attempted (none permanent)

  1. Per-session model override via /model — works temporarily but reverts on session refresh/restart
  2. Adding the custom model to agents.defaults.models — required for override to work, but doesn't fix root issue
  3. Gateway restarts — no effect, fresh sessions still resolve to global default
  4. /new to force fresh session — no effect, new session still uses global default
  5. Multiple config reloads — no effect

Code analysis

The model resolution functions in the gateway code appear correct:

resolveAgentEffectiveModelPrimary(cfg, agentId) {
  return resolveAgentExplicitModelPrimary(cfg, agentId) 
    ?? resolvePrimaryStringValue(cfg.agents?.defaults?.model);
}

The agent-level model IS checked first in resolveAgentEffectiveModelPrimary(). The bug appears to be that session creation calls a different code path that doesn't consult this function, or the result is being overwritten.

Impact

This caused significant unintended API spend — sessions that should have been running on a cheap model ($0.14/$0.28 per 1M tokens) were silently running on Opus ($5/$25 per 1M tokens). The user had no indication the model was wrong until they checked API billing.

Notes

  • A second gateway on a different machine with a similar setup does NOT have this bug (agent-level model works correctly there). This may be version-dependent or related to config ordering.
  • The model field is correctly parsed from config (confirmed via config.get).
  • This is NOT a stale session issue — completely fresh sessions exhibit the same behavior.

extent analysis

TL;DR

The issue can be fixed by ensuring the resolveAgentEffectiveModelPrimary function is called during session creation, possibly by modifying the session creation code path to consult this function.

Guidance

  • Review the session creation code to identify where the model is being resolved and ensure it calls resolveAgentEffectiveModelPrimary to prioritize the agent-level model.
  • Verify that the resolveAgentExplicitModelPrimary function is correctly implemented and returns the agent-level model when available.
  • Check the config ordering and version dependencies to ensure consistency across different gateways and machines.
  • Consider adding logging or debugging statements to track the model resolution process during session creation to identify where the global default is being applied.

Example

// Example of how the session creation code could be modified to call resolveAgentEffectiveModelPrimary
createSession(cfg, agentId) {
  const model = resolveAgentEffectiveModelPrimary(cfg, agentId);
  // Use the resolved model for the session
}

Notes

The issue appears to be related to the code path used during session creation, which may not be consulting the resolveAgentEffectiveModelPrimary function. Identifying and modifying this code path is crucial to resolving the issue.

Recommendation

Apply a workaround by modifying the session creation code to call resolveAgentEffectiveModelPrimary until a permanent fix can be implemented. This will ensure that the agent-level model is prioritized during session creation.

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…

FAQ

Expected behavior

When a message arrives in the bound Discord channel, the gateway should:

  1. Route to agent tars-v4flash via the binding ✅ (this works)
  2. Create a session using the agent's model field (deepseek-v4-openrouter/deepseek/deepseek-v4-flash) ❌ (this fails)

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 - 💡(How to fix) Fix Agent-level model field ignored during session creation — falls back to global default [4 comments, 2 participants]