Documentation Index
Fetch the complete documentation index at: https://mintlify.com/salesforce/ai-economist/llms.txt
Use this file to discover all available pages before exploring further.
BaseComponent is the abstract base class for all component implementations in Foundation. Components add dynamics, action spaces, observations, and logging behavior to environments. Every component must subclass BaseComponent and implement its four abstract methods.
Class attributes
Unique string identifier for the component class. Must be non-empty. This name is used to register the component in the component registry.
Optional shorthand category label (e.g.
"Trading", "Building"). Does not need to be unique. Used by BaseEnvironment.get_component and log finalization. Defaults to None.The agent subclass names (strings) that this component applies to. Must be a non-empty list or tuple. If multiple subclasses are listed, none may be a subclass of another.
Names of the non-agent game entities (resources or landmarks) that must be in play for this component to function. May be empty.
Constructor
The
World instance for the environment this component is part of. Exposes world.maps, world.agents, and world.planner.Total number of timesteps per episode. Must be a positive integer.
Scaling factor applied to inventory quantities when generating observations. Accessible via
self.inv_scale. All component instances in an environment share the same value, set by the environment during construction.world argument:
self.n_agents— number of mobile agentsself.resources— list of resource namesself.landmarks— list of landmark namesself.timescale— number of env steps per component step (default1)
Properties
The world object for the environment this component belongs to. Exposes
world.maps, world.agents, and world.planner.Episode length of the environment this component is part of.
The inventory scaling value used when generating observations. Set by the environment at construction time.
Returns
component_type if defined, otherwise falls back to name.Abstract methods
These four methods must be implemented in every concreteBaseComponent subclass.
get_n_actions
agent_cls_name. Called by the environment during agent action-space construction.
Name of the agent class being queried, e.g.
"BasicMobileAgent" or "BasicPlanner".None— this component adds no actions for this agent type.int— a single action subspace with this many (non-NO-OP) actions.listof(str, int)tuples — multiple named action subspaces:[("Tax_0", 10), ("Tax_1", 10), ...].
get_additional_state_fields
agent_cls_name. The returned fields are merged into agent.state and reset to their specified values when the environment resets.
Name of the agent class being queried.
A
{"state_field": reset_value} dictionary. Return an empty dict {} if no extra state is needed for this agent type.component_step
generate_observations
A
{agent.idx: agent_obs_dict} dictionary. Only agents that receive observations from this component need entries. The structure must remain consistent across calls within an episode.Optional override methods
These methods have default implementations and can be overridden for custom behavior.generate_masks
1) or invalid (0). NO-OP actions are always valid and should not be included in the mask.
The default implementation returns all-ones masks (all actions enabled).
Number of completed episodes. Intended for curriculum learning, where actions may be masked or unmasked over training.
A
{agent.idx: mask} dictionary.- For a single action subspace:
maskis a binary NumPy array of lengthn_actions. - For multiple action subspaces:
maskis a{"action_set_name": binary_array}dict.
additional_reset_steps
reset() after state fields have been re-initialized. Use this to reset any internal component state (e.g., counters, trackers). Should not return anything.
get_metrics
A
{"metric_key": scalar_value} dictionary, or None to exclude this component from the metrics report.get_dense_log
None (default) if this component does not produce a dense log.
Reset lifecycle
Thereset() method (not intended for override) coordinates component reset:
- For each agent (mobile agents + planner), calls
get_additional_state_fields(agent.name)and merges the result intoagent.state. - Calls
additional_reset_steps()for component-internal cleanup.
Registration
Components are registered using thecomponent_registry decorator defined at the bottom of base_component.py:
A component registered with
@component_registry.add is only visible in foundation.components if the file defining it is imported in ai_economist/foundation/components/__init__.py.foundation.components from the top-level package: