Skip to content

Commit 4e61cb7

Browse files
S1M0N38claude
andcommitted
docs: add comprehensive documentation to strategy system
- Add detailed docstrings to StrategyManager class - Document strategy template loading and rendering methods - Improve error handling documentation - Add comprehensive method parameter and return value documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e93dcf7 commit 4e61cb7

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

src/balatrollm/strategies.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@
88

99

1010
class StrategyManager:
11-
"""Lightweight helper for managing Jinja2 strategy templates."""
11+
"""Lightweight helper for managing Jinja2 strategy templates.
12+
13+
Manages loading and rendering of strategy-specific templates for
14+
game state representation, strategy guidance, and memory management.
15+
16+
Attributes:
17+
strategy_path: Path to the strategy directory containing templates.
18+
jinja_env: Jinja2 environment configured for template rendering.
19+
"""
1220

1321
def __init__(
1422
self, strategy: str, strategies_dir=Path(__file__).parent / "strategies"
1523
):
1624
"""Initialize StrategyManager with a strategy path.
1725
1826
Args:
19-
strategy: name of the strategy
20-
strategies_dir: path to the strategies directory
27+
strategy: Name of the strategy to load.
28+
strategies_dir: Path to the strategies directory
29+
(default: strategies/ relative to this module).
30+
31+
Raises:
32+
FileNotFoundError: If strategy directory is missing required template files.
2133
"""
2234

2335
self.strategy_path = strategies_dir / strategy
@@ -44,25 +56,52 @@ def __init__(
4456
self.jinja_env.filters["from_json"] = json.loads
4557

4658
def render_strategy(self) -> str:
47-
"""Render the strategy template."""
59+
"""Render the strategy template.
60+
61+
Returns:
62+
Rendered strategy guidance content as a string.
63+
"""
4864
template = self.jinja_env.get_template("STRATEGY.md.jinja")
4965
return template.render()
5066

5167
def render_gamestate(self, state_name: str, game_state: dict[str, Any]) -> str:
52-
"""Render the game state template."""
68+
"""Render the game state template.
69+
70+
Args:
71+
state_name: Name of the current game state (e.g., 'BLIND_SELECT').
72+
game_state: Game state dictionary from BalatroClient.
73+
74+
Returns:
75+
Rendered game state representation as a string.
76+
"""
5377
template = self.jinja_env.get_template("GAMESTATE.md.jinja")
5478
return template.render(
5579
state_name=state_name,
5680
game_state=game_state,
5781
)
5882

5983
def render_memory(self, responses: list[Any]) -> str:
60-
"""Render the memory template."""
84+
"""Render the memory template.
85+
86+
Args:
87+
responses: List of previous LLM responses for context.
88+
89+
Returns:
90+
Rendered memory/history content as a string.
91+
"""
6192
template = self.jinja_env.get_template("MEMORY.md.jinja")
6293
return template.render(responses=responses)
6394

6495
def load_tools(self) -> dict[str, Any]:
65-
"""Load tools from the strategy-specific TOOLS.json file."""
96+
"""Load tools from the strategy-specific TOOLS.json file.
97+
98+
Returns:
99+
Dictionary mapping game states to available tool definitions.
100+
101+
Raises:
102+
FileNotFoundError: If TOOLS.json file is missing.
103+
json.JSONDecodeError: If TOOLS.json contains invalid JSON.
104+
"""
66105
tools_file = self.strategy_path / "TOOLS.json"
67106
with open(tools_file) as f:
68107
return json.load(f)

0 commit comments

Comments
 (0)