|
16 | 16 |
|
17 | 17 | --- |
18 | 18 |
|
19 | | -## Overview |
20 | | - |
21 | 19 | BalatroLLM is a bot that uses Large Language Models (LLMs) to play [Balatro](https://www.playbalatro.com/), the popular roguelike poker deck-building game. The bot analyzes game states, makes strategic decisions, and executes actions through the [BalatroBot](https://github.com/coder/balatrobot) client. |
22 | 20 |
|
23 | 21 | The system combines multiple components to make informed decisions: |
24 | 22 |
|
25 | | -- **Strategy templates** (`STRATEGY.md.jinja`) - Define playing style and approach |
| 23 | +- **Strategy templates** (`STRATEGY.md.jinja`) - Define the playing style and approach |
26 | 24 | - **Game state analysis** (`GAMESTATE.md.jinja`) - Current game situation and available options |
27 | 25 | - **Memory system** (`MEMORY.md.jinja`) - Historical context from previous decisions |
28 | 26 | - **Action tools** (`TOOLS.json`) - Available game actions and their parameters |
29 | 27 |
|
30 | | -These components are processed together in a single LLM call, enabling the bot to understand the current situation and choose the optimal action based on its configured strategy. |
31 | | - |
32 | | -## Quick Start |
| 28 | +These components are processed together in a single LLM call, enabling the bot to understand the current situation and perform the optimal tool call based on its configured strategy. |
33 | 29 |
|
34 | | -### Prerequisites |
| 30 | +## 📋 Requirements |
35 | 31 |
|
36 | 32 | - [uv](https://docs.astral.sh/uv/) package manager |
37 | 33 | - Balatro instance with [BalatroBot](https://github.com/coder/balatrobot) mod installed |
38 | 34 |
|
39 | | -### Setup |
| 35 | +> [!IMPORTANT] |
| 36 | +> Setting up Balatro with the BalatroBot mod requires careful configuration. Please refer to the [BalatroBot](https://github.com/coder/balatrobot) documentation and follow the instructions step by step. |
| 37 | +
|
| 38 | +## 📦 Installation |
| 39 | + |
| 40 | +1. Clone the repository |
40 | 41 |
|
41 | 42 | ```bash |
42 | | -# 1. Clone the repository |
43 | 43 | git clone https://github.com/coder/balatrollm.git |
44 | 44 | cd balatrollm |
| 45 | +``` |
45 | 46 |
|
46 | | -# 2. Create and activate environment |
47 | | -uv sync |
48 | | - |
49 | | -# 3. Configure environment |
50 | | -cp .envrc.example .envrc |
51 | | -# edit .envrc with your OpenRouter API key |
| 47 | +2. Create environment and install dependencies |
52 | 48 |
|
53 | | -# 4. Activate environment |
54 | | -source .envrc |
| 49 | +```bash |
| 50 | +uv sync --no-dev |
55 | 51 | ``` |
56 | 52 |
|
57 | | -#### Environment Variables |
58 | | - |
59 | | -**OpenRouter API Key** (provides access to all LLM providers) |
| 53 | +3. Activate environment |
60 | 54 |
|
61 | 55 | ```bash |
62 | | -export OPENROUTER_API_KEY="your-openrouter-api-key" |
| 56 | +source .venv/bin/activate |
63 | 57 | ``` |
64 | 58 |
|
65 | | -Get your API key from: https://openrouter.ai/keys |
| 59 | +> [!TIP] |
| 60 | +> You can use [direnv](https://direnv.net/) to automatically activate the environment when you enter the project directory. The `.envrc.example` file contains an example configuration for direnv. |
66 | 61 |
|
67 | | -The CLI uses sensible defaults for all other configuration: |
68 | 62 |
|
69 | | -- Default model: `openai/gpt-oss-20b` |
70 | | -- Default base URL: `https://openrouter.ai/api/v1` |
71 | | -- Default API key: `OPENROUTER_API_KEY` environment variable |
72 | | -- Default strategy: `default` |
| 63 | +## ⚙️ LLM Configuration |
73 | 64 |
|
74 | | -### Usage |
| 65 | +BalatroLLM performs single requests to an OpenAI-compatible chat/completions endpoint. You need to configure: |
75 | 66 |
|
76 | | -#### Quick Start |
| 67 | +- `--model`: LLM model identifier |
| 68 | +- `--base-url`: OpenAI-compatible API base URL |
| 69 | +- `--api-key`: API key (if required) |
77 | 70 |
|
78 | | -```bash |
79 | | -# 1. Start Balatro with BalatroBot mod (in separate terminal) |
80 | | -./balatro.sh |
| 71 | +The default configuration uses [OpenRouter](https://openrouter.ai/), which provides access to many LLMs: |
81 | 72 |
|
82 | | -# 2. Run the bot with default settings |
83 | | -balatrollm |
84 | | - |
85 | | -# 3. Run with optimizations for different environments |
86 | | -balatrollm --no-screenshot # Headless mode (no screenshots) |
87 | | -balatrollm --use-default-paths # Distributed systems |
88 | | -balatrollm --no-screenshot --use-default-paths # Both optimizations |
89 | | -``` |
| 73 | +- `--model openai/gpt-oss-20b`: Small, fast, and affordable model |
| 74 | +- `--base-url https://openrouter.ai/api/v1`: OpenRouter API base URL |
| 75 | +- `--api-key $OPENROUTER_API_KEY`: It's recommended to export the API key in the `.envrc` file. |
90 | 76 |
|
91 | | -#### `balatrollm` - Command Line Interface |
| 77 | +> [!TIP] |
| 78 | +> After configuring the base URL and API key, you can check the available models by running `balatrollm --list-models` |
92 | 79 |
|
93 | | -```bash |
94 | | -balatrollm --help |
95 | | -``` |
| 80 | +## ⚡ Usage |
96 | 81 |
|
97 | | -``` |
98 | | -usage: balatrollm [-h] [-m MODEL] [-l] [-s STRATEGY] [-u BASE_URL] [-k API_KEY] [-c CONFIG] |
99 | | - [-d RUNS_DIR] [-r RUNS] [-p PORT] [--no-screenshot] [--use-default-paths] |
100 | | - {benchmark} ... |
101 | | -
|
102 | | -LLM-powered Balatro bot |
103 | | -
|
104 | | -positional arguments: |
105 | | - {benchmark} Available commands |
106 | | - benchmark Analyze runs and generate leaderboards |
107 | | -
|
108 | | -options: |
109 | | - -h, --help show this help message and exit |
110 | | - -m, --model MODEL Model name to use from OpenAI-compatible API (default: openai/gpt-oss-20b) |
111 | | - -l, --list-models List available models from OpenAI-compatible API and exit |
112 | | - -s, --strategy STRATEGY |
113 | | - Name of the strategy to use (default: default) |
114 | | - -u, --base-url BASE_URL |
115 | | - OpenAI-compatible API base URL (default: https://openrouter.ai/api/v1) |
116 | | - -k, --api-key API_KEY |
117 | | - API key (default: OPENROUTER_API_KEY env var) |
118 | | - -d, --runs-dir RUNS_DIR |
119 | | - Base directory for storing run data (default: current directory) |
120 | | - -r, --runs RUNS Number of times to run the bot with the same configuration (default: 1) |
121 | | - -p, --port PORT Port for BalatroBot client connection (can specify multiple, default: 12346) |
122 | | - --no-screenshot Disable taking screenshots during gameplay (use for headless mode) |
123 | | - --use-default-paths Use BalatroBot's default storage paths (use for distributed systems) |
124 | | -``` |
| 82 | +The typical workflow to run BalatroLLM is: |
125 | 83 |
|
126 | | -#### `Makefile` - Development Workflow |
| 84 | +1. Start Balatro with the BalatroBot mod: |
127 | 85 |
|
128 | 86 | ```bash |
129 | | -make help |
| 87 | +bash balatro.sh |
130 | 88 | ``` |
131 | 89 |
|
132 | | -``` |
133 | | -BalatroLLM Development Makefile |
134 | | -
|
135 | | -Available targets: |
136 | | - help Show this help message |
137 | | - install Install package dependencies |
138 | | - install-dev Install package with development dependencies |
139 | | - lint Run ruff linter (check only) |
140 | | - lint-fix Run ruff linter with auto-fixes |
141 | | - format Run ruff formatter |
142 | | - typecheck Run type checker |
143 | | - quality Run all code quality checks |
144 | | - test Run tests |
145 | | - test-cov Run tests with coverage report |
146 | | - all Run all code quality checks and tests |
147 | | - clean Clean build artifacts and caches |
148 | | - setup Kill previous instances and start Balatro |
149 | | - teardown Stop Balatro processes |
150 | | - balatrobench Run benchmark for all models and generate analysis |
151 | | -``` |
152 | | - |
153 | | -#### `balatro.sh` - Game Automation |
| 90 | +2. Run the bot, typically with multiple runs using the same configuration: |
154 | 91 |
|
155 | 92 | ```bash |
156 | | -./balatro.sh --help |
| 93 | +balatrollm --runs-per-seed 3 --seed ABCDEFG |
157 | 94 | ``` |
158 | 95 |
|
159 | | -``` |
160 | | -Usage: ./balatro.sh [OPTIONS] |
161 | | - ./balatro.sh -p PORT [OPTIONS] |
162 | | - ./balatro.sh --kill |
163 | | - ./balatro.sh --status |
164 | | -
|
165 | | -Options: |
166 | | - -p, --port PORT Specify port for Balatro instance (can be used multiple times) |
167 | | - Default: 12346 if no port specified |
168 | | - --headless Enable headless mode (sets BALATROBOT_HEADLESS=1) |
169 | | - --fast Enable fast mode (sets BALATROBOT_FAST=1) |
170 | | - --audio Enable audio (disabled by default, sets BALATROBOT_AUDIO=1) |
171 | | - --kill Kill all running Balatro instances and exit |
172 | | - --status Show information about running Balatro instances |
173 | | - -h, --help Show this help message |
174 | | -
|
175 | | -Examples: |
176 | | - ./balatro.sh # Start single instance on default port 12346 |
177 | | - ./balatro.sh -p 12347 # Start single instance on port 12347 |
178 | | - ./balatro.sh -p 12346 -p 12347 # Start two instances on ports 12346 and 12347 |
179 | | - ./balatro.sh --headless --fast # Start with headless and fast mode on default port |
180 | | - ./balatro.sh --audio # Start with audio enabled on default port |
181 | | - ./balatro.sh --kill # Kill all running Balatro instances |
182 | | - ./balatro.sh --status # Show running instances |
183 | | -``` |
| 96 | +3. Generate benchmark reports from the runs: |
184 | 97 |
|
185 | | -## Contributing |
| 98 | +```bash |
| 99 | +balatrobench --models |
| 100 | +``` |
186 | 101 |
|
187 | | -We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on: |
| 102 | +> [!TIP] |
| 103 | +> You can run `bash balatro.sh --help`, `balatrollm --help`, and `balatrobench --help` to see all available options. |
188 | 104 |
|
189 | | -- Setting up the development environment |
190 | | -- Code style and conventions |
191 | | -- Testing guidelines |
192 | | -- Release process |
193 | 105 |
|
194 | | -## License |
| 106 | +## 📚 Documentation |
195 | 107 |
|
196 | | -This project is licensed under the MIT License – see the [LICENSE](LICENSE) file for details. |
| 108 | +https://coder.github.io/balatrollm/ |
0 commit comments