{"record":{"id":"e7aa6faa8bc073b0","repo":"langchain-ai/deepagents","slug":"max-retries-must-be-an-int-got-type-max-retries","errorCode":null,"errorMessage":"max_retries must be an int, got {type(max_retries).__name__}","messagePattern":"max_retries must be an int, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/model_retry.py","lineNumber":1067,"sourceCode":"            max_retries: Startup fallback for retry attempts after the initial\n                call. `0` disables retries unless the request's runtime-selected\n                model carries a different provider-specific budget.\n            stream_output_is_visible: Whether message-stream chunks emitted by\n                this model reach a user-visible consumer; it decides the\n                `output_may_have_started` supersession flag on retry events.\n                Keep `True` unless the entire nested stream is filtered before\n                rendering.\n\n        Raises:\n            TypeError: If `max_retries` or `stream_output_is_visible` has the\n                wrong type.\n            ValueError: If `max_retries` is negative.\n        \"\"\"\n        # `True >= 0` passes and `range(True + 1)` runs two attempts, so an\n        # unchecked bool reads as a budget of one retry.\n        if isinstance(max_retries, bool):\n            msg = f\"max_retries must be an int, got {type(max_retries).__name__}\"\n            raise TypeError(msg)\n        if max_retries < 0:\n            msg = \"max_retries must be >= 0\"\n            raise ValueError(msg)\n        if not isinstance(stream_output_is_visible, bool):\n            msg = (\n                \"stream_output_is_visible must be a bool, got \"\n                f\"{type(stream_output_is_visible).__name__}\"\n            )\n            raise TypeError(msg)\n        self.max_retries = max_retries\n        self.stream_output_is_visible = stream_output_is_visible\n\n    @staticmethod\n    def _emit_stream_event(request: ModelRequest, event: dict[str, object]) -> None:\n        writer = getattr(getattr(request, \"runtime\", None), \"stream_writer\", None)\n        if writer is None:\n            return\n        try:","sourceCodeStart":1049,"sourceCodeEnd":1085,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/model_retry.py#L1049-L1085","documentation":"The retry wrapper's constructor validates that `max_retries` is a true integer before computing the attempt budget. Because `bool` is an `int` subclass in Python, `True >= 0` would silently pass and `range(True + 1)` would run two attempts, so booleans are rejected explicitly. A `TypeError` is raised naming the actual type received.","triggerScenarios":"Passing `max_retries=True` or `max_retries=False` (e.g. from a loosely-typed config value or a flag misused as a count) when constructing the retry-wrapped model in `__init__`.","commonSituations":"YAML/JSON configs where `true`/`false` is loaded as a bool and fed straight into the model constructor; refactoring a `retry=True` flag into `max_retries`; environment variables parsed with a truthiness shortcut.","solutions":["Pass an explicit integer, e.g. `max_retries=1` instead of `True`","Coerce config values with `int(value)` before constructing, guarding against bools","If the source is a boolean flag, decide the intended count and map it explicitly (True -> 2, False -> 0)"],"exampleFix":"// before\nmodel = RetryModel(inner, max_retries=True)\n// after\nmodel = RetryModel(inner, max_retries=1 if flag else 0)","handlingStrategy":"type-guard","validationCode":"if isinstance(max_retries, bool) or not isinstance(max_retries, int) or max_retries < 0:\n    raise ValueError(f\"max_retries must be a non-negative int, got {max_retries!r}\")","typeGuard":"def is_valid_max_retries(v: object) -> TypeGuard[int]:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 0","tryCatchPattern":null,"preventionTips":["Never pass booleans where a count is expected; map flags to explicit ints","Validate config values at load time, before model construction","Use mypy/pyright strict typing so bool vs int misuse is flagged"],"tags":["python","validation","retry","type-error"],"backgroundTag":"invalid-parameter-type","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}