def build(
      self,
      model: language_model.LanguageModel,
      memory_bank: list[str] | associative_memory.AssociativeMemoryBank,
  ) -> entity_agent_with_logging.EntityAgentWithLogging:
    """Build a game master specialized for matrix game decisions.

    Args:
      model: The language model to use for game master.
      memory_bank: provide a memory_bank.

    Returns:
      A game master entity.
    """
    name = self.params.get('name', DEFAULT_NAME)

    player_names = [entity.name for entity in self.entities]

    scenes = self.params.get('scenes', _configure_default_scenes(player_names))
    assert isinstance(scenes, Sequence), 'scenes must be a sequence.'
    if scenes:
      assert isinstance(
          scenes[0], scene_lib.SceneSpec
      ), 'scenes must be a sequence of SceneSpecs.'

    action_to_scores = self.params.get(
        'action_to_scores', _default_action_to_scores
    )
    assert isinstance(
        action_to_scores, Callable), 'action_to_scores must be a callable.'
    scores_to_observation = self.params.get(
        'scores_to_observation', _default_scores_to_observation
    )
    assert isinstance(
        scores_to_observation, Callable), (
            'scores_to_observation must be a callable.')

    instructions = gm_components.instructions.Instructions()

    examples_synchronous = gm_components.instructions.ExamplesSynchronous()

    player_characters = gm_components.instructions.PlayerCharacters(
        player_characters=player_names,
    )

    observation_to_memory = actor_components.observation.ObservationToMemory()

    observation_component_key = (
        actor_components.observation.DEFAULT_OBSERVATION_COMPONENT_KEY
    )
    observation = actor_components.observation.LastNObservations(
        history_length=100,
    )

    display_events_key = 'display_events'
    display_events = gm_components.event_resolution.DisplayEvents(
        model=model,
    )

    make_observation_key = (
        gm_components.make_observation.DEFAULT_MAKE_OBSERVATION_COMPONENT_KEY)
    make_observation = (
        gm_components.make_observation.MakeObservation(
            model=model,
            player_names=player_names,
            components=[
                observation_component_key,
                display_events_key,
            ],
        )
    )

    scene_tracker_key = (
        gm_components.next_game_master.DEFAULT_NEXT_GAME_MASTER_COMPONENT_KEY
    )

    next_actor = gm_components.next_acting.NextActingFromSceneSpec(
        memory_component_key=actor_components.memory.DEFAULT_MEMORY_COMPONENT_KEY,
        scene_tracker_component_key=scene_tracker_key,
    )

    next_action_spec = gm_components.next_acting.NextActionSpecFromSceneSpec(
        memory_component_key=actor_components.memory.DEFAULT_MEMORY_COMPONENT_KEY,
        scene_tracker_component_key=scene_tracker_key,
    )

    payoff_matrix_key = 'payoff_matrix'
    payoff_matrix = gm_components.payoff_matrix.PayoffMatrix(
        model=model,
        acting_player_names=player_names,
        action_to_scores=action_to_scores,
        scores_to_observation=scores_to_observation,
        scene_tracker_component_key=scene_tracker_key,
        verbose=True,
    )

    event_resolution_steps = [
        thought_chains_lib.identity,
    ]

    event_resolution_components = [
        _get_class_name(instructions),
        _get_class_name(examples_synchronous),
        _get_class_name(player_characters),
        actor_components.observation.DEFAULT_OBSERVATION_COMPONENT_KEY,
    ]

    event_resolution = gm_components.event_resolution.EventResolution(
        model=model,
        event_resolution_steps=event_resolution_steps,
        components=event_resolution_components,
    )
    scene_tracker = gm_components.scene_tracker.SceneTracker(
        model=model,
        scenes=scenes,
        observation_component_key=(
            gm_components.make_observation.DEFAULT_MAKE_OBSERVATION_COMPONENT_KEY
        ),
    )

    terminator_key = gm_components.terminate.DEFAULT_TERMINATE_COMPONENT_KEY
    terminator = gm_components.terminate.Terminate()

    components_of_game_master = {
        _get_class_name(instructions): instructions,
        _get_class_name(examples_synchronous): examples_synchronous,
        _get_class_name(player_characters): player_characters,
        scene_tracker_key: scene_tracker,
        terminator_key: terminator,
        _get_class_name(observation_to_memory): observation_to_memory,
        display_events_key: display_events,
        observation_component_key: observation,
        actor_components.memory.DEFAULT_MEMORY_COMPONENT_KEY: (
            actor_components.memory.AssociativeMemory(memory_bank=memory_bank)
        ),
        make_observation_key: make_observation,
        gm_components.next_acting.DEFAULT_NEXT_ACTING_COMPONENT_KEY: next_actor,
        gm_components.next_acting.DEFAULT_NEXT_ACTION_SPEC_COMPONENT_KEY: (
            next_action_spec
        ),
        payoff_matrix_key: payoff_matrix,
        gm_components.switch_act.DEFAULT_RESOLUTION_COMPONENT_KEY: (
            event_resolution
        ),
    }

    component_order = list(components_of_game_master.keys())

    act_component = gm_components.switch_act.SwitchAct(
        model=model,
        entity_names=player_names,
        component_order=component_order,
    )

    game_master = entity_agent_with_logging.EntityAgentWithLogging(
        agent_name=name,
        act_component=act_component,
        context_components=components_of_game_master,
    )

    return game_master
Build a game master specialized for matrix game decisions.

    Args:
      model: The language model to use for game master.
      memory_bank: provide a memory_bank.

    Returns:
      A game master entity.
    
concordia/prefabs/game_master/game_theoretic_and_dramaturgic.py