Evaluate Large Language Models (LLMs) as Texas Hold'em poker strategists with quantitative metrics, cost analytics, and full game simulation. This project lets you pit different LLMs and AI agents against each other in simulated poker tournaments and analyze their prowess, style, and efficiency.
- Features
- Getting Started
- Project Structure
- Usage Examples
- LLM Configuration
- Metrics and Analysis
- Advanced Analysis of LLM Usage
- Customization & Extensibility
- Contributing
- License
- Texas Hold'em Poker Simulation Engine: Runs realistic full-table poker tournaments with blinds, betting, elimination, and showdowns.
- Multiple AI Strategies:
- Random: Baseline player choosing random actions.
- Hand-based: Player using classic hand-evaluation heuristics.
- LLM-One-Shot: LLM chooses action without intermediate reasoning.
- LLM-Reasoning: LLM provides step-by-step rationale and action.
- LLM Integration: Supports different OpenAI GPT-4* models. Simple to extend to others.
- Metrics & Quantitative Performance: Net chips, volatility, aggression, passivity, and average bet size breakdowns after simulation.
- LLM Usage Analytics: Logs and analyzes LLM calls for cost, latency, efficiency, and outlier detection.
- Highly Modular Design: Easily add new strategies or swap in models.
- Python 3.13+
- OpenAI API Key (Get one here)
- (Recommended) Poetry or just use pip.
Clone the repository:
git clone <repo_url>
cd <repo_dir>
Install dependencies:
- With Poetry:
poetry install - With pip:
Or manually for key packages:
pip install -r requirements.txtpip install polars pyarrow pydantic tqdm python-dotenv openai
Set your OpenAI API key:
- Create a
.envfile in the root directory containing:OPENAI_API_KEY=sk-...
Launch 100 simulated poker games with default settings:
python main.py
You'll see progress bars and output metrics. All LLM usage is automatically logged for analysis.
.
βββ main.py # Entry point: runs simulations, aggregates stats
βββ game.py # Core Hold'em logic: dealing, bet handling, showdowns
βββ player_actions.py # Different player strategies (random, hand-based, LLM, etc.)
βββ constants_and_types.py # All data models, enums, type safety, utilities
βββ llm.py # LLM interface, logging, and usage tracking
βββ metrics.py # Post-game aggregate analysis and pretty tables
βββ analyze_llm_usage.py # Standalone tool to analyze LLM usage logs
βββ llm_usage_log.csv # (Auto-generated) LLM usage, cost, latency for every call
βββ ...
- main.py: Orchestrates multi-game runs and prints results.
- game.py: Implements card dealing, betting, elimination, showdown logic.
- player_actions.py: Defines modular AI/LLM strategies.
- llm.py: Handles OpenAI API calls, cost tracking, and logging.
- metrics.py: Computes chip/bet/aggression metrics.
- analyze_llm_usage.py: Loads
llm_usage_log.csvand creates an efficiency/cost report.
Just execute:
python main.py
- Configurable: Change number of games/rounds at the top of
main.py(n_games,max_rounds). - Default Players: Two "archetypes" (one-shot, reasoning) * each of three models = 6 LLM-based players.
After all games, you'll see tables like:
-------------------------------
Total Net Chips
-------------------------------
one_shot_gpt-4o-mini 10,340 chips
reasoning_gpt-4.1-nano 9,290 chips
... ...
-------------------------------
The total net chips across all games
-------------------------------
Chip Volatility
-------------------------------
one_shot_gpt-4.1-nano 82 chips
reasoning_gpt-4o-mini 175 chips
... ...
-------------------------------
The std dev of chip count across games
Metrics include:
- Net chips
- Chip volatility (consistency)
- Average bet size
- Aggressiveness (% actions as raises)
- Passivity (% folds)
All reported per player type/model.
- Models Supported (default):
gpt-4o-minigpt-4.1-minigpt-4.1-nano
- To swap/add models: Edit the
modelslist insetup_players()inmain.py. - To adjust strategies: See/add in
player_actions.py. For example, swap between LLM, random, or custom strategies. - LLM API Calls: All usage is logged (prompt, completion, tokens, cost, latency).
Pricing (see llm.py):
MODEL_PRICING = {
"gpt-4o-mini": {"input": $0.15, "output": $0.60} per million tokens,
...
}
After the simulation, the following stats are calculated (see metrics.py):
- Total Net Chips: Which player archetype ended up with the most chips.
- Chip Volatility: Standard deviation of chip count per player (lower = more consistent play).
- Average Bet Size: Average chips wagered per action.
- Aggressiveness: % of actions that are raises.
- Passivity: % of actions that are folds.
All shown in readable tabular form for quick comparison.
Every LLM call during play is logged in llm_usage_log.csv. This enables:
python analyze_llm_usage.py
Features:
- Total LLM requests, cost, tokens used
- Usage and cost breakdown by model and by function
- Token/second rates, cost per 1k tokens, average latencies
- Top most expensive requests
- Outlier detection for high-latency/high-cost calls
- Efficient "cost per action" benchmarking for tuning experiments
Sample Output:
LLM Usage Analysis Report
========================
Basic Statistics:
- Total Requests: 600
- Date Range: 2024-06-01 to 2024-06-01
- Total Cost: $0.0152
- Total Tokens: 123,456
- Unique Models: 3
Top Models by Cost:
ββββββββββββββββ¬ββββββββββββββββ¬ββββββββββββ¬βββββββββββββββββββββ¬ββββββββββββββ
β model β total_cost($) β ... β tokens_per_second β ... β
...
- Add New Player Archetypes:
Implement aget_my_strategy_action(...)function inplayer_actions.py, then add it tosetup_players()inmain.py. - Add/Swap LLM Models:
Edit themodelslist insetup_players(), and make sure their pricing is inllm.py. - Tune Game Parameters:
Change starting chips, blinds, or game rules inconstants_and_types.pyandgame.py. - Change Metrics:
Add new metrics or visualizations inmetrics.py.
- Pull requests are welcome!
- Please document new strategies, models, or analysis modules clearly.
- For bugs, suggestions, or feature requests, open an issue or contact the maintainer.
(Specify the license here β e.g., MIT, Apache-2.0, etc., if open source.)
- Heavily inspired by classic research in game-playing AI and GTO strategy.
- Uses OpenAI models and Polars for blazing-fast analytics.
Ready to test your favorite model's poker IQ or investigate the economics of LLM-powered games? Spin up and start experimenting!