mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:31:22 +00:00
feat(agents): add per-agent stream params overrides for cache tuning (#17470) (thanks @rrenamed)
This commit is contained in:
@@ -61,6 +61,79 @@ describe("resolveExtraParams", () => {
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns per-agent params when agentId matches", () => {
|
||||
const result = resolveExtraParams({
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [
|
||||
{
|
||||
id: "risk-reviewer",
|
||||
params: { cacheRetention: "none" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
provider: "anthropic",
|
||||
modelId: "claude-opus-4-6",
|
||||
agentId: "risk-reviewer",
|
||||
});
|
||||
|
||||
expect(result).toEqual({ cacheRetention: "none" });
|
||||
});
|
||||
|
||||
it("merges per-agent params over global model defaults", () => {
|
||||
const result = resolveExtraParams({
|
||||
cfg: {
|
||||
agents: {
|
||||
defaults: {
|
||||
models: {
|
||||
"anthropic/claude-opus-4-6": {
|
||||
params: {
|
||||
temperature: 0.5,
|
||||
cacheRetention: "long",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
list: [
|
||||
{
|
||||
id: "risk-reviewer",
|
||||
params: { cacheRetention: "none" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
provider: "anthropic",
|
||||
modelId: "claude-opus-4-6",
|
||||
agentId: "risk-reviewer",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
temperature: 0.5,
|
||||
cacheRetention: "none",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores per-agent params when agentId does not match", () => {
|
||||
const result = resolveExtraParams({
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [
|
||||
{
|
||||
id: "risk-reviewer",
|
||||
params: { cacheRetention: "none" },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
provider: "anthropic",
|
||||
modelId: "claude-opus-4-6",
|
||||
agentId: "main",
|
||||
});
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyExtraParamsToAgent", () => {
|
||||
|
||||
@@ -26,10 +26,21 @@ export function resolveExtraParams(params: {
|
||||
cfg: OpenClawConfig | undefined;
|
||||
provider: string;
|
||||
modelId: string;
|
||||
agentId?: string;
|
||||
}): Record<string, unknown> | undefined {
|
||||
const modelKey = `${params.provider}/${params.modelId}`;
|
||||
const modelConfig = params.cfg?.agents?.defaults?.models?.[modelKey];
|
||||
return modelConfig?.params ? { ...modelConfig.params } : undefined;
|
||||
const globalParams = modelConfig?.params ? { ...modelConfig.params } : undefined;
|
||||
const agentParams =
|
||||
params.agentId && params.cfg?.agents?.list
|
||||
? params.cfg.agents.list.find((agent) => agent.id === params.agentId)?.params
|
||||
: undefined;
|
||||
|
||||
if (!globalParams && !agentParams) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return Object.assign({}, globalParams, agentParams);
|
||||
}
|
||||
|
||||
type CacheRetention = "none" | "short" | "long";
|
||||
@@ -496,11 +507,13 @@ export function applyExtraParamsToAgent(
|
||||
modelId: string,
|
||||
extraParamsOverride?: Record<string, unknown>,
|
||||
thinkingLevel?: ThinkLevel,
|
||||
agentId?: string,
|
||||
): void {
|
||||
const extraParams = resolveExtraParams({
|
||||
cfg,
|
||||
provider,
|
||||
modelId,
|
||||
agentId,
|
||||
});
|
||||
const override =
|
||||
extraParamsOverride && Object.keys(extraParamsOverride).length > 0
|
||||
|
||||
@@ -736,6 +736,7 @@ export async function runEmbeddedAttempt(
|
||||
params.modelId,
|
||||
params.streamParams,
|
||||
params.thinkLevel,
|
||||
sessionAgentId,
|
||||
);
|
||||
|
||||
if (cacheTrace) {
|
||||
|
||||
Reference in New Issue
Block a user