def next_acting(
      self,
      game_master: entity_lib.Entity,
      entities: Sequence[entity_lib.Entity],
  ) -> tuple[Sequence[entity_lib.Entity],
             entity_lib.ActionSpec]:  # pytype: disable=signature-mismatch
    """Return the next entity or entities to act."""
    entities_by_name = {
        entity.name: entity for entity in entities
    }
    next_object_names_string = game_master.act(
        action_spec=entity_lib.ActionSpec(
            call_to_action=self._call_to_next_acting,
            output_type=entity_lib.OutputType.NEXT_ACTING,
            options=tuple(entities_by_name.keys()),
        )
    )
    next_entity_names = next_object_names_string.split(',')
    next_action_spec_string = game_master.act(
        action_spec=entity_lib.ActionSpec(
            call_to_action=self._call_to_next_action_spec.format(
                name=self._call_to_next_action_spec),
            output_type=entity_lib.OutputType.NEXT_ACTION_SPEC,
            options=[action_type.name for action_type
                     in entity_lib.PLAYER_ACTION_TYPES],
        )
    )
    next_action_spec = engine_lib.action_spec_parser(next_action_spec_string)
    return (
        [entities_by_name[entity_name] for entity_name in next_entity_names],
        next_action_spec,
    )
Return the next entity or entities to act.
concordia/environment/engines/asynchronous.py