mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 01:06:23 +00:00
Summary: - The branch adds per-agent `agents.list[].experimental.localModelLean` config and applies lean tool filtering through agent, session, and default-agent resolution. - Reproducibility: not applicable. this is a feature/config PR rather than a current-main bug report. The chan ... or is supported by source review, focused tests in the branch, and the PR body's redacted live runtime log. Automerge notes: - PR branch already contained follow-up commit before automerge: feat(agents): support per-agent local model lean mode - PR branch already contained follow-up commit before automerge: fix(clawsweeper): address review for automerge-openclaw-openclaw-8407… Validation: - ClawSweeper review passed for head1f9a9554da. - Required merge gates passed before the squash merge. Prepared head SHA:1f9a9554daReview: https://github.com/openclaw/openclaw/pull/84073#issuecomment-4486397570 Co-authored-by: Bob <dutifulbob@gmail.com> Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com> Co-authored-by: clawsweeper[bot] <274271284+clawsweeper[bot]@users.noreply.github.com> Approved-by: osolmaz Co-authored-by: osolmaz <2453968+osolmaz@users.noreply.github.com>
166 lines
4.3 KiB
TypeScript
166 lines
4.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import { filterLocalModelLeanTools, isLocalModelLeanEnabled } from "./local-model-lean.js";
|
|
import type { AnyAgentTool } from "./pi-tools.types.js";
|
|
|
|
function tools(names: string[]): AnyAgentTool[] {
|
|
return names.map((name) => ({ name })) as AnyAgentTool[];
|
|
}
|
|
|
|
describe("local model lean tool filtering", () => {
|
|
it("filters heavyweight tools for one configured agent", () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
list: [
|
|
{
|
|
id: "gemma",
|
|
experimental: {
|
|
localModelLean: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
expect(isLocalModelLeanEnabled({ config: cfg, agentId: "gemma" })).toBe(true);
|
|
expect(
|
|
filterLocalModelLeanTools({
|
|
tools: tools(["read", "browser", "cron", "message", "exec"]),
|
|
config: cfg,
|
|
agentId: "gemma",
|
|
}).map((tool) => tool.name),
|
|
).toEqual(["read", "exec"]);
|
|
});
|
|
|
|
it("lets an agent opt out of an inherited global lean setting", () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
defaults: {
|
|
experimental: {
|
|
localModelLean: true,
|
|
},
|
|
},
|
|
list: [
|
|
{
|
|
id: "main",
|
|
experimental: {
|
|
localModelLean: false,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
expect(isLocalModelLeanEnabled({ config: cfg, agentId: "main" })).toBe(false);
|
|
expect(
|
|
filterLocalModelLeanTools({
|
|
tools: tools(["read", "browser", "cron", "message", "exec"]),
|
|
config: cfg,
|
|
agentId: "main",
|
|
}).map((tool) => tool.name),
|
|
).toEqual(["read", "browser", "cron", "message", "exec"]);
|
|
});
|
|
|
|
it("inherits global lean mode when an agent experimental block omits the flag", () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
defaults: {
|
|
experimental: {
|
|
localModelLean: true,
|
|
},
|
|
},
|
|
list: [
|
|
{
|
|
id: "main",
|
|
experimental: {},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
expect(isLocalModelLeanEnabled({ config: cfg, agentId: "main" })).toBe(true);
|
|
expect(
|
|
filterLocalModelLeanTools({
|
|
tools: tools(["read", "browser", "cron", "message", "exec"]),
|
|
config: cfg,
|
|
agentId: "main",
|
|
}).map((tool) => tool.name),
|
|
).toEqual(["read", "exec"]);
|
|
});
|
|
|
|
it("keeps global lean mode for an agent id without an agent entry", () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
defaults: {
|
|
experimental: {
|
|
localModelLean: true,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(isLocalModelLeanEnabled({ config: cfg, agentId: "ad-hoc" })).toBe(true);
|
|
expect(
|
|
filterLocalModelLeanTools({
|
|
tools: tools(["read", "browser", "cron", "message", "exec"]),
|
|
config: cfg,
|
|
agentId: "ad-hoc",
|
|
}).map((tool) => tool.name),
|
|
).toEqual(["read", "exec"]);
|
|
});
|
|
|
|
it("uses the configured default agent when no agent id is explicit", () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
list: [
|
|
{
|
|
id: "gemma",
|
|
default: true,
|
|
experimental: {
|
|
localModelLean: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
expect(isLocalModelLeanEnabled({ config: cfg })).toBe(true);
|
|
expect(
|
|
filterLocalModelLeanTools({
|
|
tools: tools(["read", "browser", "cron", "message", "exec"]),
|
|
config: cfg,
|
|
}).map((tool) => tool.name),
|
|
).toEqual(["read", "exec"]);
|
|
});
|
|
|
|
it("uses the agent from an agent session key", () => {
|
|
const cfg: OpenClawConfig = {
|
|
agents: {
|
|
list: [
|
|
{
|
|
id: "main",
|
|
experimental: {
|
|
localModelLean: false,
|
|
},
|
|
},
|
|
{
|
|
id: "gemma",
|
|
experimental: {
|
|
localModelLean: true,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
expect(isLocalModelLeanEnabled({ config: cfg, sessionKey: "agent:gemma:main" })).toBe(true);
|
|
expect(
|
|
filterLocalModelLeanTools({
|
|
tools: tools(["read", "browser", "cron", "message", "exec"]),
|
|
config: cfg,
|
|
sessionKey: "agent:gemma:main",
|
|
}).map((tool) => tool.name),
|
|
).toEqual(["read", "exec"]);
|
|
});
|
|
});
|