第一章习题 #527
Unanswered
gcthomas
asked this question in
💬 Exercises & Q&A
第一章习题
#527
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
在 1.3 节的智能旅行助手基础上,请思考如何添加以下功能(可以只描述设计思路,也可以进一步尝试代码实现):
记忆功能思路如下:
智能旅行助手 - 记忆偏好功能需求规格说明书
1. 现有代码分析
1.1 核心功能逻辑
当前
FirstAgentTest.py实现了一个基于 ReAct 模式的智能旅行助手:get_weather(city: str): 查询指定城市的实时天气get_attraction(city: str, weather: str): 根据城市和天气推荐旅游景点1.2 当前限制
2. 记忆功能需求
2.1 核心目标
让智能体能够记住和利用用户偏好,提供更个性化的旅行建议。
2.2 需要记忆的信息类型
2.2.1 用户偏好配置
2.2.2 历史交互记录
2.2.3 会话上下文
2.3 功能需求
2.3.1 记忆存储
code/chapter1/user_preferences.json{ "user_id": "default", "preferences": { "attraction_types": [], "budget": {"min": 0, "max": null}, "transport_mode": null, "activity_level": null, "preferred_time": null, "group_size": null, "special_requirements": [] }, "history": { "searched_cities": [], "accepted_recommendations": [], "rejected_recommendations": [] }, "last_updated": "2024-01-01T00:00:00" }2.3.2 记忆读取
2.3.3 记忆更新
2.3.4 记忆使用
3. 技术实现方案
3.1 架构设计
3.2 核心组件设计
3.2.1 MemoryManager 类
3.2.2 工具函数增强
3.2.3 System Prompt 增强
3.3 实现步骤
步骤 1: 创建 MemoryManager 类
code/chapter1/memory_manager.py步骤 2: 修改工具函数
get_attraction()函数,接收preferences参数update_preference()工具函数步骤 3: 修改主循环
步骤 4: 添加偏好提取逻辑
update_preference()保存提取的偏好步骤 5: 测试验证
4. 数据示例
4.1 用户偏好文件示例
{ "user_id": "default", "preferences": { "attraction_types": ["历史文化", "博物馆"], "budget": {"min": 50, "max": 300}, "transport_mode": "公共交通", "activity_level": "轻松", "preferred_time": "周末", "group_size": 2, "special_requirements": [] }, "history": { "searched_cities": ["北京", "上海"], "accepted_recommendations": ["故宫博物院", "国家博物馆"], "rejected_recommendations": ["长城"] }, "last_updated": "2024-01-15T10:30:00" }4.2 个性化推荐示例
用户输入: "推荐一个北京的好去处"
系统思考过程:
5. 扩展性考虑
5.1 未来增强方向
5.2 技术优化
6. 风险与限制
6.1 潜在风险
6.2 缓解措施
7. 验收标准
Beta Was this translation helpful? Give feedback.
All reactions