mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 20:40:23 +00:00
feat(config): default thinking for sessions_spawn subagents (#7372)
* feat(config): add subagent default thinking * fix: accept config subagents.thinking + stabilize test mocks (#7372) (thanks @tyler6204) * fix: use findLast instead of clearAllMocks in test (#7372) * fix: correct test assertions for tool result structure (#7372) * fix: remove unnecessary type assertion after rebase
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createSessionsSpawnTool } from "./tools/sessions-spawn-tool.js";
|
||||
|
||||
vi.mock("../config/config.js", async () => {
|
||||
const actual = await vi.importActual("../config/config.js");
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: () => ({
|
||||
agents: {
|
||||
defaults: {
|
||||
subagents: {
|
||||
thinking: "high",
|
||||
},
|
||||
},
|
||||
},
|
||||
routing: {
|
||||
sessions: {
|
||||
mainKey: "agent:test:main",
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../gateway/call.js", () => {
|
||||
return {
|
||||
callGateway: vi.fn(async ({ method }: { method: string }) => {
|
||||
if (method === "agent") {
|
||||
return { runId: "run-123" };
|
||||
}
|
||||
return {};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe("sessions_spawn thinking defaults", () => {
|
||||
it("applies agents.defaults.subagents.thinking when thinking is omitted", async () => {
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:test:main" });
|
||||
const result = await tool.execute("call-1", { task: "hello" });
|
||||
expect(result.details).toMatchObject({ status: "accepted" });
|
||||
|
||||
const { callGateway } = await import("../gateway/call.js");
|
||||
const calls = (callGateway as unknown as ReturnType<typeof vi.fn>).mock.calls;
|
||||
|
||||
const agentCall = calls
|
||||
.map((call) => call[0] as { method: string; params?: Record<string, unknown> })
|
||||
.findLast((call) => call.method === "agent");
|
||||
|
||||
expect(agentCall?.params?.thinking).toBe("high");
|
||||
});
|
||||
|
||||
it("prefers explicit sessions_spawn.thinking over config default", async () => {
|
||||
const tool = createSessionsSpawnTool({ agentSessionKey: "agent:test:main" });
|
||||
const result = await tool.execute("call-2", { task: "hello", thinking: "low" });
|
||||
expect(result.details).toMatchObject({ status: "accepted" });
|
||||
|
||||
const { callGateway } = await import("../gateway/call.js");
|
||||
const calls = (callGateway as unknown as ReturnType<typeof vi.fn>).mock.calls;
|
||||
|
||||
const agentCall = calls
|
||||
.map((call) => call[0] as { method: string; params?: Record<string, unknown> })
|
||||
.findLast((call) => call.method === "agent");
|
||||
|
||||
expect(agentCall?.params?.thinking).toBe("low");
|
||||
});
|
||||
});
|
||||
@@ -172,15 +172,21 @@ export function createSessionsSpawnTool(opts?: {
|
||||
normalizeModelSelection(modelOverride) ??
|
||||
normalizeModelSelection(targetAgentConfig?.subagents?.model) ??
|
||||
normalizeModelSelection(cfg.agents?.defaults?.subagents?.model);
|
||||
|
||||
const resolvedThinkingDefaultRaw =
|
||||
readStringParam(targetAgentConfig?.subagents ?? {}, "thinking") ??
|
||||
readStringParam(cfg.agents?.defaults?.subagents ?? {}, "thinking");
|
||||
|
||||
let thinkingOverride: string | undefined;
|
||||
if (thinkingOverrideRaw) {
|
||||
const normalized = normalizeThinkLevel(thinkingOverrideRaw);
|
||||
const thinkingCandidateRaw = thinkingOverrideRaw || resolvedThinkingDefaultRaw;
|
||||
if (thinkingCandidateRaw) {
|
||||
const normalized = normalizeThinkLevel(thinkingCandidateRaw);
|
||||
if (!normalized) {
|
||||
const { provider, model } = splitModelRef(resolvedModel);
|
||||
const hint = formatThinkingLevels(provider, model);
|
||||
return jsonResult({
|
||||
status: "error",
|
||||
error: `Invalid thinking level "${thinkingOverrideRaw}". Use one of: ${hint}.`,
|
||||
error: `Invalid thinking level "${thinkingCandidateRaw}". Use one of: ${hint}.`,
|
||||
});
|
||||
}
|
||||
thinkingOverride = normalized;
|
||||
|
||||
@@ -204,6 +204,8 @@ export type AgentDefaultsConfig = {
|
||||
archiveAfterMinutes?: number;
|
||||
/** Default model selection for spawned sub-agents (string or {primary,fallbacks}). */
|
||||
model?: string | { primary?: string; fallbacks?: string[] };
|
||||
/** Default thinking level for spawned sub-agents (e.g. "off", "low", "medium", "high"). */
|
||||
thinking?: string;
|
||||
};
|
||||
/** Optional sandbox settings for non-main sessions. */
|
||||
sandbox?: {
|
||||
|
||||
@@ -150,6 +150,7 @@ export const AgentDefaultsSchema = z
|
||||
.strict(),
|
||||
])
|
||||
.optional(),
|
||||
thinking: z.string().optional(),
|
||||
})
|
||||
.strict()
|
||||
.optional(),
|
||||
|
||||
@@ -446,6 +446,7 @@ export const AgentEntrySchema = z
|
||||
.strict(),
|
||||
])
|
||||
.optional(),
|
||||
thinking: z.string().optional(),
|
||||
})
|
||||
.strict()
|
||||
.optional(),
|
||||
|
||||
Reference in New Issue
Block a user