On this page

Agent inventory pattern๏ƒ

๐ŸŸข Beginner ยท Lesson 39

An agent classifying the library itself - walk md.all and sort every name into callable vocabulary vs types vs errors vs metadata, producing the machine-readable inventory an agent builds before its first bind.

Before you run๏ƒ

Use the Beginner guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.

Run the saved script๏ƒ

python UX_and_AIX_experiences/01_beginner/39_agent_inventory_pattern.py
py -3.14t UX_and_AIX_experiences/01_beginner/39_agent_inventory_pattern.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

md.all, the whole root namespace, issubclass checks

Code๏ƒ

 1"""
 2TIER: beginner (39) - the AIX seat
 3GOAL: An agent classifying the library itself - walk md.__all__ and
 4      sort every name into callable vocabulary vs types vs errors vs
 5      metadata, producing the machine-readable inventory an agent
 6      builds before its first bind.
 7SURFACE EXERCISED: md.__all__, the whole root namespace, issubclass checks
 8"""
 9import melder as md
10
11
12def main() -> None:
13    groups: dict[str, list[str]] = {
14        "errors": [], "enums": [], "classes": [], "functions": [],
15        "metadata": [],
16    }
17    for name in md.__all__:
18        obj = getattr(md, name)
19        if name.startswith("__"):
20            groups["metadata"].append(name)
21        elif isinstance(obj, type) and issubclass(obj, BaseException):
22            groups["errors"].append(name)
23        elif isinstance(obj, type) and hasattr(obj, "__members__"):
24            groups["enums"].append(name)
25        elif isinstance(obj, type):
26            groups["classes"].append(name)
27        else:
28            groups["functions"].append(name)
29
30    for group, names in groups.items():
31        print(f"{group:10s} ({len(names):2d}):", ", ".join(sorted(names)[:6]),
32              "..." if len(names) > 6 else "")
33    assert len(groups["errors"]) == 9
34    assert "scan_bind" in groups["functions"]
35    print("agent inventory complete:", sum(map(len, groups.values())), "names classified")
36
37
38if __name__ == "__main__":
39    main()

Check the outcome๏ƒ

The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.

More beginner examples ยท Level guide