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¶

MancalaAgent

Agent for playing Mancala using language models.

Functions¶

ensure_game_state(state_input)

Ensure input is converted to MancalaState.

extract_data_from_response(response[, data_type])

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:

dict

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:
Returns:

Updated game state after the move.

Return type:

haive.games.mancala.state.MancalaState

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:

dict

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:

dict

run(input_data=None)¶

Run the Mancala game.

Parameters:

input_data (dict[str, Any] | None) – Optional input data for the game.

Returns:

The final game state as a dictionary.

Return type:

dict[str, Any]

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:

dict

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:

MancalaState

games.mancala.agent.extract_data_from_response(response, data_type='move')¶

Extract move or analysis data from an LLM response.

Parameters:
  • response (Any) – The response from the LLM.

  • data_type (str) – Type of data to extract (‘move’ or ‘analysis’).

Returns:

Extracted data dictionary or None.

Return type:

dict[str, Any] | None