{"record":{"id":"e48fd6b453cc62c8","repo":"alibaba/spring-ai-alibaba","slug":"maxparalleltools-must-be-at-least-1","errorCode":null,"errorMessage":"maxParallelTools must be at least 1","messagePattern":"maxParallelTools must be at least 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/Builder.java","lineNumber":428,"sourceCode":"\t * @return this builder instance\n\t */\n\tpublic Builder parallelToolExecution(boolean parallel) {\n\t\tthis.parallelToolExecution = parallel;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the maximum number of tools that can execute in parallel.\n\t * <p>\n\t * This limit helps prevent resource exhaustion when many tools are\n\t * called simultaneously. The default is 5.\n\t * @param max the maximum number of parallel tool executions (must be at least 1)\n\t * @return this builder instance\n\t * @throws IllegalArgumentException if max is less than 1\n\t */\n\tpublic Builder maxParallelTools(int max) {\n\t\tif (max < 1) {\n\t\t\tthrow new IllegalArgumentException(\"maxParallelTools must be at least 1\");\n\t\t}\n\t\tthis.maxParallelTools = max;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the timeout for individual tool executions.\n\t * <p>\n\t * If a tool execution exceeds this timeout, it will be cancelled and\n\t * an error will be returned. The default is 5 minutes.\n\t * @param timeout the maximum duration for a single tool execution\n\t * @return this builder instance\n\t * @throws NullPointerException if timeout is null\n\t */\n\tpublic Builder toolExecutionTimeout(Duration timeout) {\n\t\tthis.toolExecutionTimeout = Objects.requireNonNull(timeout, \"timeout cannot be null\");\n\t\treturn this;\n\t}","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/Builder.java#L410-L446","documentation":"Builder.maxParallelTools(int) validates that the requested parallelism is at least 1 and throws IllegalArgumentException otherwise. Parallel tool execution must have a positive bound; 0 or negative values are meaningless.","triggerScenarios":"Calling ReactAgent.builder().maxParallelTools(0) or maxParallelTools(-1) (or a computed value that became 0/negative) before build().","commonSituations":"Deriving parallelism from config (e.g. env var defaulting to 0), off-by-one in computed limits, or disabling parallel tools by setting 0 instead of omitting the setting.","solutions":["Pass a value >= 1 to maxParallelTools.","To disable parallel execution use a different mechanism (e.g. don't enable parallel tools) rather than maxParallelTools(0).","Clamp computed values: Math.max(1, configuredValue)."],"exampleFix":"// before\nint max = Integer.parseInt(cfg.get(\"tool.parallelism\")); // 0\nbuilder.maxParallelTools(max);\n// after\nbuilder.maxParallelTools(Math.max(1, max));","handlingStrategy":"validation","validationCode":"if (configuredMaxParallelTools < 1) throw new IllegalArgumentException(\"maxParallelTools must be >= 1, got \" + configuredMaxParallelTools);","typeGuard":null,"tryCatchPattern":"try { builder.maxParallelTools(n); } catch (IllegalArgumentException e) { builder.maxParallelTools(1); }","preventionTips":["Clamp any config/env-derived parallelism with Math.max(1, value).","Never use 0 to 'disable' parallelism — use the framework's non-parallel default.","Unit-test builder configurations with boundary values."],"tags":["builder-validation","illegal-argument","concurrency"],"backgroundTag":"value-out-of-range","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}