add SearchQA to DA & Engineer2, add Editor for DA write code

This commit is contained in:
garylin2099 2024-09-03 19:29:37 +08:00
parent a63b7d2829
commit 100d5af39a
6 changed files with 14 additions and 13 deletions

View file

@ -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."

View file

@ -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.

View file

@ -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, ...}}
}},
...

View file

@ -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()

View file

@ -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()

View file

@ -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(
{