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.
BaseAgent is the base class for all agent implementations in Foundation. Agent instances are stateful objects that capture location, inventory, escrow, endogenous variables, and any extra state fields added by components. They also provide a simple API for getting and setting actions across registered action subspaces.
Constructor
Index that uniquely identifies this agent within its environment. Integer indices are used for mobile agents; the planner always uses
"p".If
True, the agent takes one action per registered action subspace each timestep. If False, the agent takes a single action from the combined action space each timestep.Class attribute
Unique string identifier for the agent class. Must be set on each concrete subclass and registered in
agent_registry.Properties
idx
0, 1, 2, …); the planner uses the string "p".
state
[row, col] position in the 2D world grid. Present on BasicMobileAgent; removed on BasicPlanner.Resource quantities held by the agent, keyed by resource name. E.g.
{"Wood": 3, "Stone": 20, "Coin": 1002.83}.Resource quantities reserved for pending obligations, keyed by resource name. Shares the same keys as
inventory.Internal state quantities (e.g.
{"Labor": 30.25}). Only observable by the agent itself.agent.state with additional fields via BaseComponent.get_additional_state_fields.
loc
agent.state["loc"]. The agent’s [row, col] position in the world.
BasicPlanner.loc raises AttributeError because planner agents have no physical location.inventory
agent.state["inventory"]. A dictionary mapping resource names to quantities.
escrow
agent.state["escrow"]. Resources placed into escrow are reserved and cannot be used for other purposes until released. Shares keys with inventory.
See the ContinuousDoubleAuction component for an example of escrow usage: when an agent lists a sell order, the resource moves from inventory to escrow; on a match it transfers to the buyer.
endogenous
agent.state["endogenous"]. Quantities that represent the agent’s internal state, such as accumulated labor effort.
action_spaces
- Single-action mode (
multi_action_mode=False): returns a single integer equal to the total number of available actions (including the universal NO-OP). - Multi-action mode (
multi_action_mode=True): returns an integer array whose i-th element is the size of the i-th action subspace (each subspace includes its own NO-OP).
Inventory management
Agents track resources across two pools —inventory and escrow — which share the same set of resource keys.
inventory_to_escrow
amount of resource from inventory into escrow. The transfer is capped at the available inventory quantity.
Resource name, e.g.
"Wood" or "Coin".Amount to move. Must be non-negative.
Actual amount transferred:
min(inventory[resource], amount).escrow_to_inventory
amount of resource from escrow back into inventory. Capped at the available escrow quantity.
Resource name.
Amount to move. Must be non-negative.
Actual amount transferred:
min(escrow[resource], amount).total_endowment
inventory[resource] + escrow[resource].
Resource name.
Action API
get_component_action
None if the agent does not use that component.
The component name, e.g.
"Build" or "ContinuousDoubleAuction".For components with multiple action subspaces, the subspace name.
set_component_action
component_name to action.
Component name. Must be registered as a subaction for this agent.
Action index or array of action indices.
reset_actions
0). If component is given, resets only that component’s action(s).
parse_actions
- Multi-action mode:
actionsis an array of lengthn_unique_actions. - Single-action mode:
actionsis an integer index into the combined action space, or a{component_name: action}dict.
has_component
True if component_name is registered as an action subspace for this agent.
flatten_masks
{component_name: mask_array} dictionary into a single flat mask vector compatible with action_spaces.
get_random_action
populate_random_actions
Registration methods
These methods are called by the environment during construction and should not be called directly.| Method | Purpose |
|---|---|
register_inventory(resources) | Initializes inventory and escrow keys for all resource names. |
register_endogenous(endogenous) | Initializes endogenous keys for all endogenous entity names. |
register_components(components) | Sets up action subspaces and merges component state fields into agent.state. |
Concrete subclasses
BasicMobileAgent
state includes loc, inventory, escrow, and endogenous. Indexed with integers starting at 0.
BasicPlanner
BasicMobileAgent in two ways:
- No location:
state["loc"]is deleted on construction. Accessingplanner.locraisesAttributeError. - Fixed index: Always indexed as
"p"regardless of theidxargument passed to the constructor.
Defining a custom agent
An agent class registered with
@agent_registry.add is only visible in foundation.agents if the file defining it is imported in ai_economist/foundation/agents/__init__.py.