diff --git a/src/agentscope/environment/env.py b/src/agentscope/environment/env.py index 422ba1b45..5b3a5ca68 100644 --- a/src/agentscope/environment/env.py +++ b/src/agentscope/environment/env.py @@ -271,6 +271,8 @@ def set_parent(self, parent: Env) -> None: 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]: @@ -391,5 +393,6 @@ def __setitem__(self, env_name: str, env: Env) -> None: 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)