Unity-Technologies/ml-agents · error · ValueError

There are no '.demo' files in the provided directory.

Error message

There are no '.demo' files in the provided directory.

What it means

When the given path is a directory, get_demo_files lists files ending in '.demo'. If none are found, it raises this ValueError because there is no demonstration data to load. The directory exists but contains no usable demonstration recordings.

Source

Thrown at ml-agents/mlagents/trainers/demo_loader.py:165

    """
    Retrieves the demonstration file(s) from a path.
    :param path: Path of demonstration file or directory.
    :return: List of demonstration files

    Raises errors if |path| is invalid.
    """
    if os.path.isfile(path):
        if not path.endswith(".demo"):
            raise ValueError("The path provided is not a '.demo' file.")
        return [path]
    elif os.path.isdir(path):
        paths = [
            os.path.join(path, name)
            for name in os.listdir(path)
            if name.endswith(".demo")
        ]
        if not paths:
            raise ValueError("There are no '.demo' files in the provided directory.")
        return paths
    else:
        raise FileNotFoundError(
            f"The demonstration file or directory {path} does not exist."
        )


@timed
def load_demonstration(
    file_path: str,
) -> Tuple[BehaviorSpec, List[AgentInfoActionPairProto], int]:
    """
    Loads and parses a demonstration file.
    :param file_path: Location of demonstration file (.demo).
    :return: BrainParameter and list of AgentInfoActionPairProto containing demonstration data.
    """

    # First 32 bytes of file dedicated to meta-data.

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Verify the directory actually contains '.demo' files (ls *.demo) and pass the directory containing them.
  2. Pass the single '.demo' file path directly instead of a directory.
  3. Re-record demonstrations if the recording files were lost or saved elsewhere (check Unity Academy recorder output path).

Example fix

// before
trainer_config.demo_path = "demos/"  # empty directory
// after
trainer_config.demo_path = "demos/recordings/"  # contains *.demo files
Defensive patterns

Strategy: validation

Validate before calling

import glob, os
path = "demos/"
if os.path.isdir(path) and not glob.glob(os.path.join(path, "*.demo")):
    raise ValueError(f"no .demo files in {path}")

Type guard

def dir_has_demo_files(path: str) -> bool:
    import glob, os
    return os.path.isdir(path) and bool(glob.glob(os.path.join(path, "*.demo")))

Try / catch

try:
    demo_spec, pairs, _ = load_demonstration(demo_dir)
except ValueError as e:
    if "no '.demo' files" in str(e):
        logger.error("Point demo_path at a directory containing *.demo files")
        raise SystemExit(1)
    raise

Prevention

When it happens

Trigger: Passing an existing but empty (of '.demo' files) directory as the demo path to load_demonstration, e.g. a directory holding only .meta files, .py files, or checkpoints.

Common situations: Pointing at the wrong folder (e.g. results/ or summaries/) instead of the demo recording folder; demos deleted or moved; Unity recorded demos with a different extension into that directory.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/40881fd883befd95. Report an issue: GitHub.