diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 243f33604..5561d0942 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -40,6 +40,7 @@ Special Command: Use {{"command_name": "end"}} to do nothing or indicate complet Pay close attention to the Example provided, you can reuse the example for your current situation if it fits. You may use any of the available commands to create a plan or update the plan. You may output mutiple commands, they will be executed sequentially. If you finish current task, you will automatically take the next task in the existing plan, use Plan.finish_task, DON'T append a new task. +Pay close attention to what you have done. Be different with your previous action. # Your commands in a json array, in the following output format with correct command_name and args. If there is nothing to do, use the pass or end command: Some text indicating your thoughts, such as how you should update the plan status, respond to inquiry, or seek for help. Then a json array of commands. You must output ONE and ONLY ONE json array. DON'T output multiple json arrays with thoughts between them. @@ -52,6 +53,7 @@ Some text indicating your thoughts, such as how you should update the plan statu ... ] ``` +Notice: your output JSON data must be a command list. Notice: your output JSON data section must start with **```json [** """ @@ -61,9 +63,9 @@ JSON_REPAIR_PROMPT = """ ## Output Format ```json -Formatted JSON data + ``` -Help check if there are any formatting issues with the JSON data? If so, please help format it +Help check if there are any formatting issues with the JSON data? If so, please help format it. """ QUICK_THINK_PROMPT = """ diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index c945f4d3d..c33e398be 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -149,13 +149,12 @@ class RoleZero(Role): current_task=current_task, example=example, available_commands=tool_info, - pre_task = await self._parse_commands(), instruction=self.instruction.strip(), - root_direction = DEFAULT_WORKSPACE_ROOT, task_type_desc=self.task_type_desc, ) memory = self.rc.memory.get(self.memory_k) memory = await self.parse_browser_actions(memory) + memory = await self.add_editor_root_directory(memory) context = self.llm.format_msg(memory + [UserMessage(content=prompt)]) # print(*context, sep="\n" + "*" * 5 + "\n") async with ThoughtReporter(enable_llm_stream=True) as reporter: @@ -173,7 +172,10 @@ class RoleZero(Role): print(self.command_rsp) self.rc.memory.add(AIMessage(content=self.command_rsp)) return True - + + async def add_editor_root_directory(self,memory) -> List[Message]: + memory.append(UserMessage(cause_by="editory", content=f'Root directory is {DEFAULT_WORKSPACE_ROOT}')) + return memory async def parse_browser_actions(self, memory: List[Message]) -> List[Message]: if not self.browser.is_empty_page: pattern = re.compile(r"Command Browser\.(\w+) executed") @@ -251,7 +253,6 @@ class RoleZero(Role): ) return rsp_msg - async def _parse_commands(self) -> Tuple[List[Dict], bool]: """Retrieves commands from the Large Language Model (LLM). diff --git a/metagpt/tools/libs/editor.py b/metagpt/tools/libs/editor.py index c9f02c4f1..edc228b12 100644 --- a/metagpt/tools/libs/editor.py +++ b/metagpt/tools/libs/editor.py @@ -38,7 +38,7 @@ class Editor: # self.resource.report(path, "path") def read(self, path: str) -> FileBlock: - """Read the whole content of a file.""" + """Read the whole content of a file.It is strongly advised to utilize absolute paths""" with open(path, "r") as f: self.resource.report(path, "path") lines = f.readlines()