games.base.factory¶
Factory module for creating game agents.
from typing import Any, Dict This module provides a factory class for creating game agents with standardized workflows and configurations. It simplifies the process of creating new game agents by providing a flexible, composable pattern.
Examples
>>> # Create a new chess agent
>>> chess_agent = GameAgentFactory.create_game_agent(
... name="ChessAgent",
... state_schema=ChessState,
... state_manager=ChessStateManager,
... enable_analysis=True
... )
>>>
>>> # Create a standard workflow
>>> graph = StateGraph()
>>> graph = GameAgentFactory.create_standard_workflow(graph)
- Typical usage:
Use create_game_agent to generate new game agent classes
Use create_standard_workflow to set up game workflows
Customize agents with analysis, custom nodes, and edges
Classes¶
Factory for creating game agents using a flexible, composable pattern. |
Module Contents¶
- class games.base.factory.GameAgentFactory¶
Factory for creating game agents using a flexible, composable pattern.
This factory class provides methods for creating game agents and their workflows. It simplifies the process of creating new game agents by: 1. Generating workflow nodes from a standardized template 2. Using DynamicGraph for simplified graph building 3. Supporting consistent extension patterns for analysis and custom workflows
The factory supports: - Creation of game agent classes with standard methods - Configuration of analysis steps and custom nodes - Flexible workflow definition with conditional edges - Registration of agents with their configs
Examples
>>> # Create a new chess agent >>> chess_agent = GameAgentFactory.create_game_agent( ... name="ChessAgent", ... state_schema=ChessState, ... state_manager=ChessStateManager ... ) >>> >>> # Create an instance with custom config >>> agent = chess_agent(ChessConfig())
- static create_game_agent(name, state_schema, state_manager, player1_name='player1', player2_name='player2', enable_analysis=True, aug_llm_configs=None, custom_nodes=None, custom_edges=None, conditional_edges=None)¶
Create a new game agent class with a complete workflow.
This method generates a new game agent class with all necessary methods and workflow configuration. It creates both the agent class and its corresponding config class.
- Parameters:
name (str) – Name of the agent class.
state_schema (Type[GameState]) – The game state schema class.
state_manager (Type[GameStateManager]) – The game state manager class.
player1_name (str, optional) – Name for player 1. Defaults to “player1”.
player2_name (str, optional) – Name for player 2. Defaults to “player2”.
enable_analysis (bool, optional) – Whether to enable analysis steps. Defaults to True.
aug_llm_configs (Optional[Dict[str, AugLLMConfig]], optional) – LLM configurations. Defaults to None.
custom_nodes (Optional[Dict[str, Callable]], optional) – Custom node functions. Defaults to None.
custom_edges (Optional[List[Dict[str, Any]]], optional) – Custom edges. Defaults to None.
conditional_edges (Optional[Dict[str, Dict[str, Any]]], optional) – Conditional edges. Defaults to None.
- Returns:
A new agent class with all methods and workflow configured.
- Return type:
Type[Agent]
Examples
>>> # Create a chess agent with analysis >>> chess_agent = GameAgentFactory.create_game_agent( ... name="ChessAgent", ... state_schema=ChessState, ... state_manager=ChessStateManager, ... enable_analysis=True, ... aug_llm_configs={ ... "player1": player1_config, ... "player2": player2_config ... } ... )
- static create_standard_workflow(graph, enable_analysis=True)¶
Add a standard game workflow to an existing graph.
This method creates the typical workflow for a turn-based game with two players, optionally including analysis steps. It modifies the provided graph by adding nodes and edges for the standard game flow.
- Parameters:
graph (StateGraph) – The state graph to modify.
enable_analysis (bool, optional) – Whether to include analysis steps. Defaults to True.
- Returns:
The modified graph with standard workflow added.
- Return type:
StateGraph
Examples
>>> # Create a basic graph and add standard workflow >>> graph = StateGraph() >>> graph = GameAgentFactory.create_standard_workflow( ... graph, ... enable_analysis=True ... )