add history (历史对话记录复用和JSON持久化) #172
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
功能描述
R实现了完整的历史对话管理功能,包括:
实现细节
1. 历史管理核心模块
HistoryManager类,负责历史记录的CRUD操作HistoryItem数据结构,包含完整的对话上下文FullReuseStrategy:复用完整历史上下文TaskBasedReuseStrategy:基于任务相关性复用历史2. JSON持久化实现
phone_agent_history.json文件3. PhoneAgent扩展
PhoneAgent类,集成历史管理功能run方法,支持历史记录复用get_history、list_history、clear_history4. CLI扩展
--history-id:指定要复用的历史记录ID--list-history:列出所有历史记录--clear-history:清空所有历史记录使用示例
1. 基本使用
2. 历史记录管理
相关文件修改
创建的文件
phone_agent/history/__init__.py:历史管理模块初始化phone_agent/history/manager.py:历史管理核心实现phone_agent/history/strategy.py:上下文复用策略修改的文件
phone_agent/agent.py:集成历史管理功能main.py:添加历史相关命令行参数优势与特点
总结
本次PR实现了完整的历史对话管理功能,支持智能历史复用和JSON持久化,提升了Phone Agent的用户体验和实用性。实现方式简单可靠,易于扩展和维护,为后续功能开发打下了良好的基础。