README.md
3.47 KB
LangGraph DEEPSEEK Agent 项目
这是一个使用 LangGraph 和 DEEPSEEK 模型构建的智能体项目,实现了天气查询功能。
🚀 项目特性
- DEEPSEEK 模型集成: 使用 DEEPSEEK 作为主要语言模型
- ReAct 智能体: 实现了推理和行动模式
- 工具调用: 支持天气查询工具
- LangGraph 服务: 提供 Web API 接口
- 环境配置: 支持 .env 环境变量配置
📁 项目结构
Test_LangGraph/
├── test_agent.py # 智能体实现
├── langgraph.json # LangGraph 配置
├── .env # 环境变量
├── requirements.txt # 依赖列表
├── start_langgraph.py # 启动脚本
├── test_api.py # API 测试脚本
└── README.md # 项目说明
🛠️ 安装和配置
1. 安装依赖
pip install -r requirements.txt
2. 配置环境变量
编辑 .env 文件,设置您的 DEEPSEEK API 密钥:
OPENAI_API_KEY=your-deepseek-api-key-here
OPENAI_BASE_URL=https://api.deepseek.com/v1
3. 运行智能体
直接运行
python test_agent.py
启动 LangGraph 服务
python start_langgraph.py
使用 LangGraph CLI
python -m langgraph_cli dev
🔧 API 使用
服务端点
- 服务地址: http://localhost:2025
- API 文档: http://localhost:2025/docs
- WebSocket: ws://localhost:2025/ws
测试 API
python test_api.py
手动测试
curl -X POST "http://localhost:2025/weather_agent/invoke" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "what is the weather in Beijing"}
]
}'
📊 功能演示
智能体对话流程
- 用户输入: "what is the weather in sf"
- AI 推理: "I'll check the weather in San Francisco for you."
-
工具调用: 调用
get_weather工具 - 工具响应: "It's always sunny in San Francisco!"
- AI 总结: "According to the weather information, it's always sunny in San Francisco!"
性能指标
- 模型: deepseek-chat
- Token 使用: 输入 189,输出 14,总计 203
- 缓存效率: 67% 缓存命中率
- 响应时间: 快速响应
🔍 技术细节
核心组件
- LangGraph: 智能体框架
- LangChain: 语言模型集成
- DEEPSEEK: 大语言模型
- ReAct 模式: 推理 + 行动
工具系统
- get_weather: 天气查询工具
- 参数: city (字符串)
- 返回: 模拟天气信息
🐛 故障排除
常见问题
-
依赖安装失败
pip install --upgrade pip pip install -r requirements.txt -
API 密钥错误
- 检查
.env文件中的 API 密钥 - 确保 DEEPSEEK API 密钥有效
- 检查
-
服务启动失败
- 检查端口 2025 是否被占用
- 确保所有依赖已正确安装
-
LangGraph CLI 问题
pip install -U "langgraph-cli[inmem]"
📝 开发说明
添加新工具
- 在
test_agent.py中定义工具函数 - 将工具添加到
tools列表 - 重新启动服务
修改模型配置
编辑 test_agent.py 中的 ChatOpenAI 配置:
model = ChatOpenAI(
model="deepseek-chat",
temperature=0.7
)
📄 许可证
本项目仅供学习和研究使用。
🤝 贡献
欢迎提交 Issue 和 Pull Request!
注意: 请确保您有有效的 DEEPSEEK API 密钥才能使用此项目。