games.mancala.agent¶
Mancala game agent.
This module defines the Mancala game agent, which uses language models to generate moves and analyze positions in the game.
Classes¶
Agent for playing Mancala using language models. |
Functions¶
|
Ensure input is converted to MancalaState. |
|
Extract move or analysis data from an LLM response. |
Module Contents¶
- class games.mancala.agent.MancalaAgent(config)¶
Bases:
haive.games.framework.base.agent.GameAgent
[haive.games.mancala.config.MancalaConfig
]Agent for playing Mancala using language models.
This agent uses LLMs to generate moves and analyze positions in the Mancala game. It builds a dynamic graph for game flow and uses structured outputs for reliable move generation.
- config¶
Configuration for the Mancala game.
- graph_builder¶
Dynamic graph builder for game flow.
- state_manager¶
Manager for game state transitions.
Initialize the Mancala agent.
- Parameters:
config (haive.games.mancala.config.MancalaConfig) – Configuration for the Mancala game.
- check_game_over(state)¶
Check if the game is over and update state accordingly.
- Parameters:
state (dict | haive.games.mancala.state.MancalaState) – Current game state.
- Returns:
Updated game state as dictionary.
- Return type:
- make_move(state, player)¶
Make a move for the specified player.
This method handles move generation, validation, and state updates. It includes retry logic for invalid moves and fallback to random valid moves if the LLM fails.
- Parameters:
state (haive.games.mancala.state.MancalaState) – Current game state.
player (str) – Player making the move (‘player1’ or ‘player2’).
- Returns:
Updated game state after the move.
- Return type:
- player1_turn(state)¶
Execute player 1’s turn.
- Parameters:
state (dict | haive.games.mancala.state.MancalaState) – Current game state.
- Returns:
Updated game state after player 1’s move as dictionary.
- Return type:
- player2_turn(state)¶
Execute player 2’s turn.
- Parameters:
state (dict | haive.games.mancala.state.MancalaState) – Current game state.
- Returns:
Updated game state after player 2’s move as dictionary.
- Return type:
- run(input_data=None)¶
Run the Mancala game.
- simple_play(state)¶
Simple play logic for fallback mode.
- Parameters:
state (dict | haive.games.mancala.state.MancalaState) – Current game state.
- Returns:
Updated game state as dictionary.
- Return type:
- games.mancala.agent.ensure_game_state(state_input)¶
Ensure input is converted to MancalaState.
- Parameters:
state_input (dict[str, Any] | haive.games.mancala.state.MancalaState | langgraph.types.Command) – Input that could be a dict, MancalaState, or Command.
- Returns:
Properly typed game state.
- Return type:
- games.mancala.agent.extract_data_from_response(response, data_type='move')¶
Extract move or analysis data from an LLM response.