TauricResearch/TradingAgents · error · ValueError

Invalid value for {env_var}: {exc}

Error message

Invalid value for {env_var}: {exc}

What it means

ValueError raised by _apply_env_overrides (tradingagents/default_config.py) as a wrapper around the inner coercion failure: it names exactly which TRADINGAGENTS_* env var could not be parsed. It fires at import time when DEFAULT_CONFIG is built, so a bad env var prevents the process from starting — by design, so unattended runs never run with silently wrong settings.

Source

Thrown at tradingagents/default_config.py:67

            f"expected a boolean ({'/'.join(_BOOL_TRUE + _BOOL_FALSE)}), got {value!r}"
        )
    if isinstance(reference, int) and not isinstance(reference, bool):
        return int(value)
    if isinstance(reference, float):
        return float(value)
    return value


def _apply_env_overrides(config: dict) -> dict:
    """Apply TRADINGAGENTS_* env vars to the config dict in-place."""
    for env_var, key in _ENV_OVERRIDES.items():
        raw = os.environ.get(env_var)
        if raw is None or raw == "":
            continue
        try:
            config[key] = _coerce(raw, config.get(key))
        except ValueError as exc:
            raise ValueError(f"Invalid value for {env_var}: {exc}") from exc
    return config


DEFAULT_CONFIG = _apply_env_overrides({
    "project_dir": os.path.abspath(os.path.join(os.path.dirname(__file__), ".")),
    "results_dir": os.getenv("TRADINGAGENTS_RESULTS_DIR", os.path.join(_TRADINGAGENTS_HOME, "logs")),
    "data_cache_dir": os.getenv("TRADINGAGENTS_CACHE_DIR", os.path.join(_TRADINGAGENTS_HOME, "cache")),
    "memory_log_path": os.getenv("TRADINGAGENTS_MEMORY_LOG_PATH", os.path.join(_TRADINGAGENTS_HOME, "memory", "trading_memory.md")),
    # Optional cap on the number of resolved memory log entries. When set,
    # the oldest resolved entries are pruned once this limit is exceeded.
    # Pending entries are never pruned. None disables rotation entirely.
    "memory_log_max_entries": None,
    # LLM settings
    "llm_provider": "openai",
    "deep_think_llm": "gpt-5.5",
    "quick_think_llm": "gpt-5.4-mini",
    # When None, each provider's client falls back to its own default endpoint
    # (api.openai.com for OpenAI, generativelanguage.googleapis.com for Gemini, ...).

View on GitHub (pinned to a33fd4c0f1)

Solutions

  1. Read the message: it names the env var and the underlying reason — fix that variable's value.
  2. Strip quotes/whitespace from values in your .env or secret manager.
  3. Run a quick startup smoke test (import tradingagents.default_config) in CI to catch env problems before deploy.

Example fix

# before
TRADINGAGENTS_LLM_API_SPACE=abc   # int-typed key

# after
TRADINGAGENTS_LLM_API_SPACE=8     # numeric value matching the default's type
Defensive patterns

Strategy: validation

Validate before calling

import os

_BOOL_KEYS = {'debug', 'quick_think_llm_anthropic'}  # adapt to _ENV_OVERRIDES bool keys

def env_overrides_look_valid(env_overrides: dict[str, str]) -> list[str]:
    problems = []
    for env_var, key in env_overrides.items():
        raw = os.environ.get(env_var)
        if raw and key in _BOOL_KEYS and raw.strip().lower() not in {'true', 'false'}:
            problems.append(f'{env_var}={raw!r} not a boolean')
    return problems

Try / catch

try:
    import tradingagents.default_config
except ValueError as e:
    # message names the env var and cause; fail the deployment
    raise SystemExit(f'bad TRADINGAGENTS_* env var: {e}')

Prevention

When it happens

Trigger: Any TRADINGAGENTS_* env var listed in _ENV_OVERRIDES whose value cannot be coerced to the type of the existing default: a non-'true'/'false' string for a bool key (inner error 28), or a non-numeric string like 'abc' for an int/float key. Empty values are skipped, so the var must be non-empty.

Common situations: Deployments with stale .env files after config keys changed type; CI variables carrying whitespace/quotes; secrets managers injecting unexpected formats like 'true ' or "'true'".

Related errors


AI-assisted analysis of TauricResearch/TradingAgents@a33fd4c0f1 (2026-08-14). Data as JSON: /api/errors/6e9fa2483d48b123. Report an issue: GitHub.