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,5 +1,9 @@
import type { AssistantMessage } from "@mariozechner/pi-ai";
import type { OpenClawConfig } from "../../config/config.js";
import {
resolveAgentModelFallbackValues,
resolveAgentModelPrimaryValue,
} from "../../config/model-input.js";
import { extractAssistantText } from "../pi-embedded-utils.js";
export type ImageModelConfig = { primary?: string; fallbacks?: string[] };
@@ -51,12 +55,8 @@ export function coerceImageAssistantText(params: {
}
export function coerceImageModelConfig(cfg?: OpenClawConfig): ImageModelConfig {
const imageModel = cfg?.agents?.defaults?.imageModel as
| { primary?: string; fallbacks?: string[] }
| string
| undefined;
const primary = typeof imageModel === "string" ? imageModel.trim() : imageModel?.primary;
const fallbacks = typeof imageModel === "object" ? (imageModel?.fallbacks ?? []) : [];
const primary = resolveAgentModelPrimaryValue(cfg?.agents?.defaults?.imageModel);
const fallbacks = resolveAgentModelFallbackValues(cfg?.agents?.defaults?.imageModel);
return {
...(primary?.trim() ? { primary: primary.trim() } : {}),
...(fallbacks.length > 0 ? { fallbacks } : {}),