code/chapter13/helloagents-trip-planner/README.md
基于HelloAgents框架构建的智能旅行规划助手,集成高德地图MCP服务,提供个性化的旅行计划生成。
helloagents-trip-planner/
├── backend/ # 后端服务
│ ├── app/
│ │ ├── agents/ # Agent实现
│ │ │ └── trip_planner_agent.py
│ │ ├── api/ # FastAPI路由
│ │ │ ├── main.py
│ │ │ └── routes/
│ │ │ ├── trip.py
│ │ │ └── map.py
│ │ ├── services/ # 服务层
│ │ │ ├── amap_service.py
│ │ │ └── llm_service.py
│ │ ├── models/ # 数据模型
│ │ │ └── schemas.py
│ │ └── config.py # 配置管理
│ ├── requirements.txt
│ ├── .env.example
│ └── .gitignore
├── frontend/ # 前端应用
│ ├── src/
│ │ ├── components/ # Vue组件
│ │ ├── services/ # API服务
│ │ ├── types/ # TypeScript类型
│ │ └── views/ # 页面视图
│ ├── package.json
│ └── vite.config.ts
└── README.md
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# 编辑.env文件,填入你的API密钥
uvicorn app.api.main:app --reload --host 0.0.0.0 --port 8000
cd frontend
npm install
# 创建.env文件, 填入高德地图Web API Key 和 Web端JS API Key
cp .env.example .env
npm run dev
http://localhost:5173在首页填写旅行信息:
点击"生成旅行计划"按钮
系统将:
查看结果:
from hello_agents import SimpleAgent, HelloAgentsLLM
from hello_agents.tools import MCPTool
# 创建高德地图MCP工具
amap_tool = MCPTool(
name="amap",
server_command=["uvx", "amap-mcp-server"],
env={"AMAP_MAPS_API_KEY": "your_api_key"},
auto_expand=True
)
# 创建旅行规划Agent
agent = SimpleAgent(
name="旅行规划助手",
llm=HelloAgentsLLM(),
system_prompt="你是一个专业的旅行规划助手..."
)
# 添加工具
agent.add_tool(amap_tool)
Agent可以自动调用以下高德地图MCP工具:
maps_text_search: 搜索景点POImaps_weather: 查询天气maps_direction_walking_by_address: 步行路线规划maps_direction_driving_by_address: 驾车路线规划maps_direction_transit_integrated_by_address: 公共交通路线规划启动后端服务后,访问 http://localhost:8000/docs 查看完整的API文档。
主要端点:
POST /api/trip/plan - 生成旅行计划GET /api/map/poi - 搜索POIGET /api/map/weather - 查询天气POST /api/map/route - 规划路线欢迎提交Pull Request或Issue!
CC BY-NC-SA 4.0
HelloAgents智能旅行助手 - 让旅行计划变得简单而智能 🌈