{"record":{"id":"d26fcd7c757d7406","repo":"langchain-ai/deepagents","slug":"rewarmestimate-incremental-cost-self-incremental","errorCode":null,"errorMessage":"RewarmEstimate incremental cost {self.incremental_cost_usd!r} cannot exceed the cold cost {self.cold_cost_usd!r}","messagePattern":"RewarmEstimate incremental cost (.+?) cannot exceed the cold cost (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/cold_cache.py","lineNumber":219,"sourceCode":"            msg = (\n                f\"RewarmEstimate costs must be finite, got \"\n                f\"cold={self.cold_cost_usd!r}, \"\n                f\"incremental={self.incremental_cost_usd!r}\"\n            )\n            raise ValueError(msg)\n        if self.cold_cost_usd < 0 or self.incremental_cost_usd < 0:\n            msg = (\n                f\"RewarmEstimate costs must be non-negative, got \"\n                f\"cold={self.cold_cost_usd!r}, \"\n                f\"incremental={self.incremental_cost_usd!r}\"\n            )\n            raise ValueError(msg)\n        if self.incremental_cost_usd > self.cold_cost_usd:\n            msg = (\n                f\"RewarmEstimate incremental cost {self.incremental_cost_usd!r} \"\n                f\"cannot exceed the cold cost {self.cold_cost_usd!r}\"\n            )\n            raise ValueError(msg)\n\n\n@dataclass(frozen=True, slots=True)\nclass ColdCacheWarning:\n    \"\"\"Validated data needed to render one advisory warning.\n\n    Constructed only after every gate has passed -- a policy resolved, the\n    prefix cleared the provider's cache minimum, and the priced delta reached\n    the configured threshold -- so the modal renders it without re-deciding\n    anything.\n    \"\"\"\n\n    policy: PromptCachePolicy\n    estimate: RewarmEstimate\n    context_tokens: int\n\n    age_seconds: float | None\n    \"\"\"Idle time since the last successful turn.","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/cold_cache.py#L201-L237","documentation":"RewarmEstimate requires incremental_cost_usd <= cold_cost_usd: re-warming a cache can never cost more than a full cold rebuild. If it would, the estimate is inconsistent and the library rejects construction.","triggerScenarios":"Constructing RewarmEstimate(cold_cost_usd=1.0, incremental_cost_usd=1.5), typically because the two estimates came from different scopes, different models, or stale vs refreshed pricing.","commonSituations":"Cold cost computed for a smaller token count than the incremental path, mixing prices from two model versions, or double-counting fees into the incremental estimate.","solutions":["Recompute both estimates from the same token counts and pricing source so incremental <= cold holds.","Clamp the incremental estimate to the cold estimate (min()) if clamping is a defensible approximation for your use case.","Audit which pricing snapshot each number came from and refresh them together."],"exampleFix":"// before\nest = RewarmEstimate(cold_cost_usd=cold_old_pricing, incremental_cost_usd=inc_new_pricing)\n// after\ncold = estimate_cold(tokens, pricing_latest)\ninc = min(estimate_incremental(tokens, pricing_latest), cold)\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)","handlingStrategy":"validation","validationCode":"if inc > cold:\n    raise ValueError(f\"incremental {inc!r} exceeds cold {cold!r}; recheck estimates\")\nest = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)","typeGuard":"def is_valid_cost_pair(cold: float, inc: float) -> bool:\n    return math.isfinite(cold) and math.isfinite(inc) and 0 <= inc <= cold","tryCatchPattern":"try:\n    est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)\nexcept ValueError:\n    est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=min(inc, cold))","preventionTips":["Derive cold and incremental from the same token counts and pricing snapshot","Refresh both estimates together when pricing changes","Sanity-check with a pair validator before construction"],"tags":["validation","dataclass","config"],"backgroundTag":"invalid-cost-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}