feat: add structured result saving and main_params API #256
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.
更新日志 - 新功能说明
本文档记录了 Open-AutoGLM 项目的最新功能更新和使用说明。
🆕 新增功能
1. 结果输出功能 (
--output)功能说明
新增了
--output(或-o)参数,可以将任务执行结果保存到指定的文件中。结果统一以 JSON 数组 格式保存。使用方法
命令行方式:
编程方式:
输出说明
result保存到{output}文件示例
$ python main.py --output ./results/result.json "打开微信" Task: 打开微信 [执行过程...] Result: 任务完成 result保存到./results/result.json文件2. 结构化 JSON 输出与全量步骤保存 (
--all)功能说明
现在结果统一以 JSON 数组 格式保存。
新增了
--all参数,允许用户控制是仅保存最终结果,还是保存执行过程中的所有步骤结果。使用方法
命令行方式:
编程方式:
输出格式示例
仅保存最后结果时:
[ "任务完成" ]保存所有步骤时 (
--all):[ "正在打开微信", "已进入微信主界面", "任务完成" ]3. 编程接口
main_params()函数功能说明
新增了
main_params()函数,支持通过函数参数的方式调用主程序,方便从其他 Python 脚本中集成使用。函数签名
使用方法
基本示例:
完整示例:
参数说明
base_urlmodelapikeymax_stepsdevice_iddevice_typeoutputtaskallow_all_appssave_alllangquietwda_url4. 允许所有应用功能 (
--allow-all-apps)功能说明
新增了
--allow-all-apps参数,允许启动任何应用,不再限制在配置的应用列表中。当启用此选项时,可以直接使用应用的包名(Android)、Bundle ID(iOS)或 Bundle Name(HarmonyOS)来启动应用。使用方法
命令行方式:
编程方式:
使用场景
测试未配置的应用
python main.py --allow-all-apps "打开com.example.testapp"使用包名直接启动
动态应用管理
注意事项
allow_all_apps=True时,应用名称会被直接当作包名/Bundle ID使用5. 应用包名查询工具 (
scripts/get_package_name.py)功能说明
新增了一个实用的 Python 脚本工具,用于查询 Android 应用的包名。支持多种查询方式,方便开发者查找和添加新应用到配置中。
安装要求
使用方法
1. 列出所有第三方应用
2. 列出所有应用(包括系统应用)
3. 查看当前前台应用的包名
# 先打开你想查询的应用,然后运行: python scripts/get_package_name.py current4. 搜索包含关键词的包名
5. 查看应用的详细信息
6. 指定设备ID(多设备时)
使用示例
示例1:查找微信包名
$ python scripts/get_package_name.py search tencent 搜索包含 'tencent' 的包名: ------------------------------------------------------------ com.tencent.mm com.tencent.mobileqq com.tencent.qqmusic com.tencent.qqlive com.tencent.androidqqmail com.tencent.news 找到 6 个匹配的应用示例2:查看当前应用
示例3:获取应用详细信息
添加到配置文件
找到包名后,可以添加到
phone_agent/config/apps.py:其他查询方法
使用 ADB 命令直接查询:
📝 配置说明
环境变量支持
所有参数都支持通过环境变量设置:
🔧 完整使用示例
示例1:基本使用
python main.py "打开微信并发送消息给张三"示例2:保存结果到文件
python main.py --output ./results/result.json "打开微信"示例3:允许所有应用
python main.py --allow-all-apps "打开com.example.myapp"示例4:iOS设备使用
python main.py \ --device-type ios \ --wda-url http://localhost:8100 \ --output ./ios_results/res.json \ "打开Safari并搜索"示例5:编程集成
🐛 故障排除
问题1:无法保存结果文件
解决方案:
问题2:无法启动未配置的应用
解决方案:
--allow-all-apps参数scripts/get_package_name.py查找包名,然后添加到配置问题3:包名查询工具无法使用
解决方案:
adb devices📚 相关文件
main.py- 主程序文件,包含所有新功能phone_agent/config/apps.py- 应用配置映射scripts/get_package_name.py- 包名查询工具phone_agent/agent.py- Android/HarmonyOS Agentphone_agent/agent_ios.py- iOS Agent🔄 更新历史
最新更新
output参数为具体文件路径,支持 JSON 数组格式--output参数支持结果保存main_params()编程接口--allow-all-apps参数支持所有应用💡 提示
main_params()可以更好地集成到其他项目中