基于Tree of Thought思维树的多模态智能代理框架,支持复杂问题推理、多模态处理和任务规划。
AI_Agent_Learning/
├── src/ # 源代码
│ ├── tot/ # 思维树模块
│ │ ├── langgraph_tot.py # LangGraph版本
│ │ └── tot_orchestrator.py # 协调器版本
│ ├── agent/ # Agent模块
│ │ ├── multi_modal_agent.py # 多模态代理
│ │ └── planner_agent.py # 规划代理
│ ├── tools/ # 工具集
│ │ └── tools.py # 搜索、计算、RAG、图像分析等
│ └── prompts/ # 提示词
│ └── tot_prompts.py
├── main.py # 统一入口点
└── requirements.txt
确保 Docker Desktop 已安装并正在运行。
Windows:
- 启动 Docker Desktop 应用程序
- 等待系统托盘图标显示 Docker 已运行
使用构建脚本(推荐):
Windows (PowerShell):
.\build.ps1Linux/Mac:
chmod +x build.sh
./build.sh或手动构建:
docker build -t thinkflow:latest .或使用 docker-compose:
docker-compose build创建 .env 文件(见下方配置说明)
# 使用 Docker
docker run --rm -v $(pwd)/.env:/app/.env:ro thinkflow:latest tot --problem "你的问题"
# 使用 docker-compose
docker-compose run --rm thinkflow tot --problem "你的问题"pip install -r requirements.txt创建 .env 文件:
# 必需
OPENROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_API_BASE=https://openrouter.ai/api/v1
# 可选(用于搜索功能)
Custom_Google_Search_API=your_google_search_api_key
GOOGLE_CSE_ID=your_cse_id
# 可选(用于RAG)
EMBED_MODEL=BAAI/bge-small-zh-v1.5# 思维树 (LangGraph)
python main.py tot --problem "你的问题"
# 思维树 (协调器)
python main.py tot-orchestrator --problem "你的问题" --k 6
# 多模态Agent
python main.py multi-modal --input "问题" --image-url "图片URL"
# 规划Agent
python main.py planner --problem "你的任务"python -m src.tot.langgraph_tot
python -m src.agent.multi_modal_agent通过生成→评估→选择→优化的流程解决复杂问题。
两种实现:
langgraph_tot.py- LangGraph工作流(支持自动重试)tot_orchestrator.py- 协调器模式(简化版)
处理文本和图像,支持对话记忆。
将复杂任务自动分解为可执行的子任务。
deep_think- 深度思考推理simple_calculator- 计算器real_search- 网络搜索(需Google API)query_local_knowledge- 本地知识库查询(RAG)image_analyzer- 图像分析
# 思维树
from src.tot import run_tot
result = run_tot("你的问题")
# 多模态Agent
from src.agent import run_multi_modal_agent
response = run_multi_modal_agent("问题", "图片URL")
# 规划Agent
from src.agent import run_planner_agent
run_planner_agent("你的任务")详细的 Docker 使用说明请查看 DOCKER.md
注意: GitHub Actions 需要计费账户。如果遇到计费问题,请使用本地 Docker 构建(见 DOCKER.md)
Q: 导入错误 ModuleNotFoundError: No module named 'src'
A: 确保在项目根目录运行,或使用 python -m 方式。
Q: API密钥错误
A: 检查 .env 文件是否存在且配置正确。
Q: 模型不可用
A: 修改代码中的模型名称,使用可用的模型。
Q: Docker 容器无法访问 .env 文件
A: 确保使用 -v $(pwd)/.env:/app/.env:ro 挂载环境变量文件。
Windows (PowerShell):
.\deploy.ps1Linux/Mac:
chmod +x deploy.sh
./deploy.shgit init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/Lewis121025/ThinkFlow.git
git push -u origin main祝学习愉快! 🎉
Created with ❤️ by Lewis