def next_acting(
      self,
      game_master: entity_lib.Entity,
      entities: Sequence[entity_lib.Entity],
      log_entry: Mapping[str, Any] | None = None,
      log: list[Mapping[str, Any]] | None = None,
  ) -> tuple[entity_lib.Entity, entity_lib.ActionSpec]:
    """Return the next entity or entities to act."""
    entities_by_name = {
        entity.name: entity for entity in entities
    }
    next_object_name = 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()),
        )
    )
    if log is not None and hasattr(game_master, 'get_last_log'):
      assert hasattr(game_master, 'get_last_log')  # Assertion for pytype
      log_entry['next_acting'] = game_master.get_last_log()
    next_action_spec_string = game_master.act(
        action_spec=entity_lib.ActionSpec(
            call_to_action=self._call_to_next_action_spec.format(
                name=next_object_name),
            output_type=entity_lib.OutputType.NEXT_ACTION_SPEC,
        )
    )
    if log is not None and hasattr(game_master, 'get_last_log'):
      assert hasattr(game_master, 'get_last_log')  # Assertion for pytype
      log_entry['next_action_spec'] = game_master.get_last_log()
    next_action_spec = engine_lib.action_spec_parser(next_action_spec_string)
    return (entities_by_name[next_object_name], next_action_spec)
Return the next entity or entities to act.
concordia/environment/engines/sequential.py