class_docstr: A CompositeAgent is a group of agents in the same hierarchy level.
  In a CompositeAgent, each agent may take the role of either a controller or an observer.
  Each agent that is defined as observer, gets observations from the environment.
  Each agent that is defined as controller, can potentially also control the environment, in addition to observing it.
  There are several ways to decide on the action from different controller agents:
  1. Ensemble -
      - Take the majority vote (discrete controls)
      - Take the mean action (continuous controls)
      - Round robin between the agents (discrete/continuous)
  2. Skills -
      - At each step a single agent decides (Chosen by the uppoer hierarchy controlling agent)
  
  A CompositeAgent can be controlled using one of the following methods (ActionSpaces):
  1. Goals (in terms of measurements, observation, embedding or a change in those values)
  2. Agent Selection (skills) / Discrete action space.
  3. Attention (a subset of the real environment observation / action space)
class_docstr_tok: ["A","CompositeAgent","is","a","group","of","agents","in","the","same","hierarchy","level",".","In","a","CompositeAgent",",","each","agent","may","take","the","role","of","either","a","controller","or","an","observer",".","Each","agent","that","is","defined","as","observer",",","gets","observations","from","the","environment",".","Each","agent","that","is","defined","as","controller",",","can","potentially","also","control","the","environment",",","in","addition","to","observing","it",".","There","are","several","ways","to","decide","on","the","action","from","different","controller","agents",":","1",".","Ensemble","-","-","Take","the","majority","vote","(","discrete","controls",")","-","Take","the","mean","action","(","continuous","controls",")","-","Round","robin","between","the","agents","(","discrete\/continuous",")","2",".","Skills","-","-","At","each","step","a","single","agent","decides","(","Chosen","by","the","uppoer","hierarchy","controlling","agent",")","A","CompositeAgent","can","be","controlled","using","one","of","the","following","methods","(","ActionSpaces",")",":","1",".","Goals","(","in","terms","of","measurements",",","observation",",","embedding","or","a","change","in","those","values",")","2",".","Agent","Selection","(","skills",")","\/","Discrete","action","space",".","3",".","Attention","(","a","subset","of","the","real","environment","observation","\/","action","space",")"]
docstr: Construct an agent group
  :param agents_parameters: a list of presets describing each one of the agents in the group
  :param decision_policy: the decision policy of the group which describes how actions are consolidated
  :param out_action_space: the type of action space that is used by this composite agent in order to control the
                           underlying environment
  :param in_action_space: the type of action space that is used by the upper level agent in order to control this
                          group
  :param decision_makers: a list of booleans representing for each corresponding agent if it has a decision
                          privilege or if it is just an observer
  :param reward_policy: the type of the reward that the group receives
docstr_tok: ["Construct","an","agent","group",":","param","agents_parameters",":","a","list","of","presets","describing","each","one","of","the","agents","in","the","group",":","param","decision_policy",":","the","decision","policy","of","the","group","which","describes","how","actions","are","consolidated",":","param","out_action_space",":","the","type","of","action","space","that","is","used","by","this","composite","agent","in","order","to","control","the","underlying","environment",":","param","in_action_space",":","the","type","of","action","space","that","is","used","by","the","upper","level","agent","in","order","to","control","this","group",":","param","decision_makers",":","a","list","of","booleans","representing","for","each","corresponding","agent","if","it","has","a","decision","privilege","or","if","it","is","just","an","observer",":","param","reward_policy",":","the","type","of","the","reward","that","the","group","receives"]
code: def __init__(
      self,
      agents_parameters: Union[
          AgentParameters, Dict[str, AgentParameters]
      ],
      visualization_parameters: VisualizationParameters,
      decision_policy: DecisionPolicy,
      out_action_space: ActionSpace,
      in_action_space: Union[None, ActionSpace] = None,
      decision_makers: Union[bool, Dict[str, bool]] = True,
      reward_policy: RewardPolicy = RewardPolicy.NativeEnvironmentReward,
      name="CompositeAgent",
  ):
      """
      Construct an agent group
      :param agents_parameters: a list of presets describing each one of the agents in the group
      :param decision_policy: the decision policy of the group which describes how actions are consolidated
      :param out_action_space: the type of action space that is used by this composite agent in order to control the
                               underlying environment
      :param in_action_space: the type of action space that is used by the upper level agent in order to control this
                              group
      :param decision_makers: a list of booleans representing for each corresponding agent if it has a decision
                              privilege or if it is just an observer
      :param reward_policy: the type of the reward that the group receives
      """
      super().__init__()
  
      if isinstance(agents_parameters, AgentParameters):
          decision_makers = {agents_parameters.name: True}
          agents_parameters = {
              agents_parameters.name: agents_parameters
          }
      self.agents_parameters = agents_parameters
      self.visualization_parameters = visualization_parameters
      self.decision_makers = decision_makers
      self.decision_policy = decision_policy
      self.in_action_space = in_action_space
      self.out_action_space = (
          out_action_space  # TODO: this is not being used
      )
      self.reward_policy = reward_policy
      self.full_name_id = self.name = name
      self.current_decision_maker = 0
      self.environment = None
      self.agents = {}  # key = agent_name, value = agent
      self.incoming_action = None
      self.last_state = None
      self._phase = RunPhase.HEATUP
      self.last_action_info = None
      self.current_episode = 0
      self.parent_level_manager = None
  
      # environment spaces
      self.spaces = None
  
      # counters for logging
      self.total_steps_counter = 0
      self.current_episode_steps_counter = 0
      self.total_reward_in_current_episode = 0
  
      # validate input
      if set(self.decision_makers) != set(self.agents_parameters):
          raise ValueError(
              "The decision_makers dictionary keys does not match the names of the given agents"
          )
      if (
          sum(self.decision_makers.values()) > 1
          and type(self.decision_policy) == SingleDecider
          and type(self.in_action_space) != AgentSelection
      ):
          raise ValueError(
              "When the control policy is set to single decider, the master policy should control the"
              "agent group via agent selection (ControlType.AgentSelection)"
          )
  
imports: import copy
  import itertools
  from enum import Enum
  from typing import Union, List, Dict
  import numpy
  from rl_coach.agents.agent_interface import AgentInterface
  from rl_coach.base_parameters import AgentParameters, VisualizationParameters
  from rl_coach.core_types import ActionInfo, EnvResponse, ActionType, RunPhase
  from rl_coach.filters.observation.observation_crop_filter import ObservationCropFilter
  from rl_coach.saver import SaverCollection
  from rl_coach.spaces import ActionSpace
  from rl_coach.spaces import AgentSelection, AttentionActionSpace, SpacesDefinition
  from rl_coach.utils import short_dynamic_import
label_desc: Use image node_id 1 to create a new CompositeAgent object from inherited base classes: AgentInterface with example: obj = CompositeAgent(agents_parameters, visualization_parameters, decision_policy, out_action_space, in_action_space, decision_makers, reward_policy, name)