class_docstr: Wraps a MultiAgentEnv environment with agents grouped as specified.
  
  See multi_agent_env.py for the specification of groups.
  
  This API is experimental.
class_docstr_tok: ["Wraps","a","MultiAgentEnv","environment","with","agents","grouped","as","specified",".","See","multi_agent_env.py","for","the","specification","of","groups",".","This","API","is","experimental","."]
docstr: Wrap an existing MultiAgentEnv to group agent ID together.
  
  See `MultiAgentEnv.with_agent_groups()` for more detailed usage info.
  
  Args:
      env: The env to wrap and whose agent IDs to group into new agents.
      groups: Mapping from group id to a list of the agent ids
          of group members. If an agent id is not present in any group
          value, it will be left ungrouped. The group id becomes a new agent ID
          in the final environment.
      obs_space: Optional observation space for the grouped
          env. Must be a tuple space. If not provided, will infer this to be a
          Tuple of n individual agents spaces (n=num agents in a group).
      act_space: Optional action space for the grouped env.
          Must be a tuple space. If not provided, will infer this to be a Tuple
          of n individual agents spaces (n=num agents in a group).
docstr_tok: ["Wrap","an","existing","MultiAgentEnv","to","group","agent","ID","together",".","See","`","MultiAgentEnv.with_agent_groups","(",")","`","for","more","detailed","usage","info",".","Args",":","env",":","The","env","to","wrap","and","whose","agent","IDs","to","group","into","new","agents",".","groups",":","Mapping","from","group","id","to","a","list","of","the","agent","ids","of","group","members",".","If","an","agent","id","is","not","present","in","any","group","value",",","it","will","be","left","ungrouped",".","The","group","id","becomes","a","new","agent","ID","in","the","final","environment",".","obs_space",":","Optional","observation","space","for","the","grouped","env",".","Must","be","a","tuple","space",".","If","not","provided",",","will","infer","this","to","be","a","Tuple","of","n","individual","agents","spaces","(","n=num","agents","in","a","group",")",".","act_space",":","Optional","action","space","for","the","grouped","env",".","Must","be","a","tuple","space",".","If","not","provided",",","will","infer","this","to","be","a","Tuple","of","n","individual","agents","spaces","(","n=num","agents","in","a","group",")","."]
code: def __init__(
      self,
      env: MultiAgentEnv,
      groups: Dict[str, List[AgentID]],
      obs_space: Optional[gym.Space] = None,
      act_space: Optional[gym.Space] = None,
  ):
      """Wrap an existing MultiAgentEnv to group agent ID together.
  
      See `MultiAgentEnv.with_agent_groups()` for more detailed usage info.
  
      Args:
          env: The env to wrap and whose agent IDs to group into new agents.
          groups: Mapping from group id to a list of the agent ids
              of group members. If an agent id is not present in any group
              value, it will be left ungrouped. The group id becomes a new agent ID
              in the final environment.
          obs_space: Optional observation space for the grouped
              env. Must be a tuple space. If not provided, will infer this to be a
              Tuple of n individual agents spaces (n=num agents in a group).
          act_space: Optional action space for the grouped env.
              Must be a tuple space. If not provided, will infer this to be a Tuple
              of n individual agents spaces (n=num agents in a group).
      """
      super().__init__()
      self.env = env
      # Inherit wrapped env's `_skip_env_checking` flag.
      if hasattr(self.env, "_skip_env_checking"):
          self._skip_env_checking = self.env._skip_env_checking
      self.groups = groups
      self.agent_id_to_group = {}
      for group_id, agent_ids in groups.items():
          for agent_id in agent_ids:
              if agent_id in self.agent_id_to_group:
                  raise ValueError(
                      "Agent id {} is in multiple groups".format(
                          agent_id
                      )
                  )
              self.agent_id_to_group[agent_id] = group_id
      if obs_space is not None:
          self.observation_space = obs_space
      if act_space is not None:
          self.action_space = act_space
      for group_id in groups.keys():
          self._agent_ids.add(group_id)
  
file_path: ray/python/ray/rllib/env/wrappers/group_agents_wrapper.py
imports: from collections import OrderedDict
  import gymnasium
  from typing import Dict, List, Optional
  from ray.rllib.env.multi_agent_env import MultiAgentEnv
  from ray.rllib.utils.annotations import DeveloperAPI
  from ray.rllib.utils.typing import AgentID
label_desc: Use image node_id 1 to create a new GroupAgentsWrapper object from inherited base classes: MultiAgentEnv with example: obj = GroupAgentsWrapper(env, groups, obs_space, act_space)