langchain-ai/deepagents · error · ValueError

Duplicate async subagent names: {dupes}

Error message

Duplicate async subagent names: {dupes}

What it means

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.

Source

Thrown at libs/deepagents/deepagents/middleware/async_subagents.py:901

    state_schema = AsyncSubAgentState

    def __init__(
        self,
        *,
        async_subagents: list[AsyncSubAgent],
        system_prompt: str | None = None,
    ) -> None:
        """Initialize the `AsyncSubAgentMiddleware`."""
        super().__init__()
        if not async_subagents:
            msg = "At least one async subagent must be specified"
            raise ValueError(msg)

        names = [a["name"] for a in async_subagents]
        dupes = {n for n in names if names.count(n) > 1}
        if dupes:
            msg = f"Duplicate async subagent names: {dupes}"
            raise ValueError(msg)

        self.tools = _build_async_subagent_tools(async_subagents)

        if system_prompt:
            agents_desc = "\n".join(f"- {a['name']}: {a['description']}" for a in async_subagents)
            self.system_prompt: str | None = system_prompt + "\n\nAvailable async subagent types:\n\n" + agents_desc
        else:
            self.system_prompt = system_prompt

    def wrap_model_call(
        self,
        request: ModelRequest[ContextT],
        handler: Callable[[ModelRequest[ContextT]], ModelResponse[ResponseT]],
    ) -> ModelResponse[ResponseT]:
        """Update the system message to include async subagent instructions."""
        if self.system_prompt is not None:
            new_system_message = append_to_system_message(request.system_message, self.system_prompt)
            return handler(request.override(system_message=new_system_message))

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Rename one of the duplicates to a unique name
  2. Deduplicate the list before constructing the middleware (e.g. by name)
  3. Fix the config source that yields repeated entries

Example fix

// before
async_subagents=[{"name": "worker", ...}, {"name": "worker", ...}]
// after
async_subagents=[{"name": "worker-a", ...}, {"name": "worker-b", ...}]
Defensive patterns

Strategy: validation

Validate before calling

names = [a["name"] for a in async_subagents]
if len(names) != len(set(names)):
    raise ValueError(f"duplicate subagent names: {set(n for n in names if names.count(n) > 1)}")

Prevention

When it happens

Trigger: Passing a list of async_subagents where two or more entries share the same 'name' value.

Common situations: 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.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/8d8227e62d63aecc. Report an issue: GitHub.