From 597128dac2eae7b345239235ab708a7fda781cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Fri, 2 Aug 2024 19:31:03 +0800 Subject: [PATCH 1/2] decorate the output of Bash.run --- metagpt/roles/di/role_zero.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index d4746e167..bc62ec8a5 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -37,7 +37,7 @@ from metagpt.utils.repair_llm_raw_output import RepairType, repair_llm_raw_outpu from metagpt.utils.report import ThoughtReporter -@register_tool(include_functions=["ask_human", "reply_to_human"]) +@register_tool(include_functions=["ask_human", "reply_to_human", "Bash.run"]) class RoleZero(Role): """A role who can think and act dynamically""" @@ -59,7 +59,7 @@ class RoleZero(Role): tools: list[str] = [] # Use special symbol [""] to indicate use of all registered tools tool_recommender: ToolRecommender = None tool_execution_map: dict[str, Callable] = {} - special_tool_commands: list[str] = ["Plan.finish_current_task", "end"] + special_tool_commands: list[str] = ["Plan.finish_current_task", "end", "Bash.run"] # Equipped with three basic tools by default for optional use editor: Editor = Editor() browser: Browser = Browser() @@ -370,6 +370,16 @@ class RoleZero(Role): self._set_state(-1) command_output = "" + # output from bash.run may be empty, add decorations to the output to ensure visibility. + elif cmd["command_name"] == "Bash.run": + tool_obj = self.tool_execution_map[cmd["command_name"]] + tool_output = await tool_obj(**cmd["args"]) + if len(tool_output) <= 10: + command_output += ( + f"\n[command]: {cmd['args']['cmd']} \n [command output] : {tool_output} (pay attention to this.)" + ) + else: + command_output += f"\n[command]: {cmd['args']['cmd']} \n [command output] : {tool_output}" return command_output def _get_plan_status(self) -> Tuple[str, str]: From 4c5b5d1e40daae8095f431cb54319b86b599830e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Fri, 2 Aug 2024 19:39:38 +0800 Subject: [PATCH 2/2] fix format issues --- metagpt/roles/di/role_zero.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index bc62ec8a5..af39fa544 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -37,7 +37,7 @@ from metagpt.utils.repair_llm_raw_output import RepairType, repair_llm_raw_outpu from metagpt.utils.report import ThoughtReporter -@register_tool(include_functions=["ask_human", "reply_to_human", "Bash.run"]) +@register_tool(include_functions=["ask_human", "reply_to_human"]) class RoleZero(Role): """A role who can think and act dynamically"""