TheDocumentation 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.
ContinuousDoubleAuction component (registry name "ContinuousDoubleAuction", component type "Trade") implements a commodity-exchange-style market. Agents post bids (maximum willingness to pay) and asks (minimum acceptable payment) for any collectible resource in the world. When a bid price is at least as high as an ask price, orders are matched and the trade is executed automatically.
This component applies only to
BasicMobileAgent instances. The planner agent also receives market observations but does not take trading actions.Constructor parameters
Maximum coin amount an agent can bid or ask for one unit of a resource. Sets the price ceiling; the price floor is always
0. Must be >= 1.Labor charged to an agent each time it submits a bid or ask order. Must be
>= 0.Number of environment timesteps an unfilled order remains active before it expires and escrowed funds/resources are returned. Must be
>= 1.Maximum number of simultaneous open orders (bids + asks combined) an agent may hold per resource. Defaults to
order_duration when not set. Must be >= 1.Coin, Labor.
Action space
For every collectible resourceC in the world this component adds two sub-action spaces to each BasicMobileAgent:
| Sub-action name | Size | Meaning |
|---|---|---|
Buy_{C} | 1 + max_bid_ask | Index 0 = no-op; index k = bid k-1 coin for one unit of C |
Sell_{C} | 1 + max_bid_ask | Index 0 = no-op; index k = ask k-1 coin to sell one unit of C |
Order book mechanics
Submitting orders
When an agent bids on resourceC at price p:
pcoin is moved from the agent’s inventory to escrow.- The bid is recorded in
self.bids[C]. order_laboris charged to the agent’s labor endogenous state.
C at price p:
- One unit of
Cis moved from the agent’s inventory to escrow. - The ask is recorded in
self.asks[C]. order_laboris charged.
Matching orders
After all agents act,match_orders() runs the continuous double auction:
- Bids are sorted descending by price, then ascending by age.
- Asks are sorted ascending by price, then descending by age.
- For each valid bid/ask pair where
bid >= ask, a trade is executed:- Price rule: trade price equals the bid price if the bid was placed first; otherwise equals the ask price.
- The resource moves from the seller’s escrow to the buyer’s inventory.
- The buyer’s escrowed coin is consumed; any excess above the trade price is returned to the buyer.
- The seller receives the trade price in their inventory.
Order expiration
remove_expired_orders() runs after matching. Orders that have been open for more than order_duration timesteps are removed and all escrowed funds/resources are returned to their owners.
Observations
Both agents and the planner observe market state. Agents only see bids/asks that they did not themselves submit (i.e., orders they could respond to), plus their own outstanding orders.Agent observations (per resource C)
Exponentially weighted average trade price for resource
C across all agents.Scaled histogram of recent trade prices (length
max_bid_ask + 1). Decays by a factor of 0.995 each timestep.Histogram of open asks from other agents that this agent could bid against.
Histogram of open bids from other agents that this agent could ask against.
Histogram of this agent’s own outstanding asks.
Histogram of this agent’s own outstanding bids.
Planner observations (per resource C)
Same weighted average trade price visible to agents.
Aggregate price history across all agents.
Complete ask histogram across all agents.
Complete bid histogram across all agents.
Action masks
- Sell actions are fully masked if the agent has no inventory of that resource or is at the order limit.
- Buy actions are masked at price levels the agent cannot afford (price > current coin balance) or if the agent is at the order limit.
Metrics
get_metrics() returns per-agent, per-resource trade statistics averaged over the episode:
Number of successful purchases of resource
C by this agent.Average price paid per unit of
C (NaN if no purchases).Average total cost per purchase transaction.
Number of successful sales of resource
C by this agent.Average income per unit of
C sold (NaN if no sales).Total number of trades executed across all resources and agents over the episode.
Dense log
get_dense_log() returns a list — one entry per timestep — of trade lists. Each executed trade is a dict:
Name of the traded resource.
Agent index of the buyer.
Agent index of the seller.
Executed trade price in coin.
Original bid price submitted by the buyer.
Original ask price submitted by the seller.