From 03f69609d9e338c7b5eaad8e505649e612770b6c Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 8 May 2024 15:04:44 +0800 Subject: [PATCH 1/2] comment out unnecessary tools --- metagpt/tools/libs/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/metagpt/tools/libs/__init__.py b/metagpt/tools/libs/__init__.py index f4a112a69..f21307724 100644 --- a/metagpt/tools/libs/__init__.py +++ b/metagpt/tools/libs/__init__.py @@ -5,12 +5,12 @@ # @File : __init__.py # @Desc : from metagpt.tools.libs import ( - data_preprocess, - feature_engineering, + # data_preprocess, + # feature_engineering, sd_engine, gpt_v_generator, - web_scraping, - email_login, + # web_scraping, + # email_login, terminal, file_manager, browser, @@ -19,12 +19,12 @@ from metagpt.tools.libs import ( from metagpt.tools.libs.env import get_env, set_get_env_entry, default_get_env, get_env_description _ = ( - data_preprocess, - feature_engineering, + # data_preprocess, + # feature_engineering, sd_engine, gpt_v_generator, - web_scraping, - email_login, + # web_scraping, + # email_login, terminal, file_manager, browser, From 445db9074bc3e6ca9c5d4ae0119b7e12685e4c3d Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 8 May 2024 15:18:26 +0800 Subject: [PATCH 2/2] add deploy plan for da --- metagpt/prompts/di/data_analyst.py | 1 + metagpt/roles/di/data_analyst.py | 4 ++- metagpt/strategy/experience_retriever.py | 46 ++++++++++++++++++++++++ metagpt/strategy/thinking_command.py | 3 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/metagpt/prompts/di/data_analyst.py b/metagpt/prompts/di/data_analyst.py index f8e2c1cb5..a0624f047 100644 --- a/metagpt/prompts/di/data_analyst.py +++ b/metagpt/prompts/di/data_analyst.py @@ -23,6 +23,7 @@ Pay close attention to new user message, review the conversation history, use re Note: 1. If you keeping encountering errors, unexpected situation, or you are not sure of proceeding, use ask_human to ask for help. 2. Each time you finish a task, use reply_to_human to report your progress. +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 finish_task, DON'T append a new task. diff --git a/metagpt/roles/di/data_analyst.py b/metagpt/roles/di/data_analyst.py index 4c959575b..359094c8e 100644 --- a/metagpt/roles/di/data_analyst.py +++ b/metagpt/roles/di/data_analyst.py @@ -11,6 +11,7 @@ from metagpt.logs import logger from metagpt.prompts.di.data_analyst import CMD_PROMPT from metagpt.roles.di.data_interpreter import DataInterpreter from metagpt.schema import Message, TaskResult +from metagpt.strategy.experience_retriever import KeywordExpRetriever from metagpt.strategy.planner import Planner from metagpt.strategy.thinking_command import ( Command, @@ -61,9 +62,11 @@ class DataAnalyst(DataInterpreter): async def _think(self) -> bool: """Useful in 'react' mode. Use LLM to decide whether and what to do next.""" self._set_state(0) + example = "" if not self.planner.plan.goal: self.user_requirement = self.get_memories()[-1].content self.planner.plan.goal = self.user_requirement + example = KeywordExpRetriever().retrieve(self.user_requirement) else: self.working_memory.add_batch(self.rc.news) @@ -71,7 +74,6 @@ class DataAnalyst(DataInterpreter): for task in plan_status["tasks"]: task.pop("code") task.pop("result") - example = "" prompt = CMD_PROMPT.format( plan_status=plan_status, example=example, diff --git a/metagpt/strategy/experience_retriever.py b/metagpt/strategy/experience_retriever.py index 34ff184ab..edc49a1a0 100644 --- a/metagpt/strategy/experience_retriever.py +++ b/metagpt/strategy/experience_retriever.py @@ -154,3 +154,49 @@ class SimpleExpRetriever(ExpRetriever): def retrieve(self, context: str = "") -> str: return self.EXAMPLE + + +class KeywordExpRetriever(ExpRetriever): + """An experience retriever that returns examples based on keywords in the context.""" + + EXAMPLE: dict = { + "deploy": """ + ## example 1 + User Requirement: launch a service from workspace/web_snake_game/web_snake_game, and deploy it to public + Explanation: Launching a service requires Terminal tool with daemon mode, write this into task instruction. + ```json + [ + { + "command_name": "append_task", + "args": { + "task_id": "1", + "dependent_task_ids": [], + "instruction": "Use the Terminal tool to launch the service in daemon mode", + "assignee": "David" + } + }, + { + "command_name": "append_task", + "args": { + "task_id": "2", + "dependent_task_ids": ["1"], + "instruction": "Test the service with a simple request", + "assignee": "David" + } + }, + { + "command_name": "append_task", + "args": { + "task_id": "3", + "dependent_task_ids": ["2"], + "instruction": "Deploy the service to public", + "assignee": "David" + } + }, + """ + } + + def retrieve(self, context: str) -> str: + if "deploy" in context.lower(): + return self.EXAMPLE["deploy"] + return "" diff --git a/metagpt/strategy/thinking_command.py b/metagpt/strategy/thinking_command.py index f852c3764..cde16e714 100644 --- a/metagpt/strategy/thinking_command.py +++ b/metagpt/strategy/thinking_command.py @@ -76,7 +76,8 @@ def prepare_command_prompt(commands: list[Command]) -> str: async def run_env_command(role: Role, cmd: list[dict], role_memory: Memory = None): - assert isinstance(role.rc.env, MGXEnv), "TeamLeader should only be used in an MGXEnv" + if not isinstance(role.rc.env, MGXEnv): + return if cmd["command_name"] == Command.PUBLISH_MESSAGE.cmd_name: role.publish_message(Message(**cmd["args"])) if cmd["command_name"] == Command.ASK_HUMAN.cmd_name: