fix(agents): fall back to agents.defaults.model when agent has no model config (#24210)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 0f272b1027
Co-authored-by: bianbiandashen <16240681+bianbiandashen@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
边黎安
2026-02-23 16:18:55 +08:00
committed by GitHub
parent db32677f1d
commit a4c373935f
39 changed files with 434 additions and 251 deletions

View File

@@ -1,9 +1,7 @@
import { resolveAgentModelPrimary } from "../agents/agent-scope.js";
import { ensureAuthProfileStore, listProfilesForProvider } from "../agents/auth-profiles.js";
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "../agents/defaults.js";
import { getCustomProviderApiKey, resolveEnvApiKey } from "../agents/model-auth.js";
import { loadModelCatalog } from "../agents/model-catalog.js";
import { resolveConfiguredModelRef } from "../agents/model-selection.js";
import { resolveDefaultModelForAgent } from "../agents/model-selection.js";
import type { OpenClawConfig } from "../config/config.js";
import type { WizardPrompter } from "../wizard/prompts.js";
import { OPENAI_CODEX_DEFAULT_MODEL } from "./openai-codex-model-default.js";
@@ -13,35 +11,13 @@ export async function warnIfModelConfigLooksOff(
prompter: WizardPrompter,
options?: { agentId?: string; agentDir?: string },
) {
const agentModelOverride = options?.agentId
? resolveAgentModelPrimary(config, options.agentId)
: undefined;
const configWithModel =
agentModelOverride && agentModelOverride.length > 0
? {
...config,
agents: {
...config.agents,
defaults: {
...config.agents?.defaults,
model: {
...(typeof config.agents?.defaults?.model === "object"
? config.agents.defaults.model
: undefined),
primary: agentModelOverride,
},
},
},
}
: config;
const ref = resolveConfiguredModelRef({
cfg: configWithModel,
defaultProvider: DEFAULT_PROVIDER,
defaultModel: DEFAULT_MODEL,
const ref = resolveDefaultModelForAgent({
cfg: config,
agentId: options?.agentId,
});
const warnings: string[] = [];
const catalog = await loadModelCatalog({
config: configWithModel,
config,
useCache: false,
});
if (catalog.length > 0) {