agentscope-ai/agentscope · error · ValueError

Duplicate {kind} hub id {hub.hub_id!r}: hub ids must be uniq

Error message

Duplicate {kind} hub id {hub.hub_id!r}: hub ids must be unique so routes address exactly one hub.

What it means

create_app validates that hub ids are unique per kind; two hubs (e.g. channel hubs, session hubs) sharing a hub_id make route addressing ambiguous, so startup fails fast with this ValueError.

Source

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

    Args:
        hubs (`list | None`):
            The hubs passed to :func:`create_app`.
        kind (`str`):
            The hub kind, used in the error message.

    Returns:
        `dict`:
            The hubs keyed by :attr:`HubBase.hub_id`.

    Raises:
        `ValueError`:
            When two hubs of the same kind share an id, which would make
            them indistinguishable in the routes.
    """
    indexed: dict[str, HubBase] = {}
    for hub in hubs or []:
        if hub.hub_id in indexed:
            raise ValueError(
                f"Duplicate {kind} hub id {hub.hub_id!r}: hub ids must be "
                f"unique so routes address exactly one hub.",
            )
        indexed[hub.hub_id] = hub
    return indexed


def create_app(
    storage: StorageBase,
    message_bus: MessageBus,
    workspace_manager: WorkspaceManagerBase,
    knowledge_base_manager: KnowledgeBaseManagerBase | None = None,
    knowledge_parsers: list[ParserBase] | dict[str, ParserBase] | None = None,
    knowledge_chunkers: list[Type[ChunkerBase]] | None = None,
    blob_store: BlobStoreBase | None = None,
    enable_index_worker: bool = True,
    mcp_hubs: list[MCPHubBase] | None = None,
    skill_hubs: list[SkillHubBase] | None = None,

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Give each hub a distinct hub_id when constructing them
  2. Audit the hubs list passed to create_app for default ids ('default') collisions
  3. If only one hub per kind is intended, remove the duplicate

Example fix

# before
app = create_app(hubs=[ChannelHub(...), ChannelHub(...)])  # both 'default'

# after
app = create_app(hubs=[
    ChannelHub(hub_id="slack", ...),
    ChannelHub(hub_id="discord", ...),
])
Defensive patterns

Strategy: validation

Validate before calling

def hub_ids_unique(hubs) -> bool:
    seen = {}
    for h in hubs:
        if h.hub_id in seen:
            return False
        seen[h.hub_id] = h
    return True

Try / catch

try:
    app = create_app(hubs=hubs)
except ValueError as e:
    if "Duplicate" in str(e) and "hub id" in str(e):
        # rename conflicting hubs and retry
        ...

Prevention

When it happens

Trigger: Passing two hubs of the same kind with an identical hub_id to create_app, e.g. two ChannelHubs both defaulting to hub_id='default'.

Common situations: Adding a second hub of a kind without overriding its default hub_id; merging configurations where each section defines its own default hub; copy-pasting hub definitions.

Related errors


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