agentscope-ai/agentscope · error · ValueError

Duplicate sub_agent_template type(s): {duplicates}

Error message

Duplicate sub_agent_template type(s): {duplicates}

What it means

create_app builds a mapping of custom sub-agent templates keyed by their type string; duplicate types would silently shadow one template, so configuration collects the duplicates into a set and raises ValueError.

Source

Thrown at src/agentscope/app/_app.py:373

        app.state.knowledge_parsers = knowledge_parsers
        app.state.knowledge_chunkers = knowledge_chunkers
        app.state.blob_store = blob_store
    app.state.enable_index_worker = (
        enable_index_worker and knowledge_base_manager is not None
    )
    app.state.enable_channel_worker = enable_channel_worker

    # Validate custom sub-agent templates for duplicate types and store in
    #  app.state
    templates = custom_subagent_templates or []
    seen_types: set[str] = set()
    duplicates: set[str] = set()
    for t in templates:
        if t.type in seen_types:
            duplicates.add(t.type)
        seen_types.add(t.type)
    if duplicates:
        raise ValueError(
            f"Duplicate sub_agent_template type(s): {duplicates}",
        )
    app.state.custom_subagent_templates = {t.type: t for t in templates}

    # Built-in routers
    for router in (
        agent_router,
        chat_router,
        credential_router,
        health_router,
        hub_router,
        knowledge_base_router,
        mcp_router,
        schedule_router,
        session_router,
        skill_router,
        workspace_router,
        model_router,

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Give each SubAgentTemplate a unique type string
  2. Deduplicate the templates list before passing it to create_app
  3. If templates come from config, validate type uniqueness at config load time

Example fix

# before
templates = [
    SubAgentTemplate(type="coder", ...),
    SubAgentTemplate(type="coder", ...),
]

# after
templates = [
    SubAgentTemplate(type="coder", ...),
    SubAgentTemplate(type="reviewer", ...),
]
Defensive patterns

Strategy: validation

Validate before calling

def template_types_unique(templates) -> bool:
    types = [t.type for t in templates]
    return len(types) == len(set(types))

Try / catch

try:
    app = create_app(...)
except ValueError as e:
    if "Duplicate sub_agent_template" in str(e):
        dedupe = {t.type: t for t in templates}
        templates = list(dedupe.values())
        app = create_app(...)

Prevention

When it happens

Trigger: Passing multiple SubAgentTemplate objects with the same .type to create_app, e.g. two templates both named 'coder'.

Common situations: Dynamically generating templates from config files where types collide; copy-pasting a template and forgetting to change its type; merging template lists from multiple modules.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/6782285da8c0366e. Report an issue: GitHub.