{"record":{"id":"b5580c82c761d678","repo":"langchain-ai/deepagents","slug":"recursion-limit-must-be-positive","errorCode":null,"errorMessage":"recursion_limit must be positive","messagePattern":"recursion_limit must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/runtime.py","lineNumber":254,"sourceCode":"        cron_store: CronJobStore | None = None,\n        backend: BackendProtocol | None = None,\n        skills: Sequence[str] | None = None,\n        middleware: Sequence[AgentMiddleware[Any, Any, Any]] = (),\n        interrupt_on: Mapping[str, bool | InterruptOnConfig] | None = None,\n        memory: Sequence[str] | None = None,\n        checkpointer: Checkpointer | None = None,\n        include_web_tools: bool = True,\n        recursion_limit: int = DEFAULT_RECURSION_LIMIT,\n        max_retries: int = DEFAULT_MAX_RETRIES,\n        max_continuations: int = DEFAULT_MAX_CONTINUATIONS,\n        env: Mapping[str, str] | None = None,\n    ) -> None:\n        \"\"\"Initialize without constructing the graph.\"\"\"\n        values = os.environ if env is None else env\n        resolved_recursion_limit = _recursion_limit_from_env(values, recursion_limit)\n        if resolved_recursion_limit <= 0:\n            msg = \"recursion_limit must be positive\"\n            raise ValueError(msg)\n        if max_retries < 1:\n            msg = \"max_retries must be at least 1\"\n            raise ValueError(msg)\n        if max_continuations < 0:\n            msg = \"max_continuations cannot be negative\"\n            raise ValueError(msg)\n\n        self.model = model\n        self.tools = tuple(tools)\n        self.system_prompt = system_prompt\n        self.subagents = tuple(subagents) if subagents is not None else None\n        self._has_async_subagents = _has_async_subagents(self.subagents)\n        self.assistant_dir = assistant_dir\n        self.cron_store = cron_store\n        self.env = dict(os.environ if env is None else env)\n        self.backend = backend if backend is not None else _default_backend(self.env)\n        self.skills = tuple(skills) if skills is not None else None\n        self.middleware = tuple(middleware)","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/runtime.py#L236-L272","documentation":"DeepAgentRuntime.__init__ resolves the recursion limit from the explicit argument or the environment (via _recursion_limit_from_env) and raises this ValueError when the resolved value is zero or negative. LangGraph recursion limits must be positive integers, so a non-positive value would make every invocation fail.","triggerScenarios":"Constructing DeepAgentRuntime with recursion_limit <= 0, or with recursion_limit=None while the corresponding env variable is set to 0, a negative number, or a value like '0'/'-5'.","commonSituations":"A deployment env file contains `AGENT_RECURSION_LIMIT=0` under the assumption it means 'unlimited'; a computed default produced 0; a template variable was left unsubstituted and stripped to an empty/invalid number.","solutions":["Pass a positive recursion_limit (e.g. 25) to DeepAgentRuntime","Fix the environment variable that _recursion_limit_from_env reads to a positive integer (e.g. `export AGENT_RECURSION_LIMIT=50`)","Remove the env variable entirely so the built-in default is used"],"exampleFix":"// before\nos.environ[\"AGENT_RECURSION_LIMIT\"] = \"0\"\nruntime = DeepAgentRuntime(...)\n// after\nos.environ[\"AGENT_RECURSION_LIMIT\"] = \"50\"\nruntime = DeepAgentRuntime(...)  # or pass recursion_limit=50 explicitly","handlingStrategy":"validation","validationCode":"import os\n\ndef resolve_limit(env: dict[str, str] | None = None) -> int:\n    raw = (env or os.environ).get(\"AGENT_RECURSION_LIMIT\")\n    value = int(raw) if raw and raw.strip() else 25\n    if value <= 0:\n        raise ValueError(\"AGENT_RECURSION_LIMIT must be a positive integer\")\n    return value\n\nruntime = DeepAgentRuntime(..., recursion_limit=resolve_limit())","typeGuard":"def is_positive_int(v: object) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":null,"preventionTips":["Never encode 'unlimited' as 0 in recursion-limit config; use a large positive number","Validate env-derived integers at config-load time, before constructing the runtime","Keep a documented default (e.g. 25) and only override when necessary"],"tags":["configuration","validation","env"],"backgroundTag":"invalid-config-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}