@@ -9,185 +9,106 @@ BalatroLLM is an LLM-powered bot that plays Balatro (a roguelike poker deck-buil
99## Development Commands
1010
1111### Environment Setup
12-
1312``` bash
14- # Install dependencies (including dev dependencies)
1513uv sync --all-extras --group dev
16-
17- # Create environment configuration
1814cp .envrc.example .envrc
1915source .envrc
2016```
2117
2218### LiteLLM Proxy
23-
2419``` bash
25- # Start the LiteLLM proxy server (required before running the bot)
2620litellm --config config/litellm.yaml
2721```
2822
2923### Running the Application
30-
3124``` bash
32- # Run with default settings
33- balatrollm
34-
35- # Run with specific model
36- balatrollm --model groq-qwen3-32b
37-
38- # List available models from proxy
39- balatrollm --list-models
40-
41- # Enable verbose logging
42- balatrollm --verbose
25+ balatrollm # Default settings (cerebras-qwen3-235b)
26+ balatrollm --model groq-qwen3-32b # Specific model
27+ balatrollm --template aggressive # Specific strategy
28+ balatrollm --list-models # List available models
29+ balatrollm --verbose # Enable verbose logging
30+ balatrollm --proxy-url http://localhost:4000 --api-key your-key
4331```
4432
45- ### Development Quality Commands
46-
33+ ### Development
4734``` bash
48- # Run all quality checks
49- make all
50-
51- # Individual quality checks
52- make lint # Run ruff linter (check only)
53- make lint-fix # Run ruff linter with auto-fixes
54- make format # Run ruff formatter
55- make typecheck # Run basedpyright type checker
56-
57- # Development workflow
58- make dev # Quick development check (format + lint + typecheck)
59-
60- # Cleanup
61- make clean # Remove build artifacts and caches
62- ```
63-
64- ### Testing
65-
66- ``` bash
67- # Run tests (using pytest)
68- pytest
69-
70- # Run specific test file
71- pytest tests/test_example.py
35+ make dev # Quick check (format + lint + typecheck)
36+ make all # Complete quality check
37+ make test # Run tests
38+ make test-cov # Run tests with coverage
39+ make clean # Remove build artifacts
40+ make start # Kill previous instances and start LiteLLM + Balatro
7241```
7342
7443## Architecture
7544
76- ### Core Components
77-
78- ** LLMBot (` src/balatrollm/llm.py ` )**
79- - Main bot implementation that orchestrates game play
80- - Manages LiteLLM client connection and model validation
81- - Handles game state analysis and decision making through LLM
82- - Executes actions via BalatroClient integration
83- - Uses Jinja2 templates for prompt generation
84-
85- ** CLI Entry Point (` src/balatrollm/__init__.py ` )**
86- - Command-line interface with argument parsing
87- - Environment variable support for configuration
88- - Proxy connection validation and error handling
89- - Async game execution wrapper
45+ ** LLMBot (` src/balatrollm/llm.py ` )** : Main bot with Config dataclass, TemplateManager integration, LLM decision-making, response history tracking, and BalatroClient integration.
9046
91- ** Template System (` src/balatrollm/templates/ ` )**
92- - ` system.md.jinja ` : Comprehensive Balatro strategy guide and rules
93- - ` game_state.md.jinja ` : Dynamic game state representation for LLM analysis
94- - Templates use Jinja2 with custom filters (e.g., ` from_json ` )
47+ ** CLI Entry Point (` src/balatrollm/__init__.py ` )** : Command-line interface with argument parsing, environment variable support, proxy validation, and async game execution.
9548
96- ** Tools Configuration (` src/balatrollm/tools.json ` )**
97- - OpenAI function calling definitions for different game states
98- - Maps game states (BLIND_SELECT, SELECTING_HAND, SHOP) to available actions
99- - Defines function schemas for LLM tool use
49+ ** Template System (` src/balatrollm/templates/ ` )** : Strategy-based organization:
50+ - ` default/ ` : Conservative strategy (financial discipline)
51+ - ` aggressive/ ` : High-risk, high-reward strategy
10052
101- ### Key Dependencies
53+ Each strategy contains:
54+ - ` STRATEGY.md.jinja ` : Strategy-specific guide
55+ - ` GAMESTATE.md.jinja ` : Game state representation
56+ - ` MEMORY.md.jinja ` : Response history tracking
57+ - ` TOOLS.json ` : Strategy-specific function definitions
10258
103- - ** balatrobot** : Core Balatro game client (from git repository)
104- - ** litellm** : LLM proxy server for multiple providers
105- - ** openai** : OpenAI client for LLM communication
106- - ** jinja2** : Template engine for prompt generation
107- - ** httpx** : HTTP client for proxy health checks
59+ ** Key Dependencies** : balatrobot, litellm, openai, jinja2, httpx
10860
109- ### Game Integration Flow
61+ ** Game Flow** :
62+ 1 . Validate proxy connection and model availability
63+ 2 . Game loop: Get state → Render templates → Send to LLM → Parse response → Execute action
64+ 3 . Handle different states: BLIND_SELECT, SELECTING_HAND, SHOP, ROUND_EVAL
11065
111- 1 . ** Initialization** : Validate LiteLLM proxy connection and model availability
112- 2 . ** Game Loop** :
113- - Get current game state from BalatroClient
114- - Render game state using Jinja2 templates
115- - Send context to LLM with state-specific tools
116- - Parse LLM tool call response
117- - Execute action through BalatroClient
118- 3 . ** State Handling** : Different logic for BLIND_SELECT, SELECTING_HAND, SHOP, ROUND_EVAL states
66+ ** Available Models** (` config/litellm.yaml ` ):
67+ - ** Cerebras** : cerebras-qwen3-235b (default), cerebras-gpt-oss-120b, cerebras-gpt-oss-20b
68+ - ** Groq** : groq-qwen3-32b
69+ - ** Local** : LM Studio integration
11970
120- ### LiteLLM Configuration
71+ ** Environment Variables** :
72+ - ` CEREBRAS_API_KEY ` , ` GROQ_API_KEY `
73+ - ` LITELLM_MODEL ` (default: cerebras-qwen3-235b)
74+ - ` LITELLM_PROXY_URL ` (default: http://localhost:4000 )
75+ - ` LITELLM_API_KEY ` (default: sk-balatrollm-proxy-key)
76+ - ` BALATROLLM_TEMPLATE ` (default: system)
12177
122- The ` config/litellm.yaml ` defines available models:
123- - ** Cerebras** : High-performance cloud inference (gpt-oss-120b, gpt-oss-20b)
124- - ** Groq** : Fast inference with Qwen models
125- - ** Local** : LM Studio integration for development
78+ ## Code Quality
12679
127- Environment variables required:
128- - ` CEREBRAS_API_KEY ` : For Cerebras models
129- - ` GROQ_API_KEY ` : For Groq models
80+ Uses Ruff (linting/formatting), basedpyright (type checking), pytest (testing), conventional commits, and Release Please automation.
13081
131- ## Development Guidelines
132-
133- ### Code Quality
134- - Uses Ruff for linting and formatting with import sorting
135- - Uses basedpyright for type checking in basic mode
136- - Follows conventional commits specification
137- - Automated release process with Release Please
138-
139- ### Project Structure
82+ ## Project Structure
14083
14184```
14285src/balatrollm/
143- ├── __init__.py # CLI entry point and argument parsing
144- ├── llm.py # Core LLMBot implementation
145- ├── tools.json # OpenAI function definitions by game state
146- └── templates/
147- ├── system.md.jinja # Comprehensive game strategy guide
148- └── game_state.md.jinja # Dynamic game state representation
86+ ├── __init__.py # CLI entry point
87+ ├── llm.py # Core LLMBot with Config and TemplateManager
88+ └── templates/ # Strategy-based templates
89+ ├── default/ # Conservative strategy
90+ └── aggressive/ # High-risk strategy
91+ ├── STRATEGY.md.jinja # Strategy guide
92+ ├── GAMESTATE.md.jinja # Game state representation
93+ ├── MEMORY.md.jinja # Response history
94+ └── TOOLS.json # Function definitions
95+
96+ balatro.sh # Game automation script
97+ runs/ # Game execution logs (organized by version/model/strategy)
98+ tests/test_llm.py # Test suite
14999```
150100
151- ### Template System Usage
152-
153- - Templates handle complex game state rendering for LLM context
154- - System template contains extensive Balatro strategy documentation
155- - Game state template dynamically formats current game information
156- - Custom Jinja2 filter ` from_json ` for JSON parsing in templates
157-
158- ### Error Handling Patterns
159-
160- - Proxy connection validation before game start
161- - Model availability checking with fallback suggestions
162- - Graceful keyboard interrupt handling
163- - Comprehensive logging with different verbosity levels
164-
165- ## Dependency Documentation
166-
167- When working with code that uses these dependencies, search their documentation using Context7 MCP server (` --c7 ` flag) with these library IDs:
168-
169- ** Core Dependencies:**
170-
171- - ** balatrobot** : ` /s1m0n38/balatrobot `
172- - ** jinja2** : ` /pallets/jinja `
173- - ** openai** : ` /openai/openai-python `
174- - ** litellm** : ` /berriai/litellm `
175- - ** httpx** : ` /encode/httpx `
101+ ## Context7 Library IDs
176102
177- ** Dev Dependencies:**
103+ ** Core** : ` /s1m0n38/balatrobot ` , ` /pallets/jinja ` , ` /openai/openai-python ` , ` /berriai/litellm ` , ` /encode/httpx `
104+ ** Dev** : ` /detachhead/basedpyright ` , ` /pytest-dev/pytest ` , ` /pytest-dev/pytest-asyncio ` , ` /astral-sh/ruff ` , ` /astral-sh/uv `
178105
179- - ** basedpyright** : ` /detachhead/basedpyright `
180- - ** pytest** : ` /pytest-dev/pytest `
181- - ** pytest-asyncio** : ` /pytest-dev/pytest-asyncio `
182- - ** ruff** : ` /astral-sh/ruff `
183- - ** uv** : ` /astral-sh/uv `
106+ ## Results Tracking
184107
185- ** Usage:** When implementing features or fixing issues related to any of these libraries, use the Context7 MCP server to get up-to-date documentation and code examples.
108+ - ` runs/[version]/[model]/[strategy]/[timestamp]_[deck]_[seed].jsonl `
109+ - JSONL format for performance analysis across models and strategies
186110
187- ## Important Notes
111+ ## Strategy System
188112
189- - The bot currently has LLM decision-making enabled only for SELECTING_HAND state
190- - BLIND_SELECT and SHOP states use hardcoded actions (TODOs indicate future LLM integration)
191- - Game state management relies on BalatroClient state machine
192- - LiteLLM proxy must be running before starting the bot
193- - Response history is maintained for context in subsequent LLM calls
113+ ** Default** (` --template default ` ): Conservative, financially disciplined approach
114+ ** Aggressive** (` --template aggressive ` ): High-risk, high-reward approach with aggressive spending
0 commit comments