#17470: feat(cache): per-agent params for cacheRetention control (#17112)
agents
stale
size: S
Cluster:
Cron Session Enhancements
## Summary
Fixes #17112. No way to set `cacheRetention` per-agent. Low-traffic agents (e.g., cron jobs running every 30 min) waste money on cache writes ($1.25/MTok) that expire before the next request.
## Root Cause
`resolveExtraParams()` only reads from global model defaults (`agents.defaults.models["provider/model"].params`). There is no per-agent override — all agents sharing the same model get identical cache settings.
## Fix
Add optional `params` field to `AgentConfig` and resolve it in `resolveExtraParams()`:
```ts
// types.agents.ts
export type AgentConfig = {
// ...existing fields...
params?: Record<string, unknown>;
};
```
```ts
// extra-params.ts — resolveExtraParams now accepts agentId
const agentConfig = cfg?.agents?.list?.find((a) => a.id === params.agentId);
return Object.assign({}, globalParams, agentConfig?.params);
```
Agent params merge on top of global model defaults. Three files changed, no new dependencies.
**Config example:**
```json
{
"agents": {
"list": [{
"id": "risk-reviewer",
"params": { "cacheRetention": "none" }
}]
}
}
```
## Test plan
- [x] Per-agent params returned when agentId matches
- [x] Agent params merge over global model defaults (agent wins)
- [x] Unmatched agentId returns undefined (no side effects)
## Local Validation
- `pnpm build` ✅
- `pnpm check` (format + tsgo + lint) ✅
- Relevant test suites pass ✅
## Contribution Checklist
- [x] Focused scope — single feature per PR
- [x] Clear "what" + "why" in description
- [x] AI-assisted (Claude) — reviewed and tested by human
- [x] Local validation run (`pnpm build && pnpm check`)
*AI-assisted (Claude). Reviewed and tested by human.*
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds per-agent `params` override support to `resolveExtraParams`, allowing individual agents to customize stream parameters (e.g., `cacheRetention`, `temperature`) that previously could only be set globally per model. Agent-level params merge on top of global model defaults, with agent values winning on conflict.
- Adds optional `params?: Record<string, unknown>` field to `AgentConfig` type
- Extends `resolveExtraParams` and `applyExtraParamsToAgent` with optional `agentId` parameter
- Passes `sessionAgentId` through at the call site in `attempt.ts`
- Three new tests cover match, merge, and no-match scenarios
- Backward-compatible: all new parameters are optional, existing behavior unchanged when `agentId` is not provided
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it's a small, well-scoped additive feature with proper tests and no breaking changes.
- The change is minimal (4 files, ~50 lines of logic), fully backward-compatible (all new parameters are optional), and well-tested. The merge semantics (Object.assign with agent overriding global) are correct and straightforward. The integration point in attempt.ts correctly passes the already-resolved sessionAgentId. No security concerns, no mutation of config objects, and existing call sites don't need updating.
- No files require special attention.
<sub>Last reviewed commit: 8c13172</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#19329: feat: add per-agent compaction and context pruning overrides
by curtismercier · 2026-02-17
79.4%
#14640: feat(agents): support per-agent temperature and maxTokens in agents...
by lailoo · 2026-02-12
78.5%
#22845: Pass agentDir through cron and followup embedded runs
by seilk · 2026-02-21
77.2%
#21646: fix(cron): pass agentDir to runEmbeddedPiAgent for correct auth res...
by zhangjunmengyang · 2026-02-20
76.0%
#22707: fix: pass agentDir to runEmbeddedPiAgent in cron isolated sessions
by mrlerner · 2026-02-21
74.8%
#19328: Fix: preserve modelOverride in agent handler (#5369)
by CodeReclaimers · 2026-02-17
74.5%
#17462: fix(cache): enable cache retention for Google Vertex AI (#15525)
by rrenamed · 2026-02-15
74.4%
#19385: fix: pass authProfileId from cron session to runEmbeddedPiAgent
by gigi-trifle · 2026-02-17
74.2%
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
74.2%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
73.9%