diff --git a/examples/environments/chatroom/envs/immutable.py b/examples/environments/chatroom/envs/immutable.py index 47221670c..42b4c8d02 100644 --- a/examples/environments/chatroom/envs/immutable.py +++ b/examples/environments/chatroom/envs/immutable.py @@ -22,13 +22,11 @@ def __init__( value: Any, listeners: dict[str, List[EventListener]] = None, children: List[Env] = None, - parent: Env = None, ) -> None: super().__init__( name=name, listeners=listeners, children=children, - parent=parent, ) self._value = value diff --git a/examples/environments/chatroom/envs/map2d.py b/examples/environments/chatroom/envs/map2d.py index 1c044ae8a..8a0429827 100644 --- a/examples/environments/chatroom/envs/map2d.py +++ b/examples/environments/chatroom/envs/map2d.py @@ -41,7 +41,6 @@ def __init__( self, name: str, children: List[Env] = None, - parent: Env = None, ) -> None: """Initialize a Map2D env. @@ -49,7 +48,6 @@ def __init__( name (`str`): The name of the env. children (`List[envibute]`): The children of the env. Note that all children must be Movable2D. - parent (`envibute`): The parent of the env. """ for child in children if children else []: if not isinstance(child, Movable2D): @@ -60,7 +58,6 @@ def __init__( super().__init__( name=name, children=children, - parent=parent, ) @event_func diff --git a/examples/environments/chatroom/envs/mutable.py b/examples/environments/chatroom/envs/mutable.py index b6fba2a93..0b2506430 100644 --- a/examples/environments/chatroom/envs/mutable.py +++ b/examples/environments/chatroom/envs/mutable.py @@ -21,13 +21,11 @@ def __init__( value: Any, listeners: dict[str, List[EventListener]] = None, children: List[Env] = None, - parent: Env = None, ) -> None: super().__init__( name=name, listeners=listeners, children=children, - parent=parent, ) self._value = value diff --git a/examples/environments/chatroom/envs/point2d.py b/examples/environments/chatroom/envs/point2d.py index 024040f2e..f0b629b4d 100644 --- a/examples/environments/chatroom/envs/point2d.py +++ b/examples/environments/chatroom/envs/point2d.py @@ -22,13 +22,11 @@ def __init__( y: float, listeners: dict[str, List[EventListener]] = None, children: List[Env] = None, - parent: Env = None, ) -> None: super().__init__( name=name, listeners=listeners, children=children, - parent=parent, ) self.x = x self.y = y @@ -75,14 +73,12 @@ def __init__( y: float, listeners: dict[str, List[EventListener]] = None, children: List[Env] = None, - parent: Env = None, ) -> None: super().__init__( name=name, value=value, listeners=listeners, children=children, - parent=parent, ) self.add_child(Point2D("position", x, y)) diff --git a/examples/environments/chatroom/envs/timeline.py b/examples/environments/chatroom/envs/timeline.py index 04a1d7f7e..82569117d 100644 --- a/examples/environments/chatroom/envs/timeline.py +++ b/examples/environments/chatroom/envs/timeline.py @@ -20,12 +20,10 @@ def __init__( unit: int = 1, end: Optional[int] = None, children: List[Env] = None, - parent: Env = None, ) -> None: super().__init__( name=name, children=children, - parent=parent, ) self.cur_time = start self.unit = unit diff --git a/src/agentscope/environment/env.py b/src/agentscope/environment/env.py index 5b3a5ca68..ff1cc6601 100644 --- a/src/agentscope/environment/env.py +++ b/src/agentscope/environment/env.py @@ -97,7 +97,7 @@ class Env(ABC, metaclass=RpcMeta): Each env has its own name and value, and multiple envs can be organized into a tree structure, where each env can have - multiple children envs and one parent env. + multiple children envs. Different implementations of envs may have different event functions, which are marked by `@event_func`. @@ -115,22 +115,6 @@ def name(self) -> str: `str`: The name of the env. """ - @abstractmethod - def get_parent(self) -> Env: - """Get the parent env of the current env. - - Returns: - `Env`: The parent env. - """ - - @abstractmethod - def set_parent(self, parent: Env) -> None: - """Set the parent env of the current env. - - Args: - parent (`Env`): The parent env. - """ - @abstractmethod def get_children(self) -> dict[str, Env]: """Get the children envs of the current env. @@ -225,7 +209,6 @@ def __init__( name: str, listeners: dict[str, List[EventListener]] = None, children: List[Env] = None, - parent: Env = None, ) -> None: """Init an BasicEnv instance. @@ -235,14 +218,11 @@ def __init__( listener dict. Defaults to None. children (`List[Env]`, optional): A list of children envs. Defaults to None. - parent (`Env`, optional): The parent env. Defaults - to None. """ self._name = name self.children = { child.name: child for child in (children if children else []) } - self.parent = parent self.event_listeners = {} if listeners: for target_func, listener in listeners.items(): @@ -257,24 +237,6 @@ def name(self) -> str: """Name of the env""" return self._name - def get_parent(self) -> Env: - """Get the parent env of the current env. - - Returns: - `Env`: The parent env. - """ - return self.parent - - def set_parent(self, parent: Env) -> None: - """Set the parent env of the current env. - - Args: - parent (`Env`): The parent env. - """ - if self.parent is not None: - self.parent.remove_child(self.name) - self.parent = parent - def get_children(self) -> dict[str, Env]: """Get the children envs of the current env. @@ -296,7 +258,6 @@ def add_child(self, child: Env) -> bool: if child.name in self.children: return False self.children[child.name] = child - child.set_parent(self) return True def remove_child(self, children_name: str) -> bool: @@ -392,7 +353,6 @@ def __setitem__(self, env_name: str, env: Env) -> None: raise TypeError("Only Env can be set") if env_name not in self.children: self.children[env_name] = env - env.set_parent(self) logger.debug(f"Set Env[{env_name}] as child of Env[{self.name}]") else: raise EnvAlreadyExistError(env_name)