Skip to content

fix(agents): resolve configured default model in runEmbeddedAgent (fixes #93419)#93428

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
zenglingbiao:fix/issue-93419-embedded-agent-default-model
Jun 16, 2026
Merged

fix(agents): resolve configured default model in runEmbeddedAgent (fixes #93419)#93428
vincentkoc merged 4 commits into
openclaw:mainfrom
zenglingbiao:fix/issue-93419-embedded-agent-default-model

Conversation

@zenglingbiao

Copy link
Copy Markdown
Contributor

Summary

  • Problem: runEmbeddedAgent hardcodes openai/gpt-5.5 as the default provider/model, ignoring agents.defaults.model.primary. Plugin-triggered embedded agent runs fail with No API key found for provider "openai" even when a non-OpenAI default is configured and authenticated.
  • Root Cause: In src/agents/embedded-agent-runner/run.ts:747-748, the provider/model resolution chain is params.provider ?? DEFAULT_PROVIDER and params.model ?? DEFAULT_MODEL, with no check of agents.defaults.model.primary from the config.
  • Fix: Before falling back to the hardcoded DEFAULT_PROVIDER/DEFAULT_MODEL, resolve agents.defaults.model.primary via resolveAgentModelPrimaryValue and parse the canonical provider/model ref with parseModelRef. The resolved provider/model are inserted into the fallback chain between explicit params and the hardcoded defaults.
  • What changed:
    • src/agents/embedded-agent-runner/run.ts — import resolveAgentModelPrimaryValue and parseModelRef; add configured-primary resolution step before the fallback chain.
  • What did NOT change (scope boundary):
    • No changes to the auto-reply pipeline or channel-triggered model resolution.
    • No changes to DEFAULT_PROVIDER/DEFAULT_MODEL constants in defaults.ts.
    • No changes to the compaction model resolution path.
    • No changes to the fallback chain (modelFallbacksOverride).

Reproduction

  1. Configure a non-OpenAI default model: openclaw models set "anthropic/claude-sonnet-4-6".
  2. From a plugin, call api.runtime.agent.runEmbeddedAgent({ ... }) without passing provider or model.
  3. Before this PR: The embedded run resolves to openai/gpt-5.5 and fails with ProviderAuthError: No API key found for provider "openai".
  4. After this PR: The embedded run resolves to anthropic/claude-sonnet-4-6, matching the configured default and the auto-reply pipeline resolution.

Real behavior proof

Behavior or issue addressed (#93419): runEmbeddedAgent now resolves agents.defaults.model.primary from the config as the default provider/model when the caller does not pass explicit provider/model, matching the documented contract that embedded runs use the same model resolution as channel-triggered replies.

Real environment tested: Linux, Node 22 — in-memory test harness against the embedded agent runner.

Exact steps or command run after this patch: node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.codex-app-server-recovery.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts

Evidence after fix:

Test Files  2 passed (2)
     Tests  121 passed (121)

Files:
  run.codex-app-server-recovery.test.ts    1 file
  run.incomplete-turn.test.ts              1 file

Observed result after fix: The runEmbeddedAgentInternal function now checks params.config?.agents?.defaults?.model via resolveAgentModelPrimaryValue when neither params.provider nor params.model is explicitly passed. The canonical model ref (e.g., "anthropic/claude-sonnet-4-6") is parsed into {provider, model} via parseModelRef and inserted into the fallback chain before the hardcoded DEFAULT_PROVIDER/DEFAULT_MODEL. All 121 existing embedded agent runner tests continue to pass, confirming no regressions in the execution, recovery, and compaction paths.

What was not tested: A live plugin-triggered embedded agent run with a non-OpenAI configured default was not driven. The parseModelRef integration with live config was not exercised end-to-end.

Repro confirmation: Code-path analysis confirms the gap: before the fix, line 747-748 was let provider = (params.provider ?? DEFAULT_PROVIDER)... and let modelId = (params.model ?? DEFAULT_MODEL)... with no reference to agents.defaults.model. After the fix, resolveAgentModelPrimaryValue(params.config?.agents?.defaults?.model) is called and the result is parsed and inserted into the fallback chain.

Risk / Mitigation

  • Risk: parseModelRef returns null for malformed model refs, causing a fallback to hardcoded defaults (same as before).
    Mitigation: When configuredModelRef is null (invalid ref), the existing ?? DEFAULT_PROVIDER/?? DEFAULT_MODEL fallback is used, preserving backward compatibility.
  • Risk: The configured primary resolution is skipped when caller explicitly passes provider or model.
    Mitigation: This is intentional — explicit caller parameters always take precedence over configured defaults, matching the principle of least surprise.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • agents (embedded agent runner model resolution)

Regression Test Plan

  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.codex-app-server-recovery.test.ts
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.incomplete-turn.test.ts

Review Findings Addressed

N/A (initial submission)

Linked Issue/PR

Fixes #93419

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 15, 2026
@vincentkoc vincentkoc self-assigned this Jun 15, 2026
@vincentkoc vincentkoc force-pushed the fix/issue-93419-embedded-agent-default-model branch from 9d4cce8 to 7041c71 Compare June 15, 2026 23:36
@vincentkoc

Copy link
Copy Markdown
Member

Land-ready maintainer verification:

  • Configured per-agent/global defaults now apply only when provider and model are omitted; explicit routing remains unchanged.
  • Runtime snapshot lookup stays limited to omitted-config, omitted-model calls.
  • Transcript fallback is accepted only for the effective runtime model, while live retry fixtures now model currentAttemptAssistant explicitly.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner.e2e.test.ts — 16 tests passed.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.cross-provider-fallback-error-context.test.ts src/agents/embedded-agent-runner/run.codex-server-error-fallback.test.ts — 5 tests passed.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.empty-error-retry.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts — 129 tests passed; four local linked-worktree cases were blocked only by the known @openclaw/llm-core resolution gap. The full checks-node-agentic-agents-embedded CI shard passed on this head: https://github.com/openclaw/openclaw/actions/runs/27585374727/job/81554471895
  • node_modules/.bin/oxfmt --check on changed files and git diff --check passed.
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean, no accepted/actionable findings.

All relevant PR checks completed green. check-additional-runtime-topology-architecture is the unrelated base-branch Kysely guard failure in src/agents/auth-profiles/sqlite.ts:103; this PR does not touch that file.

@vincentkoc vincentkoc merged commit 03e3ef8 into openclaw:main Jun 16, 2026
169 of 172 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 16, 2026
 openclaw#93419) (openclaw#93428)

* fix(agents): honor configured default model in embedded runs

* fix(agents): resolve embedded defaults from runtime config

* fix(agents): preserve embedded model routing semantics

* test(agents): model current embedded attempts explicitly

---------

Co-authored-by: Vincent Koc <25068+vincentkoc@users.noreply.github.com>
crh-code pushed a commit to crh-code/openclaw that referenced this pull request Jun 18, 2026
 openclaw#93419) (openclaw#93428)

* fix(agents): honor configured default model in embedded runs

* fix(agents): resolve embedded defaults from runtime config

* fix(agents): preserve embedded model routing semantics

* test(agents): model current embedded attempts explicitly

---------

Co-authored-by: Vincent Koc <25068+vincentkoc@users.noreply.github.com>
badgerbees pushed a commit to badgerbees/openclaw that referenced this pull request Jul 8, 2026
 openclaw#93419) (openclaw#93428)

* fix(agents): honor configured default model in embedded runs

* fix(agents): resolve embedded defaults from runtime config

* fix(agents): preserve embedded model routing semantics

* test(agents): model current embedded attempts explicitly

---------

Co-authored-by: Vincent Koc <25068+vincentkoc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants