games.chess.generic_engines¶

Generic chess engines using the new generic player agent system.

This module demonstrates how to use the generic player agent system for chess, providing a clean, type-safe implementation that eliminates hardcoded LLM configurations.

Classes¶

ChessPromptGenerator

Chess-specific prompt generator using the generic system.

Functions¶

create_generic_chess_config_from_example(example_name)

Create chess engines from predefined examples using generics.

create_generic_chess_engines(player_configs)

Create chess engines using the generic system.

create_generic_chess_engines_simple([white_model, ...])

Create chess engines with simple model configurations using generics.

create_role_specific_chess_engines()

Create chess engines with different models per role using generics.

create_typed_chess_engines()

Demonstrate type-safe engine creation using the generic system.

demonstrate_generic_pattern()

Demonstrate how the generic pattern works across different games.

Module Contents¶

class games.chess.generic_engines.ChessPromptGenerator(players)¶

Bases: haive.games.core.agent.generic_player_agent.GenericPromptGenerator[str, str]

Chess-specific prompt generator using the generic system.

Init .

Parameters:

players (GamePlayerIdentifiers[PlayerType, PlayerType2]) – [TODO: Add description]

create_analysis_prompt(player)¶

Create a chess analysis prompt for the specified player.

Parameters:

player (str) – Player color (“white” or “black”)

Returns:

Prompt template for position analysis

Return type:

ChatPromptTemplate

create_move_prompt(player)¶

Create a chess move prompt for the specified player.

Parameters:

player (str) – Player color (“white” or “black”)

Returns:

Prompt template for move generation

Return type:

ChatPromptTemplate

get_analysis_output_model()¶

Get the structured output model for chess analysis.

Return type:

type

get_move_output_model()¶

Get the structured output model for chess moves.

Return type:

type

games.chess.generic_engines.create_generic_chess_config_from_example(example_name, temperature=0.7)¶

Create chess engines from predefined examples using generics.

Parameters:
  • example_name (str) – Name of the example configuration

  • temperature (float) – Temperature for all engines

Returns:

Dictionary of engines

Return type:

dict[str, AugLLMConfig]

Available examples:
  • “anthropic_vs_openai”: Claude vs GPT-4

  • “gpt4_only”: GPT-4 for all roles

  • “claude_only”: Claude for all roles

  • “mixed_providers”: Different provider per role

  • “budget_friendly”: Cost-effective models

games.chess.generic_engines.create_generic_chess_engines(player_configs)¶

Create chess engines using the generic system.

Parameters:

player_configs (dict[str, haive.games.core.agent.player_agent.PlayerAgentConfig]) – Dictionary of role name to player configuration

Returns:

Dictionary of configured engines

Return type:

dict[str, AugLLMConfig]

Example

>>> configs = {
...     "white_player": PlayerAgentConfig(llm_config="gpt-4"),
...     "black_player": PlayerAgentConfig(llm_config="claude-3-opus"),
...     "white_analyzer": PlayerAgentConfig(llm_config="gpt-4"),
...     "black_analyzer": PlayerAgentConfig(llm_config="claude-3-opus"),
... }
>>> engines = create_generic_chess_engines(configs)
games.chess.generic_engines.create_generic_chess_engines_simple(white_model='gpt-4o', black_model='claude-3-5-sonnet-20240620', temperature=0.7, **kwargs)¶

Create chess engines with simple model configurations using generics.

Parameters:
  • white_model (str | haive.core.models.llm.LLMConfig) – Model for white player and analyzer

  • black_model (str | haive.core.models.llm.LLMConfig) – Model for black player and analyzer

  • temperature (float) – Temperature for player engines

  • **kwargs – Additional configuration parameters

Returns:

Dictionary of engines

Return type:

dict[str, AugLLMConfig]

Example

>>> engines = create_generic_chess_engines_simple("gpt-4", "claude-3-opus")
>>> engines = create_generic_chess_engines_simple(
...     "anthropic:claude-3-5-sonnet-20240620",
...     "openai:gpt-4o",
...     temperature=0.8
... )
games.chess.generic_engines.create_role_specific_chess_engines()¶

Create chess engines with different models per role using generics.

This example shows how to use different LLM models for players vs analyzers, demonstrating the flexibility of the generic system.

Returns:

Dictionary of engines

Return type:

dict[str, AugLLMConfig]

games.chess.generic_engines.create_typed_chess_engines()¶

Demonstrate type-safe engine creation using the generic system.

This function shows how the generic system provides compile-time type checking for player identifiers and role names.

Returns:

Dictionary of engines

Return type:

dict[str, AugLLMConfig]

games.chess.generic_engines.demonstrate_generic_pattern()¶

Demonstrate how the generic pattern works across different games.

This function shows how the same generic system can be used for any two-player game with just different player identifiers and prompts.