{"record":{"id":"34dd7243fb9d5d94","repo":"n8n-io/n8n","slug":"toolname-policy-maxchildren-must-be-at-least-1","errorCode":null,"errorMessage":"${toolName} policy.maxChildren must be at least 1","messagePattern":"(.+?) policy\\.maxChildren must be at least 1","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/runtime/tools/delegate-sub-agent-tool.ts","lineNumber":379,"sourceCode":"\nfunction resolveDelegateSubAgentPolicy(\n\tpolicy: DelegateSubAgentPolicy | undefined,\n\ttoolName: string,\n): DelegateSubAgentPolicy {\n\tconst resolvedPolicy = {\n\t\t...policy,\n\t\tmaxChildren: policy?.maxChildren ?? DEFAULT_SUB_AGENT_MAX_CHILDREN,\n\t};\n\n\tif (\n\t\t!Number.isFinite(resolvedPolicy.maxChildren) ||\n\t\t!Number.isInteger(resolvedPolicy.maxChildren)\n\t) {\n\t\tthrow new Error(`${toolName} policy.maxChildren must be a finite positive integer`);\n\t}\n\n\tif (resolvedPolicy.maxChildren < 1) {\n\t\tthrow new Error(`${toolName} policy.maxChildren must be at least 1`);\n\t}\n\n\treturn resolvedPolicy;\n}\n\nconst DELEGATE_SUB_AGENT_TOOL_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;\n\nfunction resolveDelegateSubAgentToolName(name: string | undefined): string {\n\tif (name === undefined) return DELEGATE_SUB_AGENT_TOOL_NAME;\n\tif (!DELEGATE_SUB_AGENT_TOOL_NAME_PATTERN.test(name)) {\n\t\tthrow new Error(\n\t\t\t`Invalid delegate sub-agent tool name \"${name}\": must start with a letter and contain only letters, digits, underscores, and hyphens (max 64 characters)`,\n\t\t);\n\t}\n\treturn name;\n}\n\nconst DEFAULT_DELEGATE_SUB_AGENT_DESCRIPTION =","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/runtime/tools/delegate-sub-agent-tool.ts#L361-L397","documentation":"After confirming `maxChildren` is a finite integer, `resolveDelegateSubAgentPolicy` checks that it is at least 1. Zero or negative values throw. `maxChildren` controls the maximum number of parallel child sub-agent runs; zero would mean no children can ever run, making the delegation tool useless, and negative values are nonsensical.","triggerScenarios":"Calling the delegate sub-agent tool factory with `policy: { maxChildren: 0 }` or `policy: { maxChildren: -3 }`. This happens when a computation produces zero or negative (e.g. `availableSlots - reservedSlots` where reserved exceeds available).","commonSituations":"A dynamic computation of `maxChildren` produced zero (e.g. `totalCapacity - usedCapacity` where all capacity is used). A config field defaulted to 0. A UI let the user set 0 thinking it meant 'unlimited'.","solutions":["Clamp `maxChildren` to at least 1 before passing: `Math.max(1, value)`.","If zero means 'disable delegation', do not create the delegate tool at all rather than passing `maxChildren: 0`.","Add UI/config validation to reject values below 1.","Omit `maxChildren` if the default of 10 is acceptable."],"exampleFix":"// before:\ncreateDelegateSubAgentTool({ policy: { maxChildren: 0 } });\n\n// after:\ncreateDelegateSubAgentTool({ policy: { maxChildren: Math.max(1, computedSlots) } });\n// or if delegation should be disabled when slots are 0, don't create the tool:\nif (availableSlots > 0) {\n  agent.tool(createDelegateSubAgentTool({ policy: { maxChildren: availableSlots } }));\n}","handlingStrategy":"validation","validationCode":"function resolveMaxChildren(value: unknown): number {\n  const n = typeof value === 'number' ? value : 10; // default\n  return Math.max(1, Math.floor(n));\n}\n\ncreateDelegateSubAgentTool({ policy: { maxChildren: resolveMaxChildren(userValue) } });","typeGuard":"function isPositiveInteger(value: unknown): value is number {\n  return typeof value === 'number' && Number.isInteger(value) && value >= 1;\n}","tryCatchPattern":null,"preventionTips":["Clamp maxChildren to at least 1: Math.max(1, value).","If zero means 'disable', conditionally skip creating the delegate tool.","Validate with z.number().int().min(1) at the config boundary."],"tags":["tools","delegate","sub-agent","validation","policy","numeric"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}