diff --git a/examples/st_game/actions/inner_voice_action.py b/examples/st_game/actions/inner_voice_action.py index 082921554..d60144beb 100644 --- a/examples/st_game/actions/inner_voice_action.py +++ b/examples/st_game/actions/inner_voice_action.py @@ -3,6 +3,7 @@ from examples.st_game.actions.st_action import STAction from examples.st_game.memory.agent_memory import BasicMemory from metagpt.logs import logger + class AgentWhisperThoughtAction(STAction): def __init__(self, name="AgentWhisperThoughtAction", context: list[BasicMemory] = None, llm=None): @@ -12,7 +13,7 @@ class AgentWhisperThoughtAction(STAction): try: self._func_cleanup(llm_resp, prompt) return True - except: + except Exception as exp: return False def _func_cleanup(self, llm_resp: str, prompt: str = "") -> list: @@ -21,7 +22,7 @@ class AgentWhisperThoughtAction(STAction): def _func_fail_default_resp(self) -> str: pass - async def run(self, role: "STRole", statements: str, test_input=None, verbose=False) -> str: + def run(self, role: "STRole", statements: str, test_input=None, verbose=False) -> str: def create_prompt_input(role: "STRole", statements, test_input=None): prompt_input = [role.scratch.name, statements] return prompt_input @@ -30,7 +31,6 @@ class AgentWhisperThoughtAction(STAction): prompt = self.generate_prompt_with_tmpl_filename(prompt_input, "whisper_inner_thought_v1.txt") - output = await self._run_v1(prompt) + output = self._run_v1(prompt) logger.info(f"Run action: {self.__class__.__name__} with result: {output}") return output - diff --git a/examples/st_game/memory/spatial_memory.py b/examples/st_game/memory/spatial_memory.py index 87d16b635..ffd06f930 100644 --- a/examples/st_game/memory/spatial_memory.py +++ b/examples/st_game/memory/spatial_memory.py @@ -10,15 +10,13 @@ import os from ..utils.utils import check_if_file_exists + class MemoryTree: - def __init__(self, f_saved: str): + def __init__(self): self.tree = {} - if check_if_file_exists(f_saved): - with open(f_saved) as f: - self.tree = json.load(f) def set_mem_path(self, f_saved: str): - if os.path.isfile(f_saved) and os.path.exists(f_saved): + if check_if_file_exists(f_saved): with open(f_saved) as f: self.tree = json.load(f) diff --git a/examples/st_game/roles/st_role.py b/examples/st_game/roles/st_role.py index 08500a24b..fdde4f5e3 100644 --- a/examples/st_game/roles/st_role.py +++ b/examples/st_game/roles/st_role.py @@ -102,11 +102,11 @@ class STRole(Role): @property def scratch(self): return self._rc.scratch - + @property def role_tile(self): return self.scratch.curr_tile - + @property def a_mem(self): return self._rc.memory @@ -143,18 +143,16 @@ class STRole(Role): return 1 # always return 1 to execute role's `_react` - def add_inner_voice(self, whisper): - # TODO - def generate_inner_thought(role: STRole, whisper): + def add_inner_voice(self, whisper: str): + def generate_inner_thought(whisper: str): run_whisper_thought = AgentWhisperThoughtAction() inner_thought = run_whisper_thought.run(self, whisper) return inner_thought - whisper = input("Enter Input: ") thought = generate_inner_thought(whisper) - created = self._rc.scratch.curr_time - expiration = self._rc.scratch.curr_time + datetime.timedelta(days=30) + created = self._rc.scratch.curr_time if self._rc.scratch.curr_time else datetime.datetime.now() + expiration = created + datetime.timedelta(days=30) run_event_triple = AgentEventTriple() s, p, o = run_event_triple.run(thought, self) keywords = set([s, p, o])