feat(agents): add per-agent stream params overrides for cache tuning (#17470) (thanks @rrenamed)
This commit is contained in:
@@ -26,6 +26,7 @@ Docs: https://docs.openclaw.ai
|
||||
- Agents/Compaction: pass `agentDir` into manual `/compact` command runs so compaction auth/profile resolution stays scoped to the active agent. (#24133) thanks @Glucksberg.
|
||||
- Agents/Compaction: pass model metadata through the embedded runtime so safeguard summarization can run when `ctx.model` is unavailable, avoiding repeated `"Summary unavailable due to context limits"` fallback summaries. (#3479) Thanks @battman21, @hanxiao and @vincentkoc.
|
||||
- Agents/Compaction: cancel safeguard compaction when summary generation cannot run (missing model/API key or summarization failure), preserving history instead of truncating to fallback `"Summary unavailable"` text. (#10711) Thanks @DukeDeSouth and @vincentkoc.
|
||||
- Agents/Config: support per-agent `params` overrides merged on top of model defaults (including `cacheRetention`) so mixed-traffic agents can tune cache behavior independently. (#17470, #17112) Thanks @rrenamed.
|
||||
- Agents/Overflow: detect additional provider context-overflow error shapes (including `input length` + `max_tokens` exceed-context variants) so failures route through compaction/recovery paths instead of leaking raw provider errors to users. (#9951) Thanks @echoVic and @Glucksberg.
|
||||
- Agents/Overflow: add Chinese context-overflow pattern detection in `isContextOverflowError` so localized provider errors route through overflow recovery paths. (#22855) Thanks @Clawborn.
|
||||
- Agents/Failover: treat HTTP 502/503/504 errors as failover-eligible transient timeouts so fallback chains can switch providers/models during upstream outages instead of retrying the same failing target. (#20999) Thanks @taw0002 and @vincentkoc.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -29,6 +29,8 @@ export type AgentConfig = {
|
||||
};
|
||||
/** Optional per-agent sandbox overrides. */
|
||||
sandbox?: AgentSandboxConfig;
|
||||
/** Optional per-agent stream params (e.g. cacheRetention, temperature). */
|
||||
params?: Record<string, unknown>;
|
||||
tools?: AgentToolsConfig;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user