mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-02 21:01:51 +00:00
fix(agents): fall back to agents.defaults.model when agent has no model config
When an agent in agents.list lacks a model configuration, resolveAgentModelPrimary now correctly falls back to cfg.agents.defaults.model instead of returning undefined. This fixes embedded agents (like slug-generator) silently falling back to a hardcoded DEFAULT_MODEL when the main agent omits the model block but global defaults are configured. Fixes openclaw#24168
This commit is contained in:
committed by
Gustavo Madeira Santana
parent
db32677f1d
commit
b9a61aa0d2
@@ -59,6 +59,38 @@ describe("resolveAgentConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to agents.defaults.model when agent has no model configured", () => {
|
||||
const cfgWithStringDefault: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: "anthropic/claude-sonnet-4",
|
||||
},
|
||||
list: [{ id: "main" }],
|
||||
},
|
||||
};
|
||||
expect(resolveAgentModelPrimary(cfgWithStringDefault, "main")).toBe("anthropic/claude-sonnet-4");
|
||||
|
||||
const cfgWithObjectDefault: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: {
|
||||
primary: "openai/gpt-5.2",
|
||||
fallbacks: ["anthropic/claude-sonnet-4"],
|
||||
},
|
||||
},
|
||||
list: [{ id: "main" }],
|
||||
},
|
||||
};
|
||||
expect(resolveAgentModelPrimary(cfgWithObjectDefault, "main")).toBe("openai/gpt-5.2");
|
||||
|
||||
const cfgNoDefaults: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [{ id: "main" }],
|
||||
},
|
||||
};
|
||||
expect(resolveAgentModelPrimary(cfgNoDefaults, "main")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("supports per-agent model primary+fallbacks", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
|
||||
@@ -144,14 +144,29 @@ export function resolveAgentSkillsFilter(
|
||||
|
||||
export function resolveAgentModelPrimary(cfg: OpenClawConfig, agentId: string): string | undefined {
|
||||
const raw = resolveAgentConfig(cfg, agentId)?.model;
|
||||
if (!raw) {
|
||||
if (raw) {
|
||||
if (typeof raw === "string") {
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed) {
|
||||
return trimmed;
|
||||
}
|
||||
} else {
|
||||
const primary = raw.primary?.trim();
|
||||
if (primary) {
|
||||
return primary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to agents.defaults.model when agent has no model configured
|
||||
const defaultModel = cfg.agents?.defaults?.model;
|
||||
if (!defaultModel) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof raw === "string") {
|
||||
return raw.trim() || undefined;
|
||||
if (typeof defaultModel === "string") {
|
||||
return defaultModel.trim() || undefined;
|
||||
}
|
||||
const primary = raw.primary?.trim();
|
||||
return primary || undefined;
|
||||
return defaultModel.primary?.trim() || undefined;
|
||||
}
|
||||
|
||||
export function resolveAgentModelFallbacksOverride(
|
||||
|
||||
Reference in New Issue
Block a user