langchain-ai/deepagents · error · ValueError
RewarmEstimate costs must be finite, got cold={self.cold_cos
Error message
RewarmEstimate costs must be finite, got cold={self.cold_cost_usd!r}, incremental={self.incremental_cost_usd!r} What it means
RewarmEstimate is a frozen dataclass validated in __post_init__ to ensure its two cost fields are finite numbers. This error means cold_cost_usd or incremental_cost_usd was NaN or +/-inf, which would corrupt any downstream cost comparison or budget math. The library fails fast at construction rather than propagating non-finite costs.
Source
Thrown at libs/code/deepagents_code/cold_cache.py:206
"""Enforce the documented finiteness, ordering, and sign invariants.
Raises:
ValueError: When either figure is non-finite or negative, or the
delta exceeds the total it is a part of.
"""
# Checked first, and separately: `NaN` satisfies neither comparison
# 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.View on GitHub (pinned to a1af029e6e)
Solutions
- Check both cost inputs with math.isfinite() before constructing RewarmEstimate and substitute a real estimate for the missing value.
- Fix the upstream pricing/telemetry data source so it no longer yields NaN or infinity.
- If 'unknown cost' must be represented, use None or a separate flag at the call site instead of inf, before the dataclass boundary.
Example fix
// before est = RewarmEstimate(cold_cost_usd=total / count, incremental_cost_usd=0.02) # count==0 -> inf // after import math cold = total / count if count else 0.0 assert math.isfinite(cold), "cold cost estimate not computable" est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=0.02)
Defensive patterns
Strategy: validation
Validate before calling
import math
if not (math.isfinite(cold) and math.isfinite(inc)):
raise ValueError(f"cost estimates must be finite: cold={cold!r}, inc={inc!r}")
est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc) Type guard
def is_finite_cost(v: object) -> bool:
return isinstance(v, (int, float)) and math.isfinite(v) Try / catch
try:
est = RewarmEstimate(cold_cost_usd=cold, incremental_cost_usd=inc)
except ValueError as e:
logger.warning("invalid rewarm estimate: %s", e)
est = None Prevention
- Run math.isfinite() on every cost derived from division or external data
- Never use inf/nan as an 'unknown' sentinel; use None
- Sanitize pricing-table lookups with explicit defaults
When it happens
Trigger: Constructing RewarmEstimate(cold_cost_usd=..., incremental_cost_usd=...) where either value is math.nan, math.inf, or -math.inf (e.g. computed by dividing by zero or from a missing pricing entry).
Common situations: Estimating costs from a pricing table with a missing model entry (0/0 division), loading cached estimates from corrupted JSON, or passing float('inf') as a sentinel for 'unknown cost'.
Related errors
- RewarmEstimate costs must be non-negative, got cold={self.co
- 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/773f80e18c9552f4.
Report an issue: GitHub.