langchain-ai/deepagents · error · ValueError

{MAX_MEDIA_BYTES_ENV} must be a positive integer byte count

Error message

{MAX_MEDIA_BYTES_ENV} must be a positive integer byte count

What it means

`max_media_bytes_from_env` parses `DEEPAGENTS_TALON_MAX_MEDIA_BYTES`; when the value cannot be converted with `int()`, it raises this ValueError with a message naming the env var. The function requires a positive integer byte count or falls back to the default.

Source

Thrown at libs/talon/deepagents_talon/channels/base.py:346

    """Return the configured global media cap.

    Args:
        env: Environment variable mapping.

    Returns:
        Maximum media bytes allowed for channel media.

    Raises:
        ValueError: If the configured value is not a positive integer.
    """
    value = env.get(MAX_MEDIA_BYTES_ENV)
    if value is None:
        return DEFAULT_MAX_MEDIA_BYTES
    msg = f"{MAX_MEDIA_BYTES_ENV} must be a positive integer byte count"
    try:
        parsed = int(value)
    except ValueError as error:
        raise ValueError(msg) from error
    if parsed < 1:
        raise ValueError(msg)
    return parsed


def parse_float(value: str | None, default: float) -> float:
    """Parse an optional float value with a default.

    Args:
        value: Raw environment value.
        default: Value returned when `value` is missing.

    Returns:
        Parsed float.

    Raises:
        ValueError: If `value` is not a float.
    """

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Set a plain positive integer of bytes, e.g. `DEEPAGENTS_TALON_MAX_MEDIA_BYTES=1073741824` for 1 GiB.
  2. Remove the variable entirely to use the default (1 GiB).
  3. Catch the ValueError at startup and fail fast with a clear config error.

Example fix

# before
DEEPAGENTS_TALON_MAX_MEDIA_BYTES=1GB

# after
DEEPAGENTS_TALON_MAX_MEDIA_BYTES=1073741824
Defensive patterns

Strategy: validation

Validate before calling

import os, re
raw = os.environ.get('DEEPAGENTS_TALON_MAX_MEDIA_BYTES')
if raw is not None and not re.fullmatch(r'[0-9]+', raw.strip()):
    raise SystemExit('DEEPAGENTS_TALON_MAX_MEDIA_BYTES must be a positive integer byte count')

Try / catch

try:
    cap = max_media_bytes_from_env(os.environ)
except ValueError as exc:
    raise SystemExit(f'invalid media cap config: {exc}') from exc

Prevention

When it happens

Trigger: Setting `DEEPAGENTS_TALON_MAX_MEDIA_BYTES` to a non-numeric string (e.g. `'1GB'`, `'500 MB'`, `''` treated as value, `'10_000'` with unsupported separator in some locales) and calling `max_media_bytes_from_env` from `from_talon_config`.

Common situations: Writing human-readable sizes like `1GB` or `100MiB` instead of raw byte counts; stray whitespace/quotes from .env files; copy-paste with a thousands comma like `1,073,741,824`.

Related errors


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