From 628aaf00d1d3ac6d05b09478db22569ae5069386 Mon Sep 17 00:00:00 2001 From: Randool Date: Fri, 7 Mar 2025 17:43:58 +0800 Subject: [PATCH] feat: Adding human interaction functionality to Manus --- app/agent/manus.py | 7 ++++++- app/prompt/manus.py | 2 +- app/tool/ask_human.py | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 app/tool/ask_human.py diff --git a/app/agent/manus.py b/app/agent/manus.py index d7ec2f9..6a42860 100644 --- a/app/agent/manus.py +++ b/app/agent/manus.py @@ -5,6 +5,7 @@ from app.config import config from app.prompt.browser import NEXT_STEP_PROMPT as BROWSER_NEXT_STEP_PROMPT from app.prompt.manus import NEXT_STEP_PROMPT, SYSTEM_PROMPT from app.tool import Terminate, ToolCollection +from app.tool.ask_human import AskHuman from app.tool.browser_use_tool import BrowserUseTool from app.tool.python_execute import PythonExecute from app.tool.str_replace_editor import StrReplaceEditor @@ -33,7 +34,11 @@ class Manus(BrowserAgent): # Add general-purpose tools to the tool collection available_tools: ToolCollection = Field( default_factory=lambda: ToolCollection( - PythonExecute(), BrowserUseTool(), StrReplaceEditor(), Terminate() + PythonExecute(), + BrowserUseTool(), + StrReplaceEditor(), + AskHuman(), + Terminate(), ) ) diff --git a/app/prompt/manus.py b/app/prompt/manus.py index f080ba4..1d7d956 100644 --- a/app/prompt/manus.py +++ b/app/prompt/manus.py @@ -1,5 +1,5 @@ SYSTEM_PROMPT = ( - "You are OpenManus, an all-capable AI assistant, aimed at solving any task presented by the user. You have various tools at your disposal that you can call upon to efficiently complete complex requests. Whether it's programming, information retrieval, file processing, or web browsing, you can handle it all." + "You are OpenManus, an all-capable AI assistant, aimed at solving any task presented by the user. You have various tools at your disposal that you can call upon to efficiently complete complex requests. Whether it's programming, information retrieval, file processing, web browsing, or human interaction (only for extreme cases), you can handle it all." "The initial directory is: {directory}" ) diff --git a/app/tool/ask_human.py b/app/tool/ask_human.py new file mode 100644 index 0000000..5fd4550 --- /dev/null +++ b/app/tool/ask_human.py @@ -0,0 +1,21 @@ +from app.tool import BaseTool + + +class AskHuman(BaseTool): + """Add a tool to ask human for help.""" + + name: str = "ask_human" + description: str = "Use this tool to ask human for help." + parameters: str = { + "type": "object", + "properties": { + "inquire": { + "type": "string", + "description": "The question you want to ask human.", + } + }, + "required": ["inquire"], + } + + async def execute(self, inquire: str) -> str: + return input(f"""Bot: {inquire}\n\nYou: """).strip()