langchain-ai/deepagents · error · TypeError
cli_max_retries must be None or a non-negative integer
Error message
cli_max_retries must be None or a non-negative integer
What it means
ServerConfig validates cli_max_retries: it must be None (library default) or a non-negative integer. This ValueError is raised when a value less than 0 is supplied; True/False raise a TypeError one line earlier. Negative retry counts are meaningless, so the constructor rejects them eagerly.
Source
Thrown at libs/code/deepagents_code/_server_config.py:506
# rather than deferring to `FilesystemMiddleware`, which would only
# surface the violation a process boundary away. `_parse_allow_fs_tools_flag`
# still enforces the same rule at the CLI for a friendlier error.
if self.allow_fs_tools is not None:
if len(self.allow_fs_tools) == 0:
msg = "allow_fs_tools must be None or a non-empty list"
raise ValueError(msg)
if "read_file" not in self.allow_fs_tools:
msg = "allow_fs_tools must include 'read_file'"
raise ValueError(msg)
if isinstance(self.rubric_max_iterations, bool):
msg = "rubric_max_iterations must be None or a positive integer"
raise TypeError(msg)
if self.rubric_max_iterations is not None and self.rubric_max_iterations <= 0:
msg = "rubric_max_iterations must be None or a positive integer"
raise ValueError(msg)
if isinstance(self.cli_max_retries, bool):
msg = "cli_max_retries must be None or a non-negative integer"
raise TypeError(msg)
if self.cli_max_retries is not None and self.cli_max_retries < 0:
msg = "cli_max_retries must be None or a non-negative integer"
raise ValueError(msg)
if isinstance(self.recursion_limit, bool):
msg = "recursion_limit must be None or a positive integer"
raise TypeError(msg)
if self.recursion_limit is not None and self.recursion_limit <= 0:
msg = "recursion_limit must be None or a positive integer"
raise ValueError(msg)
# ------------------------------------------------------------------
# Serialization
# ------------------------------------------------------------------
def to_env(self) -> dict[str, str | None]:
"""Serialize this config to a `DEEPAGENTS_CODE_SERVER_*` env-var mapping.
`None` values signal that the variable should be *cleared* from theView on GitHub (pinned to a1af029e6e)
Solutions
- Set cli_max_retries to 0 or a positive integer
- Set cli_max_retries=None to use the library's default retry behavior
- If -1 was meant as 'unlimited', check the docs for how this library expresses unlimited retries and use that value instead
Example fix
// before config = ServerConfig(cli_max_retries=-1) # meant 'unlimited' // after config = ServerConfig(cli_max_retries=None)
Defensive patterns
Strategy: validation
Validate before calling
def validate_cli_max_retries(v):
if isinstance(v, bool):
raise TypeError("cli_max_retries must be None or a non-negative integer")
if v is not None and v < 0:
raise ValueError("cli_max_retries must be None or a non-negative integer") Type guard
def is_valid_cli_max_retries(v) -> bool:
return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 0) Try / catch
try:
config = ServerConfig(cli_max_retries=value)
except (TypeError, ValueError) as e:
if "cli_max_retries" in str(e):
config = ServerConfig(cli_max_retries=None) # library default
else:
raise Prevention
- Don't use -1 as an 'unlimited' sentinel — this field uses None for defaults
- Clamp with max(0, v) when computing retries from a budget
- Validate CLI/env-provided retry counts before passing them into ServerConfig
When it happens
Trigger: ServerConfig(cli_max_retries=-1) or any negative int. The same message appears at two raise sites (lines 506 and 509, errors 48 and 49) covering the non-negative check.
Common situations: Computing retries as base - consumed and going negative; importing a config from another tool where -1 means 'infinite retries' (the opposite convention); misconfiguring an env var like CLI_MAX_RETRIES=-1.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- rubric_max_iterations must be None or a positive integer
- allow_fs_tools must include 'read_file'
- Could not parse embedded resource block. Block expected eith
- question text must not be blank
- choice has a blank 'value': {choice!r}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/da6229997452fb16.
Report an issue: GitHub.