{"record":{"id":"1c6eac5911bcfc8b","repo":"langchain-ai/deepagents","slug":"at-least-one-async-subagent-must-be-specified","errorCode":null,"errorMessage":"At least one async subagent must be specified","messagePattern":"At least one async subagent must be specified","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/async_subagents.py","lineNumber":895,"sourceCode":"        ```\n    \"\"\"\n\n    trace_policy = TracePolicy(process_inputs=omit_payload)\n    \"\"\"Omit hook inputs from traces by default; set a `TracePolicy` to override.\"\"\"\n\n    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],","sourceCodeStart":877,"sourceCodeEnd":913,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/async_subagents.py#L877-L913","documentation":"AsyncSubAgentMiddleware requires at least one async subagent; constructing it with an empty list (or empty dict-like) raises this ValueError immediately in __init__. The middleware has nothing to expose to the agent otherwise.","triggerScenarios":"AsyncSubAgentMiddleware(async_subagents=[]) or async_subagents=None; building the list programmatically and it ends up empty at runtime.","commonSituations":"Feature-flagged subagent config resolving to no entries; refactoring that moved subagents elsewhere but left an empty middleware instantiation.","solutions":["Pass at least one async subagent spec","Remove the middleware entirely if no async subagents are needed","Fix the config loading/flag logic that produced an empty list"],"exampleFix":"// before\nAsyncSubAgentMiddleware(async_subagents=[])\n// after\nAsyncSubAgentMiddleware(async_subagents=[{\"name\": \"researcher\", \"url\": \"http://localhost:8123\"}])","handlingStrategy":"validation","validationCode":"if not async_subagents:\n    raise ValueError(\"async_subagents must contain at least one spec (or omit the middleware)\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only register AsyncSubAgentMiddleware when subagent config is non-empty","Assert non-empty list in config-loading code","Use conditional middleware assembly in your agent factory"],"tags":["python","configuration","validation"],"backgroundTag":"empty-required-config","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}