fix(agents): prefer agent model for subagent spawns

This commit is contained in:
MarsDoge 2026-03-17 23:31:19 +08:00
parent f036ed27f4
commit fbc62c4976
3 changed files with 39 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import {
resolveConfiguredModelRef,
resolveThinkingDefault,
resolveModelRefFromString,
resolveSubagentConfiguredModelSelection,
} from "./model-selection.js";
const EXPLICIT_ALLOWLIST_CONFIG = {
@ -826,3 +827,21 @@ describe("normalizeModelSelection", () => {
expect(normalizeModelSelection(42)).toBeUndefined();
});
});
describe("resolveSubagentConfiguredModelSelection", () => {
it("prefers the target agent primary model over the global subagent default", () => {
const cfg = {
agents: {
defaults: {
subagents: { model: "minimax/MiniMax-M2.5" },
model: { primary: "openai/gpt-5.4" },
},
list: [{ id: "research", model: { primary: "opencode/claude" } }],
},
} as OpenClawConfig;
expect(resolveSubagentConfiguredModelSelection({ cfg, agentId: "research" })).toBe(
"opencode/claude",
);
});
});

View File

@ -381,8 +381,8 @@ export function resolveSubagentConfiguredModelSelection(params: {
const agentConfig = resolveAgentConfig(params.cfg, params.agentId);
return (
normalizeModelSelection(agentConfig?.subagents?.model) ??
normalizeModelSelection(params.cfg.agents?.defaults?.subagents?.model) ??
normalizeModelSelection(agentConfig?.model)
normalizeModelSelection(agentConfig?.model) ??
normalizeModelSelection(params.cfg.agents?.defaults?.subagents?.model)
);
}

View File

@ -230,6 +230,24 @@ describe("openclaw-tools: subagents (sessions_spawn model + thinking)", () => {
});
});
it("sessions_spawn prefers target agent primary model over global subagent default", async () => {
await expectSpawnUsesConfiguredModel({
config: {
session: { mainKey: "main", scope: "per-sender" },
agents: {
defaults: {
subagents: { model: "minimax/MiniMax-M2.5" },
model: { primary: "openai/gpt-5.4" },
},
list: [{ id: "research", model: { primary: "opencode/claude" } }],
},
},
runId: "run-agent-primary-over-subagent-default",
callId: "call-agent-primary-over-subagent-default",
expectedModel: "opencode/claude",
});
});
it("sessions_spawn prefers target agent primary model over global default", async () => {
await expectSpawnUsesConfiguredModel({
config: {