{"record":{"id":"8d8227e62d63aecc","repo":"langchain-ai/deepagents","slug":"duplicate-async-subagent-names-dupes","errorCode":null,"errorMessage":"Duplicate async subagent names: {dupes}","messagePattern":"Duplicate async subagent names: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/async_subagents.py","lineNumber":901,"sourceCode":"    state_schema = AsyncSubAgentState\n\n    def __init__(\n        self,\n        *,\n        async_subagents: list[AsyncSubAgent],\n        system_prompt: str | None = None,\n    ) -> None:\n        \"\"\"Initialize the `AsyncSubAgentMiddleware`.\"\"\"\n        super().__init__()\n        if not async_subagents:\n            msg = \"At least one async subagent must be specified\"\n            raise ValueError(msg)\n\n        names = [a[\"name\"] for a in async_subagents]\n        dupes = {n for n in names if names.count(n) > 1}\n        if dupes:\n            msg = f\"Duplicate async subagent names: {dupes}\"\n            raise ValueError(msg)\n\n        self.tools = _build_async_subagent_tools(async_subagents)\n\n        if system_prompt:\n            agents_desc = \"\\n\".join(f\"- {a['name']}: {a['description']}\" for a in async_subagents)\n            self.system_prompt: str | None = system_prompt + \"\\n\\nAvailable async subagent types:\\n\\n\" + agents_desc\n        else:\n            self.system_prompt = system_prompt\n\n    def wrap_model_call(\n        self,\n        request: ModelRequest[ContextT],\n        handler: Callable[[ModelRequest[ContextT]], ModelResponse[ResponseT]],\n    ) -> ModelResponse[ResponseT]:\n        \"\"\"Update the system message to include async subagent instructions.\"\"\"\n        if self.system_prompt is not None:\n            new_system_message = append_to_system_message(request.system_message, self.system_prompt)\n            return handler(request.override(system_message=new_system_message))","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/async_subagents.py#L883-L919","documentation":"AsyncSubAgentMiddleware rejects duplicate subagent names in __init__ because names are the lookup keys for specs and tools; duplicates would make agent resolution ambiguous. The error lists the offending duplicated names as a set.","triggerScenarios":"Passing a list of async_subagents where two or more entries share the same 'name' value.","commonSituations":"Merging subagent lists from config files/env where the same agent was appended twice; copy-paste of a spec entry without renaming; programmatic list building with a loop bug.","solutions":["Rename one of the duplicates to a unique name","Deduplicate the list before constructing the middleware (e.g. by name)","Fix the config source that yields repeated entries"],"exampleFix":"// before\nasync_subagents=[{\"name\": \"worker\", ...}, {\"name\": \"worker\", ...}]\n// after\nasync_subagents=[{\"name\": \"worker-a\", ...}, {\"name\": \"worker-b\", ...}]","handlingStrategy":"validation","validationCode":"names = [a[\"name\"] for a in async_subagents]\nif len(names) != len(set(names)):\n    raise ValueError(f\"duplicate subagent names: {set(n for n in names if names.count(n) > 1)}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate specs by name when merging config sources","Adopt a naming convention reviewed at config load","Add a unit test asserting unique subagent names"],"tags":["python","configuration","validation"],"backgroundTag":"duplicate-name-config","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}