def _world_function(): world_generator = utils.get_world_fn_attr(self._world_module, overworld_name, "generate_world") overworld = world_generator(self.opt, [overworld_agent]) while not self.system_done: world_type = overworld.parley() if world_type is None: time.sleep(0.5) continue # perform onboarding onboard_type = onboard_map.get(world_type) if onboard_type: onboard_id = 'onboard-{}-{}'.format( overworld_agent.id, time.time()) agent = self.manager._create_agent(onboard_id, overworld_agent.id) agent_state.set_active_agent(agent) agent_state.assign_agent_to_task(agent, onboard_id) _, onboard_data = self._run_world(task, onboard_type, [agent]) agent_state.onboard_data = onboard_data self.manager.add_agent_to_pool(agent_state, world_type) utils.print_and_log(logging.INFO, 'onboarding/overworld complete') time.sleep(5) # sleep until agent returns from task world while agent_state.get_active_agent() != overworld_agent: time.sleep(2) overworld.return_overworld() return world_type
def _run_world(self, task, world_name, agents): """Run a world until completion. :param task: TaskState. State of the given task. :param world_name: string. The name of the world in the module file :param agents: list. A list of agents that should be in the world. :return: ret_val: last output of world's parley function. Return None if ERROR world_data: data attribute of world, if it has one """ ret_val = None world_generator = utils.get_world_fn_attr(self._world_module, world_name, "generate_world") world = world_generator(self.opt, agents) task.world = world while not world.episode_done() and not self.system_done: ret_val = world.parley() time.sleep(0.3) world.shutdown() world_data = world.data if hasattr(world, "data") else {} return ret_val, world_data