langchain-ai/deepagents · error · ValueError
RewarmEstimate costs must be non-negative, got cold={self.co
Error message
RewarmEstimate costs must be non-negative, got cold={self.cold_cost_usd!r}, incremental={self.incremental_cost_usd!r} What it means
RewarmEstimate.__post_init__ rejects negative cold_cost_usd or incremental_cost_usd. Costs in USD cannot be negative, so a negative value indicates a sign error, a refund misapplied as a cost, or corrupted data. The library raises immediately to keep cost accounting sane.
Source
Thrown at libs/code/deepagents_code/cold_cache.py:213
# below (`nan < 0` and `nan > nan` are both `False`), so it would slide
# past both guards and reach `format_cost_estimate`, where the
# magnitude arithmetic raises far from the value's real origin.
if not math.isfinite(self.cold_cost_usd) or not math.isfinite(
self.incremental_cost_usd
):
msg = (
f"RewarmEstimate costs must be finite, got "
f"cold={self.cold_cost_usd!r}, "
f"incremental={self.incremental_cost_usd!r}"
)
raise ValueError(msg)
if self.cold_cost_usd < 0 or self.incremental_cost_usd < 0:
msg = (
f"RewarmEstimate costs must be non-negative, got "
f"cold={self.cold_cost_usd!r}, "
f"incremental={self.incremental_cost_usd!r}"
)
raise ValueError(msg)
if self.incremental_cost_usd > self.cold_cost_usd:
msg = (
f"RewarmEstimate incremental cost {self.incremental_cost_usd!r} "
f"cannot exceed the cold cost {self.cold_cost_usd!r}"
)
raise ValueError(msg)
@dataclass(frozen=True, slots=True)
class ColdCacheWarning:
"""Validated data needed to render one advisory warning.
Constructed only after every gate has passed -- a policy resolved, the
prefix cleared the provider's cache minimum, and the priced delta reached
the configured threshold -- so the modal renders it without re-deciding
anything.
"""
View on GitHub (pinned to a1af029e6e)
Solutions
- Compute costs with abs() or verify the subtraction order so both values are >= 0 before constructing RewarmEstimate.
- If a negative number signals 'savings', model that separately (e.g. a savings field) instead of passing it as a cost.
- Validate values at the data-ingestion boundary and log/skip corrupted records instead of feeding them into estimates.
Example fix
// before inc = old_total - new_total # negative when new is cheaper est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc) // after inc = max(0.0, new_total - old_total) est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)
Defensive patterns
Strategy: validation
Validate before calling
if cold < 0 or inc < 0:
raise ValueError(f"costs cannot be negative: cold={cold!r}, inc={inc!r}")
est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc) Type guard
def is_non_negative_number(v: object) -> bool:
return isinstance(v, (int, float)) and not isinstance(v, bool) and v >= 0 Try / catch
try:
est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)
except ValueError:
est = RewarmEstimate(cold_cost_usd=abs(cold), incremental_cost_usd=abs(inc)) Prevention
- Verify subtraction order when computing deltas; use abs() for magnitudes
- Keep 'savings' (signed) separate from 'cost' (non-negative) fields
- Validate cost fields at CSV/JSON ingestion time
When it happens
Trigger: Calling RewarmEstimate(cold_cost_usd=-0.5, ...) or passing a negative incremental_cost_usd, typically from subtracting in the wrong order or negating a delta.
Common situations: Computing incremental cost as (new_total - old_total) when values were swapped, parsing cost columns from a CSV with currency signs, or reusing a signed 'savings' value as a cost.
Related errors
- RewarmEstimate costs must be finite, got cold={self.cold_cos
- RewarmEstimate incremental cost {self.incremental_cost_usd!r
- modes can only be provided when agent is a factory
- models can only be provided when agent is a factory
- -32602
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/085448e963c91a98.
Report an issue: GitHub.