An LLM-powered economic simulation where AI agents autonomously trade goods in a marketplace using Claude for intelligent decision-making.
This project implements a simple economic marketplace where agents buy and sell commodities (wheat by default). Each agent uses Claude AI to make trading decisions based on their role, personality, current resources, and market conditions. The simulation demonstrates emergent economic behavior as agents interact through a price-discovery mechanism.
- AI-Powered Decision Making: Agents use Claude (Haiku) to analyze market conditions and make buy/sell/hold decisions
- Distinct Agent Personalities: Each agent has a unique personality that influences their trading strategy
- Order Matching System: Automatic matching of buy and sell orders with price discovery
- Trade History Tracking: Complete transaction history for market analysis
- Market Roles: Agents can be buyers, sellers, or market makers
- Configurable Simulation: Customize number of rounds, enable debug mode to see AI reasoning
- Python 3.10+
- Anthropic API key
- Clone the repository:
git clone <repository-url>
cd econsim- Install dependencies:
pip install -r requirements.txt- Set up your API key:
cp .env.example .env
# Edit .env and add your Anthropic API keyGet your API key from: https://console.anthropic.com/settings/keys
Run a 5-round simulation:
python llm_demo.pyRun a 10-round simulation:
python llm_demo.py 10See the prompts sent to Claude and full AI responses:
python llm_demo.py --debugOr combine with custom rounds:
python llm_demo.py 3 --debugRun the basic simulator without LLM (manual orders):
python simulator.py-
Each round, agents receive a market summary containing:
- Current round number
- Last traded price and average recent prices
- Number of pending buy/sell orders
- Their own state (money, inventory, recent trades)
-
Claude analyzes this information along with the agent's:
- Role (buyer/seller/market maker)
- Personality traits
- Transaction history
-
Claude returns a decision in JSON format:
buy: Submit a buy order with quantity and pricesell: Submit a sell order with quantity and pricehold: Wait for better market conditions
The market uses a simple order matching algorithm:
- Buy orders are sorted by price (highest first)
- Sell orders are sorted by price (lowest first)
- Orders are matched when buy price >= sell price
- Trade price is the average of bid and ask prices
- Partial fills are supported
- Agent: Economic agent with money, inventory, personality, and LLM decision-making
- Market: Marketplace that manages orders and executes trades
- Order: Buy or sell order with price and quantity
- Trade: Executed trade between two agents
econsim/
├── simulator.py # Core classes (Agent, Market, Order, Trade)
├── llm_demo.py # LLM-powered simulation runner
├── requirements.txt # Python dependencies
├── .env.example # Environment variable template
└── README.md # This file
=== LLM-Powered Economic Simulator ===
============================================================
ROUND 1
============================================================
Market Conditions:
No trades yet
Agent Decisions:
alice (seller):
State: $100.00, 50 units
Decision: SELL 10 @ $12.50
bob (buyer):
State: $500.00, 0 units
Decision: BUY 15 @ $11.00
------------------------------------------------------------
Executing Trades...
Executed 1 trade(s):
Round 1: bob bought 10 from alice @ $11.75
In simulator.py, you can adjust:
MODEL: Claude model to use (default:claude-3-5-haiku-20241022)MAX_TOKENS: Maximum response length (default: 200)TEMPERATURE: Randomness in decisions (default: 0.7)
Create agents with custom:
- Starting money
- Initial inventory
- Role (buyer/seller/market_maker)
- Personality description