diff --git a/metagpt/actions/search_enhanced_qa.py b/metagpt/actions/search_enhanced_qa.py index 23f21b2a8..1427f9b19 100644 --- a/metagpt/actions/search_enhanced_qa.py +++ b/metagpt/actions/search_enhanced_qa.py @@ -9,6 +9,7 @@ from pydantic import Field, PrivateAttr, model_validator from metagpt.actions import Action from metagpt.actions.research import CollectLinks, WebBrowseAndSummarize from metagpt.logs import logger +from metagpt.tools.tool_registry import register_tool from metagpt.tools.web_browser_engine import WebBrowserEngine from metagpt.utils.common import CodeParser from metagpt.utils.parse_html import WebPage @@ -57,8 +58,9 @@ Remember, don't blindly repeat the contexts verbatim. And here is the user quest """ +@register_tool(include_functions=["run"]) class SearchEnhancedQA(Action): - """Enhancing question-answering capabilities through search engine augmentation.""" + """Question answering and info searching through search engine.""" name: str = "SearchEnhancedQA" desc: str = "Integrating search engine results to anwser the question." diff --git a/metagpt/prompts/di/data_analyst.py b/metagpt/prompts/di/data_analyst.py index 8e5b888d3..9f943b187 100644 --- a/metagpt/prompts/di/data_analyst.py +++ b/metagpt/prompts/di/data_analyst.py @@ -1,12 +1,12 @@ from metagpt.strategy.task_type import TaskType EXTRA_INSTRUCTION = """ -6. Carefully choose to use or not use the browser tool to assist you in web tasks. - - When no click action is required, no need to use the Browser tool to navigate to the webpage before scraping. - - Write code to view the HTML content rather than using the Browser tool. - - Make sure the command_name are certainly in Available Commands when you use the Browser tool. - - For information searching requirement, you should use the Browser tool instead of web scraping. - - When no link is provided, you should use the Browser tool to search for the information. +6. Carefully consider how you handle web tasks: + - Use SearchEnhancedQA for general information searching, i.e. querying search engines, such as googling news, weather, wiki, etc. Usually, no link is provided. + - Use Browser for reading, navigating, or in-domain searching within a specific web, such as reading a blog, searching products from a given e-commerce web link, or interacting with a web app. + - Use DataAnalyst.write_and_execute_code for web scraping, such as gathering batch data or info from a provided link. + - Write code to view the HTML content rather than using the Browser tool. + - Make sure the command_name are certainly in Available Commands when you use the Browser tool. 7. When you are making plan. It is highly recommend to plan and append all the tasks in first response once time, except for 7.1. 7.1. When the requirement is inquiring about a pdf, docx, md, or txt document, read the document first through either Editor.read WITHOUT a plan. After reading the document, use RoleZero.reply_to_human if the requirement can be answered straightaway, otherwise, make a plan if further calculation is needed. 8. Don't finish_current_task multiple times for the same task. diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py index 54f325be1..876e61835 100644 --- a/metagpt/prompts/di/role_zero.py +++ b/metagpt/prompts/di/role_zero.py @@ -79,7 +79,7 @@ Output should adhere to the following format. ```json [ {{ - "command_name": str, + "command_name": "ClassName.method_name" or "function_name", "args": {{"arg_name": arg_value, ...}} }}, ... diff --git a/metagpt/roles/di/data_analyst.py b/metagpt/roles/di/data_analyst.py index 329b3c45d..f9bead1ac 100644 --- a/metagpt/roles/di/data_analyst.py +++ b/metagpt/roles/di/data_analyst.py @@ -30,8 +30,8 @@ class DataAnalyst(RoleZero): instruction: str = ROLE_INSTRUCTION + EXTRA_INSTRUCTION task_type_desc: str = TASK_TYPE_DESC - tools: list[str] = ["Plan", "DataAnalyst", "RoleZero", "Browser", "Editor:write,read"] - custom_tools: list[str] = ["web scraping", "Terminal"] + tools: list[str] = ["Plan", "DataAnalyst", "RoleZero", "Browser", "Editor:write,read", "SearchEnhancedQA"] + custom_tools: list[str] = ["web scraping", "Terminal", "Editor:write,read"] custom_tool_recommender: ToolRecommender = None experience_retriever: Annotated[ExpRetriever, Field(exclude=True)] = KeywordExpRetriever() diff --git a/metagpt/roles/di/engineer2.py b/metagpt/roles/di/engineer2.py index 4600e3254..7a862dfcd 100644 --- a/metagpt/roles/di/engineer2.py +++ b/metagpt/roles/di/engineer2.py @@ -28,7 +28,7 @@ class Engineer2(RoleZero): terminal: Terminal = Field(default_factory=Terminal, exclude=True) - tools: list[str] = ["Plan", "Editor:read", "RoleZero", "Terminal:run_command", "Engineer2"] + tools: list[str] = ["Plan", "Editor:read", "RoleZero", "Terminal:run_command", "SearchEnhancedQA", "Engineer2"] def _update_tool_execution(self): # validate = ValidateAndRewriteCode() diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py index ce87d13dc..b8d0c671a 100644 --- a/metagpt/roles/di/role_zero.py +++ b/metagpt/roles/di/role_zero.py @@ -31,7 +31,6 @@ from metagpt.prompts.di.role_zero import ( ROLE_INSTRUCTION, SUMMARY_PROMPT, SYSTEM_PROMPT, - THOUGHT_GUIDANCE, ) from metagpt.roles import Role from metagpt.schema import AIMessage, Message, UserMessage @@ -62,7 +61,6 @@ class RoleZero(Role): system_prompt: str = SYSTEM_PROMPT # Use None to conform to the default value at llm.aask cmd_prompt: str = CMD_PROMPT cmd_prompt_current_state: str = "" - thought_guidance: str = THOUGHT_GUIDANCE instruction: str = ROLE_INSTRUCTION task_type_desc: Optional[str] = None @@ -118,6 +116,7 @@ class RoleZero(Role): "Editor.read": self.editor.read, "RoleZero.ask_human": self.ask_human, "RoleZero.reply_to_human": self.reply_to_human, + "SearchEnhancedQA.run": SearchEnhancedQA().run, } self.tool_execution_map.update( {