要注意的是,由于资源限制,Ollama中只能运行参数较小B的模型,所以效果可能没有高B的模型好,而且有时候还会出现一些未知的问题。不过这是一次有益的尝试。
- 创建环境
conda create -n open_manus python=3.12 conda activate open_manus
- 下载源码
git clone https://github.com/mannaandpoem/OpenManus.git cd OpenManus
- 安装依赖
pip install -r requirements.txt
- 复制配置文件
cp config/config.example.toml config/config.toml
- 配置使用本地Ollama的模型
由于本地资源限制,这里我使用Ollama中下载的Qwen2.5:7b模型。该模型的效果有时候可能不是太好。
[llm] model = "Qwen2.5:7b" base_url = "http://127.0.0.1:11434/v1" api_key = "sk-..." max_tokens = 4096 temperature = 0.0
进入源码文件夹,然后运行。这次我输入了一个最简单的问题:1+1=?
~/OpenManus INFO [browser_use] BrowserUse logging setup complete with level info INFO [root] Anonymized telemetry enabled. See https://docs.browser-use.com/development/telemetry for more information. Enter your prompt (or 'exit' to quit): 1+1=? 2025-03-09 09:53:28.204 | WARNING | __main__:main:15 - Processing your request... 2025-03-09 09:53:28.205 | INFO | app.agent.base:run:137 - Executing step 1/30 2025-03-09 10:04:54.268 | INFO | app.agent.toolcall:think:53 - ✨ Manus's thoughts: 2025-03-09 10:04:54.268 | INFO | app.agent.toolcall:think:54 - 🛠️ Manus selected 1 tools to use 2025-03-09 10:04:54.268 | INFO | app.agent.toolcall:think:58 - 🧰 Tools being prepared: ['python_execute'] 2025-03-09 10:04:54.269 | INFO | app.agent.toolcall:execute_tool:140 - 🔧 Activating tool: 'python_execute'... 2025-03-09 10:04:54.269 | INFO | app.agent.toolcall:act:113 - 🎯 Tool 'python_execute' completed its mission! Result: Observed output of cmd `python_execute` executed: {'observation': '2\n'} 2025-03-09 10:04:54.269 | INFO | app.agent.base:run:137 - Executing step 2/30 ...
可以看到,OpenManus会生成python代码,并通过工具python_execute来执行该代码,并获取最终结果。
可以看到总共有30步?不知道这是为什么。就1+1=?这个问题需要共执行30步吗?于是看了一下它的实现逻辑,其实在主逻辑中有一个这样的循环:
async def run(self, request: Optional[str] = None) -> str: while (self.current_step < self.max_steps and self.state != AgentState.FINISHED): self.current_step += 1 logger.info(f"Executing step {self.current_step}/{self.max_steps}") step_result = await self.step()
其实,在Agent的实现中基本都是通过这样的迭代来完成的。这里的self.max_steps是迭代的最大次数,默认就是30,也就是说,要是迭代到了最大次数,还没有得到正确的答案,就直接宣告失败了。而这期间,要是在某一次中找到了正确答案,则可以询问用户是否要退出循环,还是要继续问其他问题。
运行时发现,它回答完成一个问题后,会继续询问我是否要进行下面的一些步骤,但此时任务已经完成,我想直接退出,而不希望在进行其他任务了。此时,我只能直接终止掉应用。这样退出不是很优雅。能不能让manus执行完任务后自动终止,或则提醒用户是否要终止,而不是继续询问,知道30次才结束?
在源码中发现了一个提示词:NEXT_STEP_PROMPT,内容如下:
NEXT_STEP_PROMPT = """You can interact with the computer using PythonExecute, save important content and information files through FileSaver, open browsers with BrowserUseTool, and retrieve information using GoogleSearch. PythonExecute: Execute Python code to interact with the computer system, data processing, automation tasks, etc. FileSaver: Save files locally, such as txt, py, html, etc. BrowserUseTool: Open, browse, and use web browsers.If you open a local HTML file, you must provide the absolute path to the file. GoogleSearch: Perform web information retrieval Based on user needs, proactively select the most appropriate tool or combination of tools. For complex tasks, you can break down the problem and use different tools step by step to solve it. After using each tool, clearly explain the execution results and suggest the next steps. """
可以看出,该提示词中并没有提示用户结束任务的指令,要是添加一条终止的提示词是不是会有效果?于是在原来的提示词GoogleSearch后面添加了一句:
... GoogleSearch: ... Terminate: Terminate the interaction when the request is met OR if the assistant cannot proceed further with the task. ...
说明:Terminate是OpenManus提供的一个终止任务执行的工具。
在运行以上命令,输出如下:
2025-03-09 10:23:39.485 | INFO | app.agent.toolcall:think:53 - ✨ Manus's thoughts: 2025-03-09 10:23:39.485 | INFO | app.agent.toolcall:think:54 - 🛠️ Manus selected 1 tools to use 2025-03-09 10:23:39.485 | INFO | app.agent.toolcall:think:58 - 🧰 Tools being prepared: ['terminate'] 2025-03-09 10:23:39.485 | INFO | app.agent.toolcall:execute_tool:140 - 🔧 Activating tool: 'terminate'... 2025-03-09 10:23:39.485 | INFO | app.agent.toolcall:_handle_special_tool:172 - 🏁 Special tool 'terminate' has completed the task! 2025-03-09 10:23:39.485 | INFO | app.agent.toolcall:act:113 - 🎯 Tool 'terminate' completed its mission! Result: Observed output of cmd `terminate` executed: The interaction has been completed with status: success Enter your prompt (or 'exit' to quit): exit
此时输入exit就可以退出了。
初步尝试了一下OpenManus,感觉上基本的多Agent框架已经有了,但工具只有3-4个,功能上还存在一些小的问题。个人认为类似Manus这样的多Agent系统,最大的优势就是利用产品化思维,把各种复杂的流程设计与调用都进行了封装,这样留给用户的是一个非常容易使用的界面接口。这样小白用户使用起来也非常的方便,可以享受AI带来的遍历。
原文链接:https://blog.csdn.net/zg_hover/article/details/146128593?ops_request_misc=%257B%2522request%255Fid%2522%253A%25225a0ac2e932c2e125d404092080aa64fb%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=5a0ac2e932c2e125d404092080aa64fb&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-21-146128593-null-null.nonecase&utm_term=manus