{"record":{"id":"a69b9669f75e730d","repo":"TauricResearch/TradingAgents","slug":"llm-max-retries-must-be-0-got-n","errorCode":null,"errorMessage":"llm_max_retries must be >= 0, got {n}","messagePattern":"llm_max_retries must be >= 0, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tradingagents/graph/trading_graph.py","lineNumber":61,"sourceCode":"\nlogger = logging.getLogger(__name__)\n\n\ndef _coerce_max_retries(value):\n    \"\"\"Validate an ``llm_max_retries`` value to a non-negative int.\n\n    Accepts an int or a numeric string (env vars arrive as strings). Rejects\n    booleans and negatives loudly so a misconfiguration fails at startup rather\n    than silently disabling retries.\n    \"\"\"\n    if isinstance(value, bool):\n        raise ValueError(f\"llm_max_retries must be an integer, not a boolean: {value!r}\")\n    try:\n        n = int(value)\n    except (TypeError, ValueError) as exc:\n        raise ValueError(f\"llm_max_retries must be an integer, got {value!r}\") from exc\n    if n < 0:\n        raise ValueError(f\"llm_max_retries must be >= 0, got {n}\")\n    return n\n\n\nclass TradingAgentsGraph:\n    \"\"\"Main class that orchestrates the trading agents framework.\"\"\"\n\n    def __init__(\n        self,\n        selected_analysts=(\"market\", \"social\", \"news\", \"fundamentals\"),\n        debug=False,\n        config: dict[str, Any] = None,\n        callbacks: list | None = None,\n    ):\n        \"\"\"Initialize the trading agents graph and components.\n\n        Args:\n            selected_analysts: List of analyst types to include\n            debug: Whether to run in debug mode","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/TauricResearch/TradingAgents/blob/a33fd4c0f134485a43553a2c23a63cb14adbd88f/tradingagents/graph/trading_graph.py#L43-L79","documentation":"ValueError raised by _coerce_max_retries when the value converts to an int but is negative. Retry counts of -1 are meaningless for the LLM retry loop, so a negative value fails at startup — deliberately, so retries are never silently disabled by a bad config.","triggerScenarios":"Passing llm_max_retries=-1 (or '-1' as a string from an env var) to TradingAgentsGraph. int('-1') succeeds, then the n < 0 check raises.","commonSituations":"Using -1 as an 'infinite/disabled' sentinel from other tools' conventions; arithmetic in config scripts that underflows to a negative count; copy-pasted env values.","solutions":["Use 0 to disable retries, or a positive count like 3.","Fix config generation that computes the value arithmetically and can go negative.","Document 0-means-no-retries in your deployment instead of -1."],"exampleFix":"# before\nTradingAgentsGraph(config={**DEFAULT_CONFIG, 'llm_max_retries': -1})\n\n# after\nTradingAgentsGraph(config={**DEFAULT_CONFIG, 'llm_max_retries': 0})  # 0 = no retries","handlingStrategy":"validation","validationCode":"def resolve_max_retries(cfg: dict, default: int = 3) -> int:\n    value = cfg.get('llm_max_retries', default)\n    n = int(value)\n    if n < 0:\n        raise ValueError('use 0 to disable retries, not a negative count')\n    return n","typeGuard":null,"tryCatchPattern":"try:\n    graph = TradingAgentsGraph(config=config)\nexcept ValueError as e:\n    if 'llm_max_retries must be >= 0' in str(e):\n        config['llm_max_retries'] = 0\n        graph = TradingAgentsGraph(config=config)\n    else:\n        raise","preventionTips":["Use 0 (not -1) to disable retries in all your tooling.","Clamp computed retry counts with max(0, n) before passing them in.","Document the 0-means-disabled convention for your team."],"tags":["configuration","validation","retries","startup"],"backgroundTag":null,"analyzedSha":"a33fd4c0f134485a43553a2c23a63cb14adbd88f","analyzedAt":"2026-08-14T19:45:16.920Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}