openmanus.cpp/README.md

204 lines
5.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# OpenManus C++版本
这是OpenManus项目的C++实现版本旨在提供与原始Python版本相同的功能。
## 项目结构
```
cpp/
├── include/ # 头文件目录
│ ├── agent_base.h # 代理基类
│ ├── manus.h # Manus代理
│ ├── tool_base.h # 工具基类
│ ├── tool_call.h # 工具调用类
│ ├── tool_call_agent.h # 工具调用代理
│ ├── tool_collection.h # 工具集合类
│ ├── flow/ # 流程头文件目录
│ │ ├── base_flow.h # 流程基类
│ │ ├── planning_flow.h # 规划流程
│ │ └── flow_factory.h # 流程工厂
│ └── tools/ # 工具头文件目录
│ └── terminate.h # 终止工具
├── src/ # 源文件目录
│ ├── agent_base.cpp # 代理基类实现
│ ├── manus.cpp # Manus代理实现
│ ├── tool_base.cpp # 工具基类实现
│ ├── tool_call.cpp # 工具调用类实现
│ ├── tool_call_agent.cpp # 工具调用代理实现
│ ├── tool_collection.cpp # 工具集合类实现
│ ├── flow/ # 流程实现目录
│ │ ├── base_flow.cpp # 流程基类实现
│ │ ├── planning_flow.cpp # 规划流程实现
│ │ └── flow_factory.cpp # 流程工厂实现
│ └── tools/ # 工具实现目录
│ └── terminate.cpp # 终止工具实现
├── server/ # MCP服务器目录
│ ├── mcp_server_main.cpp # MCP服务器主程序
│ └── CMakeLists.txt # 服务器构建文件
├── main.cpp # 主程序入口
├── mcp/ # MCP协议库
└── CMakeLists.txt # CMake构建文件
```
## 已完成工作
1. **基础框架搭建**
- 创建了基本的项目结构和CMakeLists.txt文件
- 实现了基础代理类(AgentBase)
- 实现了工具集合类(ToolCollection)
- 实现了工具基类(ToolBase)
- 实现了工具调用类(ToolCall)
- 实现了工具调用代理类(ToolCallAgent)
- 实现了Manus代理类
2. **流程层实现**
- 实现了流程基类(BaseFlow)
- 实现了规划流程(PlanningFlow)
- 实现了流程工厂(FlowFactory)
- 修改了主程序,使用流程层执行任务
3. **工具实现**
- 实现了终止工具(Terminate),用于终止代理执行
- 实现了Python执行工具(PythonExecute)可以执行Python代码
4. **MCP服务器**
- 实现了基本的MCP服务器
- 实现了PythonExecute工具可以执行Python代码
5. **LLM集成**
- 使用httplib.h实现了与LLM API的通信
- 实现了think方法能够调用LLM API获取下一步行动
- 实现了工具调用的解析和执行
- 添加了Authorization头部支持API密钥认证
6. **配置系统**
- 实现了TOML格式的配置文件读取
- 支持从配置文件中读取LLM API、工具和代理等参数
- 支持在运行时指定配置文件路径
7. **编译与运行**
- 成功编译并运行了基本框架
- 解决了与MCP协议库的集成问题
## 未完成工作
1. **工具实现**
- Google搜索工具(GoogleSearch)
- 浏览器使用工具(BrowserUseTool)
- 文件保存工具(FileSaver)
- 其他工具...
2. **LLM集成完善**
- 添加更多的LLM模型支持
- 实现流式响应处理
- 添加更多的提示模板
3. **MCP协议完整集成**
- 完善客户端与MCP服务器的通信
- 实现完整的请求-响应流程
4. **错误处理与日志**
- 添加更完善的错误处理机制
- 实现日志记录功能
5. **测试与文档**
- 编写单元测试
- 编写集成测试
- 完善API文档
## 配置文件
OpenManus使用TOML格式的配置文件来配置LLM API、工具和代理等参数。默认配置文件为`config.toml`,位于可执行文件所在目录。
### 配置文件示例
```toml
# OpenManus配置文件
[llm]
# LLM API主机
host = "localhost"
# LLM API端口
port = 8000
# LLM API路径
path = "/chat/completions"
# LLM API密钥
api_key = "your_api_key_here"
# LLM模型名称
model = "gpt-3.5-turbo"
# 是否启用流式响应
stream = false
[tools]
# 是否启用Python执行工具
enable_python_execute = true
# 是否启用Google搜索工具
enable_google_search = false
# 是否启用浏览器使用工具
enable_browser_use = false
# 是否启用文件保存工具
enable_file_saver = false
[agent]
# 最大步骤数
max_steps = 30
# 系统提示
system_prompt = "你是Manus一个通用的智能助手可以使用多种工具解决各种任务。"
# 下一步提示
next_step_prompt = "请思考下一步行动,使用可用的工具来解决用户的问题。"
```
### 运行时指定配置文件
可以在运行时通过命令行参数指定配置文件路径:
```bash
./openmanus_cpp /path/to/your/config.toml
```
## 构建与运行
### 构建主程序
```bash
cd cpp
mkdir -p build
cd build
cmake ..
make
```
### 运行主程序
```bash
./openmanus_cpp
```
### 构建MCP服务器
```bash
cd cpp/server
mkdir -p build
cd build
cmake ..
make
```
### 运行MCP服务器
```bash
./openmanus_mcp_server
```
## 依赖
- C++17
- CMake 3.10+
- nlohmann/json (包含在mcp/common目录中)
- httplib.h (包含在项目中)
- Python 3 (用于PythonExecute工具)
- LLM API服务 (如OpenAI API或本地部署的LLM服务)
## 许可证
与原始OpenManus项目相同的许可证。