How registries work
Each registry is an instance ofRegistry(base_class). When you decorate a class with @registry.add, the class is stored internally and keyed by its name attribute (case-insensitive). You can then retrieve it with registry.get("ClassName").
Registry API
Constructor
class
The base class that all entries must subclass. Pass
None to skip the subclass check.add
cls in the registry. Returns cls so it can be used as a decorator.
class
required
The class to register. Must be a subclass of
base_class (if set). The class’s name attribute must not contain a dot ("."). Lookup is case-insensitive.get
name matches cls_name (case-insensitive).
str
required
Name of the class to retrieve.
KeyError if no class with that name is registered.
has
True if a class named cls_name (case-insensitive) is in the registry.
str
required
Name to check.
entries
The six registries
The top-levelfoundation package exposes six registries as module attributes:
foundation.scenarios
Registry of BaseEnvironment scenario subclasses. Used to instantiate environments by name via foundation.make_env_instance.
Built-in entries:
foundation.components
Registry of BaseComponent subclasses. The environment looks up and instantiates components from this registry during construction.
Built-in entries:
foundation.agents
Registry of BaseAgent subclasses.
Built-in entries:
foundation.resources
Registry of Resource entity subclasses. Resources can be held in agent inventories and (if collectible=True) exist in the world map.
Built-in entries:
foundation.landmarks
Registry of Landmark entity subclasses. Landmarks exist exclusively in the world grid and are never held in agent inventories.
Built-in entries:
StoneSourceBlock and WoodSourceBlock are auto-generated at import time from each collectible resource in resource_registry.foundation.endogenous
Registry of Endogenous entity subclasses. Endogenous entities represent internal agent state quantities (e.g. effort) that are not physically exchangeable.
Built-in entries:
Registering a custom class
To register a custom component, agent, resource, landmark, or endogenous entity:1
Subclass the base class
Create a class that inherits from the appropriate base (
BaseComponent, BaseAgent, Resource, Landmark, or Endogenous) and set its name attribute to a unique string with no dots.2
Apply the registry decorator
Decorate the class with
@registry.add.3
Ensure the file is imported
For the class to appear in the registry at runtime, the file that defines it must be imported before the registry is queried. For built-in classes, this is handled by the package’s
__init__.py.