agentscope-ai/agentscope · error · AttributeError

module {__name__!r} has no attribute {name!r}

Error message

module {__name__!r} has no attribute {name!r}

What it means

The agentscope.app.rag package defines a module-level __getattr__ for lazy exports (currently only 'run_worker'). Any other attribute access on the package that is not in __all__ raises this AttributeError. It is the standard Python lazy-import pattern, so seeing it means you imported a name that the package genuinely does not export (or renamed/removed in this version).

Source

Thrown at src/agentscope/app/rag/__init__.py:76

    pay the import cost on first access.

    Args:
        name (`str`):
            The attribute name requested by the importer.

    Returns:
        `object`:
            The resolved attribute value.

    Raises:
        `AttributeError`:
            When ``name`` is not exposed by this package.
    """
    if name == "run_worker":
        from .index_worker import run_worker as _run_worker

        return _run_worker
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


__all__ = [
    "AsyncReadable",
    "BlobStoreBase",
    "CollectionPerKbManager",
    "DimensionPolicy",
    "DimensionPolicyError",
    "DimensionPolicyKind",
    "KnowledgeBaseError",
    "KnowledgeBaseManagerBase",
    "KnowledgeBaseNotFoundError",
    "LocalBlobStore",
    "S3BlobStore",
    "run_worker",
]

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Check agentscope/app/rag/__init__.py's __all__ for the names actually exported and import from there
  2. If the symbol lives in a submodule, import it directly, e.g. from agentscope.app.rag.blob_store import LocalBlobStore
  3. If it was renamed in a release, migrate to the new name from the changelog
  4. For run_worker, the lazy import only works as agentscope.app.rag.run_worker

Example fix

# before
from agentscope.app.rag import LocalBlobStore  # AttributeError

# after
from agentscope.app.rag.blob_store import LocalBlobStore
Defensive patterns

Strategy: type-guard

Validate before calling

import agentscope.app.rag as rag
name = 'run_worker'
if name not in rag.__all__ and name != 'run_worker':
    raise ImportError(f'{name} is not exported by agentscope.app.rag')

Type guard

import agentscope.app.rag as rag

def rag_exports(name: str) -> bool:
    return name in rag.__all__ or name == 'run_worker'

Try / catch

try:
    from agentscope.app.rag import run_worker
except AttributeError:
    # name genuinely not exported; check __all__ or import from submodule
    raise

Prevention

When it happens

Trigger: Doing 'from agentscope.app.rag import SomeName' or 'agentscope.app.rag.SomeName' where SomeName is not run_worker and not in the package's __all__; common with renamed classes or names that live in submodules (e.g. agentscope.app.rag.blob_store.LocalBlobStore) rather than the top-level package.

Common situations: Upgrading agentscope after a RAG API refactor renamed/moved symbols; IDE autocompleting a submodule attribute; copy-pasting imports from older docs or examples.

Related errors


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