langchain-ai/deepagents · error · ValueError

{key} must be a non-negative integer

Error message

{key} must be a non-negative integer

What it means

ValueError raised by `_env_non_negative_int` in libs/talon/deepagents_talon/data_lifecycle.py when an environment variable used by `cleanup_sensitive_state` cannot be parsed as an int. The raw string is passed to `int()` and a ValueError is chained into this error with the variable key in the message. It guards configuration supplied via the environment.

Source

Thrown at libs/talon/deepagents_talon/data_lifecycle.py:130

    if not root.exists():
        return

    for path in sorted((item for item in root.rglob("*") if item.is_dir()), reverse=True):
        try:
            path.rmdir()
        except OSError:
            continue


def _env_non_negative_int(config: TalonConfig, key: str, default: int) -> int:
    value = config.env.get(key)
    if value is None:
        return default
    try:
        parsed = int(value)
    except ValueError as error:
        msg = f"{key} must be a non-negative integer"
        raise ValueError(msg) from error
    if parsed < 0:
        msg = f"{key} must be a non-negative integer"
        raise ValueError(msg)
    return parsed


def _coerce_utc(value: datetime) -> datetime:
    if value.tzinfo is None:
        return value.replace(tzinfo=UTC)
    return value.astimezone(UTC)

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Set the env var to a plain non-negative integer (e.g. `RETENTION_MINUTES=30`), not '30m'.
  2. If the value has units, convert to the base integer unit yourself before setting it.
  3. Check .env files and shell exports for quotes, spaces, or suffix characters around the number.

Example fix

// before
export CLEANUP_INTERVAL=30m
// after
export CLEANUP_INTERVAL=30
Defensive patterns

Strategy: validation

Validate before calling

raw = os.environ.get("CLEANUP_INTERVAL")
if raw is not None and not raw.strip().lstrip("+").isdecimal():
    raise ValueError(f"CLEANUP_INTERVAL must be a non-negative integer, got {raw!r}")

Try / catch

try:
    cleanup_sensitive_state()
except ValueError as exc:
    logger.error("data lifecycle env config invalid: %s", exc)
    raise SystemExit(f"fix env: {exc}") from exc

Prevention

When it happens

Trigger: Setting a data-lifecycle env var (e.g. a retention/interval setting consumed by `cleanup_sensitive_state`) to a non-numeric string like 'soon', '1h', or '10m' instead of a plain integer.

Common situations: Putting unit suffixes in env vars ('30m', '2h') when the code expects raw integers; typos or accidental quotes/whitespace in .env files; shell exporting '300 seconds'.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/2ad8969c6a3afd99. Report an issue: GitHub.