OpenManus 是一个多功能AI代理框架,通过组合工具链实现复杂任务自动化。其核心功能包括:
Manusapp/agent/manus.py):classManus(ToolCallAgent):
available_tools=ToolCollection(
PythonExecute(),WebSearch(),BrowserUseTool(),FileSaver(),Terminate()
)
app/agent/planning.py):classPlanningAgent(ToolCallAgent):
asyncdefact():
# 执行工具并更新计划状态
classBaseTool:
name:str
description:str
asyncdefexecute(self,**kwargs):...
classWebSearch(BaseTool):
asyncdefexecute(self,query):
# 调用搜索引擎API
app/flow/flow_factory.py):classFlowFactory:
@staticmethod
defcreate_flow(flow_type):
ifflow_type==FlowType.PLANNING:
returnPlanningFlow(agents=agents)
# 推荐使用 uv 安装(片段4)
uv pipinstall-rrequirements.txt
python run_flow.py
config/config.toml):[llm]
model="gpt-4o"
api_key="sk-..."
app/config.py):classConfig:
defbrowser_config(self)->BrowserSettings:
# 返回浏览器设置参数
用户输入:
需要制定4月15-23日从西雅图出发的7日日本行程,预算2500-5000美元,包含历史遗迹、文化体验(剑道、茶道)和奈良鹿等元素,需生成带地图和日语短语的HTML手册。
执行流程:
WebSearch查询景点信息PythonExecuteBrowserUseToolFileSaverawaittool.execute(save_path="/output/travel_plan.html")
示例输出:
代理-工具协作:
classManus(ToolCallAgent):
asyncdefact():
tool=self.available_tools.get("WebSearch")
result=awaittool.execute(query)
流程执行器:
asyncdefrun_flow():
flow=FlowFactory.create_flow(FlowType.PLANNING)
awaitflow.execute(user_prompt)
# 新建 tool/my_tool.py
classMyTool(BaseTool):
name="my_tool"
asyncdefexecute(self,param):
# 实现工具逻辑
return"执行结果"
# 注册到代理
classCustomAgent(Manus):
available_tools.add_tool(MyTool())
# 修改 prompt/manus.py
SYSTEM_PROMPT="您现在是旅游规划专家..."
NEXT_STEP_PROMPT="优先使用WebSearch获取最新景点信息..."
OpenManus 通过模块化设计和强大的工具链,实现了从简单查询到复杂任务的全流程自动化。其核心优势在于:
通过本文的深度解析,开发者可以快速掌握该项目的核心原理和开发方法,实现从理解到实践的完整跨越。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |