Skip to content

[Bug]: runEmbeddedAgent ignores agents.defaults.model and hardcodes openai/gpt-5.5 #93419

Description

@danielgerlag

Bug type

Behavior bug (incorrect output/state without crash)

Summary

api.runtime.agent.runEmbeddedAgent(...) ignores the configured default model (agents.defaults.model) and hardcodes openai/gpt-5.5 as the primary provider/model when the caller does not pass provider/model, so plugin-triggered agent turns fail with No API key found for provider "openai" even when a different provider is configured and authenticated.

Steps to reproduce

  1. Install OpenClaw 2026.6.6 and configure a non-OpenAI default model, e.g. openclaw models set "anthropic/claude-sonnet-4-6" (writes agents.defaults.model.primary). Do not configure any OpenAI auth.
  2. From a native plugin, register a background service that calls the documented neutral helper without an explicit model:
    const workspaceDir = (await api.runtime.agent.ensureAgentWorkspace()).dir;
    await api.runtime.agent.runEmbeddedAgent({
      sessionId: "repro:1",
      runId: crypto.randomUUID(),
      sessionFile: path.join(workspaceDir, "repro.jsonl"),
      workspaceDir,
      prompt: "summarize this",
      timeoutMs: api.runtime.agent.resolveAgentTimeoutMs({ cfg: api.config }),
    });
  3. Start the gateway (openclaw gateway run) and trigger the run.

Expected behavior

The embedded run uses the configured default model (anthropic/claude-sonnet-4-6), matching the gateway's own resolution and the documented contract. The SDK runtime docs state:

runEmbeddedAgent(...) is the neutral helper for starting a normal OpenClaw agent turn from plugin code. It uses the same provider/model resolution and agent-harness selection as channel-triggered replies.

At startup the gateway logs the channel-reply resolution honoring the default:

[gateway] agent model: anthropic/claude-sonnet-4-6 (thinking=adaptive, fast=off)

Actual behavior

The embedded run resolves to openai/gpt-5.5 regardless of the configured default, and fails:

[plugins] folder-watch: add probe.txt -> running agent
[diagnostic] lane task error: lane=main ... error="ProviderAuthError: No API key found for provider "openai". Auth store: .../agents/main/agent/openclaw-agent.sqlite ..."

I verified the resolution does not consult agents.defaults.model three independent ways (OpenClaw 2026.6.6):

Attempt Result
openclaw models set anthropic/... (default model), no provider/model passed embedded run → openai
pass full config snapshot to the call, no provider/model openai
omit config entirely, no provider/model openai
pass provider: "anthropic", model: "claude-sonnet-4-6" explicitly resolves anthropic ✅ (only auth missing)

Note: passing model: "anthropic/claude-sonnet-4-6" (a canonical provider/model ref) without a separate provider produces FailoverError: Unknown model: openai/anthropic/claude-sonnet-4-6 — i.e. model is treated as a bare id and provider is prepended (defaulting to openai).

Root cause (code references, 2026.6.6 npm build)

Primary turn model is hardcoded in runEmbeddedAgent, dist/embedded-agent-L9tQiaO-.js:2286-2287:

let provider = (params.provider ?? "openai").trim() || "openai";
let modelId  = (params.model    ?? "gpt-5.5").trim() || "gpt-5.5";

Constants in dist/plugin-sdk/defaults-6FEupg54.d.ts:

declare const DEFAULT_PROVIDER = "openai";
declare const DEFAULT_MODEL = "gpt-5.5";

The only model-related config consulted on this path is the fallback chain (modelFallbacksOverride / hasEmbeddedRunConfiguredModelFallbacks) and the compaction model (agents.defaults.compaction.model, dist/compaction-runtime-context-DTO0IG8s.js:44-46). agents.defaults.model is never read for the primary model.

OpenClaw version

2026.6.6 (8c802aa)

Operating system

Reproduced on macOS (Darwin); originally observed on Windows 11

Install method

npm global (npm install -g openclaw@latest)

Model

Configured default: anthropic/claude-sonnet-4-6 (agents.defaults.model.primary); embedded run incorrectly uses openai/gpt-5.5

Provider / routing chain

openclaw -> embedded agent runner (runEmbeddedAgent) -> provider auth resolution for agent main

Logs, screenshots, and evidence

[gateway] agent model: anthropic/claude-sonnet-4-6 (thinking=adaptive, fast=off)
[plugins] folder-watch: add probe.txt -> running agent
[diagnostic] lane task error: lane=main durationMs=622 error="ProviderAuthError: No API key found for provider "openai". Auth store: /Users/<user>/.openclaw/agents/main/agent/openclaw-agent.sqlite (agentDir: /Users/<user>/.openclaw/agents/main/agent). Configure auth for this agent ..."

# with model:"anthropic/claude-sonnet-4-6" (canonical ref, no separate provider):
[diagnostic] lane task error: lane=main error="FailoverError: Unknown model: openai/anthropic/claude-sonnet-4-6"

Impact and severity

  • Affected: any plugin that calls api.runtime.agent.runEmbeddedAgent(...) without an explicit provider/model, for users whose configured default provider is not OpenAI.
  • Severity: blocks the workflow — embedded agent turns never run; fails closed with a misleading "provider openai" auth error.
  • Frequency: always (deterministic) when no explicit provider/model is passed.
  • Consequence: plugins silently route to OpenAI regardless of the user's configured provider; users must hardcode/pin a model per plugin. Also a documentation mismatch with the SDK runtime page's "same provider/model resolution as channel-triggered replies" claim.

Additional information

Workaround: pass provider and model to runEmbeddedAgent separately (split a provider/model ref into provider + bare model). A fix could have runEmbeddedAgent fall back to the agent's resolved agents.defaults.model (the same resolution used for the gateway agent model: line) before applying the openai/gpt-5.5 constants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions