引言

DroidRun 是一个强大的框架,用于通过 LLM 代理控制 Android 设备。它允许您使用自然语言命令自动化 Android 设备交互。

特点

  • 使用自然语言命令控制 Android 设备

  • 支持多个 LLM 提供商(OpenAI、Anthropic、Gemini)

  • 易于使用的 CLI

  • 用于自定义自动化的可扩展 Python API

  • 屏幕截图分析,直观了解设备

开始使用

前提条件
  • 系统已安装adb工具

  • 通过 USB 或 ADB 通过 TCP/IP 连接 Android 设备或模拟器

  • Android或模拟器上已安装DroidRun Portal 应用程序

  • 至少一个受支持的 LLM 提供程序的 API 密钥(OpenAI、Anthropic、Gemini)

新建项目

打开Pycharm新建项目droidrun-demo

设置环境
安装依赖

在Pycharm里打开终端输入命令:

pip install droidrun
安装DroidRun Portal

下载link:https://github.com/droidrun/droidrun-portal

下载完成后使用adb命令安装

adb install /Users/wan/Downloads/App/droidrun.apk
设置API key

在droidrun-demo目录打开终端输入命令

touch .env

我用的是Gemini,配置如下:

# Choose at least one of these based on your preferred provider
export GEMINI_API_KEY="***"

然后保存,输入命令

source .env
编写脚本
# coding=utf-8
import asyncio
import os
from droidrun.agent.react_agent import ReActAgent
from droidrun.agent.llm_reasoning import LLMReasoner
from dotenv import load_dotenv# Load environment variables from .env file
load_dotenv()async def main():# Create an LLM instancellm = LLMReasoner(llm_provider="gemini",  # Can be "openai", "anthropic", or "gemini"model_name="gemini-2.5-pro-preview-03-25",  # Choose appropriate model for your providerapi_key=os.environ.get("GEMINI_API_KEY"),  # Get API key from environmenttemperature=0.2,vision=True  # Enable vision capabilities)# Create and run the agentagent = ReActAgent(task="打开Chrome,搜索droidrun",llm=llm,vision=True  # Enable screenshot analysis)steps = await agent.run()print(f"Execution completed with {len(steps)} steps")if __name__ == "__main__":asyncio.run(main())
运行脚本

输出结果

INFO:droidrun:Vision capabilities enabled: screenshot tool available
INFO:droidrun:Using provided LLM reasoner: provider=gemini, model=gemini-2.5-pro-preview-03-25
INFO:droidrun:Using first available device: emulator-5554
INFO:droidrun:Connected to device: emulator-5554
INFO:droidrun:🎯 GOAL: 打开Chrome,搜索droidrun
INFO:droidrun:Token usage before API call: {'prompt_tokens': 0, 'completion_tokens': 0, 'total_tokens': 0, 'api_calls': 0}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #1
INFO:droidrun:This call: 713 prompt + 225 completion = 938 tokens
INFO:droidrun:Cumulative: 713 prompt + 225 completion = 938 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 713, 'completion_tokens': 225, 'total_tokens': 938, 'api_calls': 1}
INFO:droidrun:🤔 THOUGHT: I need to open the Chrome browser first. I will check the clickable elements on the current screen to see if the Chrome icon is present.
INFO:droidrun:🔄 ACTION: get_clickables()
ERROR:droidrun:Error executing tool get_clickables: Error getting clickable elements: Error retrieving clickable elements: Failed to find the JSON file path in logcat after 10 seconds
INFO:droidrun:👁️ OBSERVATION: Error: Error getting clickable elements: Error retrieving clickable elements: Failed to find the JSON file path in logcat after 10 seconds
INFO:droidrun:Token usage before API call: {'prompt_tokens': 713, 'completion_tokens': 225, 'total_tokens': 938, 'api_calls': 1}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #2
INFO:droidrun:This call: 785 prompt + 174 completion = 959 tokens
INFO:droidrun:Cumulative: 1498 prompt + 399 completion = 1897 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 1498, 'completion_tokens': 399, 'total_tokens': 1897, 'api_calls': 2}
INFO:droidrun:🤔 THOUGHT: The previous attempt to get clickable elements failed. This could be due to various reasons, possibly a temporary issue with the UI automation framework or the device state. To get a better understanding of the current screen and confirm if Chrome is visible, I will take a screenshot.
INFO:droidrun:🔄 ACTION: take_screenshot()
INFO:droidrun:Screenshot compressed successfully: 588.2KB → 56.8KB (90.3% reduction)
INFO:droidrun:👁️ OBSERVATION: Screenshot captured and available for analysis
INFO:droidrun:Token usage before API call: {'prompt_tokens': 1498, 'completion_tokens': 399, 'total_tokens': 1897, 'api_calls': 2}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #3
INFO:droidrun:This call: 1139 prompt + 196 completion = 1335 tokens
INFO:droidrun:Cumulative: 2637 prompt + 595 completion = 3232 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 2637, 'completion_tokens': 595, 'total_tokens': 3232, 'api_calls': 3}
INFO:droidrun:🤔 THOUGHT: The screenshot confirms that the Chrome icon is visible on the home screen dock. I need to tap it to open the browser. I will attempt to get the clickable elements again to find the index for the Chrome icon.
INFO:droidrun:🔄 ACTION: get_clickables()
ERROR:droidrun:Error executing tool get_clickables: Error getting clickable elements: Error retrieving clickable elements: Failed to find the JSON file path in logcat after 10 seconds
INFO:droidrun:👁️ OBSERVATION: Error: Error getting clickable elements: Error retrieving clickable elements: Failed to find the JSON file path in logcat after 10 seconds
INFO:droidrun:Token usage before API call: {'prompt_tokens': 2637, 'completion_tokens': 595, 'total_tokens': 3232, 'api_calls': 3}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #4
INFO:droidrun:This call: 947 prompt + 312 completion = 1259 tokens
INFO:droidrun:Cumulative: 3584 prompt + 907 completion = 4491 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 3584, 'completion_tokens': 907, 'total_tokens': 4491, 'api_calls': 4}
INFO:droidrun:🤔 THOUGHT: The `get_clickables` tool is consistently failing, preventing me from identifying the Chrome icon's index for tapping. However, I know the goal is to open Chrome. A more robust way to achieve this, especially when UI interaction tools are unreliable, is to start the app directly using its package name. The package name for Google Chrome is 'com.android.chrome'. I will use the `start_app` tool to launch Chrome.
INFO:droidrun:🔄 ACTION: start_app(package=com.android.chrome)
INFO:droidrun:👁️ OBSERVATION: Started com.android.chrome
INFO:droidrun:Token usage before API call: {'prompt_tokens': 3584, 'completion_tokens': 907, 'total_tokens': 4491, 'api_calls': 4}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #5
INFO:droidrun:This call: 1068 prompt + 144 completion = 1212 tokens
INFO:droidrun:Cumulative: 4652 prompt + 1051 completion = 5703 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 4652, 'completion_tokens': 1051, 'total_tokens': 5703, 'api_calls': 5}
INFO:droidrun:🤔 THOUGHT: Chrome has been successfully launched. Now I need to find the search/address bar to input the search query 'droidrun'. I will use `get_clickables` to identify the elements on the current Chrome screen.
INFO:droidrun:🔄 ACTION: get_clickables()
ERROR:droidrun:Error executing tool get_clickables: Error getting clickable elements: Error retrieving clickable elements: Failed to find the JSON file path in logcat after 10 seconds
INFO:droidrun:👁️ OBSERVATION: Error: Error getting clickable elements: Error retrieving clickable elements: Failed to find the JSON file path in logcat after 10 seconds
INFO:droidrun:Token usage before API call: {'prompt_tokens': 4652, 'completion_tokens': 1051, 'total_tokens': 5703, 'api_calls': 5}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #6
INFO:droidrun:This call: 1156 prompt + 980 completion = 2136 tokens
INFO:droidrun:Cumulative: 5808 prompt + 2031 completion = 7839 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 5808, 'completion_tokens': 2031, 'total_tokens': 7839, 'api_calls': 6}
INFO:droidrun:🤔 THOUGHT: The `get_clickables` tool is consistently failing, preventing me from identifying the search bar in Chrome. However, when Chrome starts, the address bar is often focused by default. I will attempt to directly input the search query 'droidrun' assuming the address bar is already focused.
INFO:droidrun:🔄 ACTION: input_text(text=droidrun)
INFO:droidrun:👁️ OBSERVATION: Text input completed: droidrun
INFO:droidrun:Token usage before API call: {'prompt_tokens': 5808, 'completion_tokens': 2031, 'total_tokens': 7839, 'api_calls': 6}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #7
INFO:droidrun:This call: 1241 prompt + 277 completion = 1518 tokens
INFO:droidrun:Cumulative: 7049 prompt + 2308 completion = 9357 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 7049, 'completion_tokens': 2308, 'total_tokens': 9357, 'api_calls': 7}
INFO:droidrun:🤔 THOUGHT: I have successfully inputted the search query 'droidrun' into what I assume is the address/search bar in Chrome. The next logical step to perform the search is to press the Enter key. The keycode for Enter is 66. I will use the `press_key` tool to simulate this action.
INFO:droidrun:🔄 ACTION: press_key(keycode=66)
INFO:droidrun:👁️ OBSERVATION: Pressed key 66
INFO:droidrun:Token usage before API call: {'prompt_tokens': 7049, 'completion_tokens': 2308, 'total_tokens': 9357, 'api_calls': 7}
INFO:httpx:HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/openai/chat/completions "HTTP/1.1 200 OK"
INFO:droidrun:===== Token Usage Statistics =====
INFO:droidrun:API Call #8
INFO:droidrun:This call: 1331 prompt + 300 completion = 1631 tokens
INFO:droidrun:Cumulative: 8380 prompt + 2608 completion = 10988 tokens
INFO:droidrun:=================================
INFO:droidrun:Token usage after API call: {'prompt_tokens': 8380, 'completion_tokens': 2608, 'total_tokens': 10988, 'api_calls': 8}
INFO:droidrun:🤔 THOUGHT: The sequence of actions indicates that Chrome was opened, the search term 'droidrun' was entered, and the Enter key was pressed. This completes the user's request to open Chrome and search for 'droidrun'. The search results page should now be displayed in Chrome. Therefore, the goal has been achieved.
INFO:droidrun:🔄 ACTION: complete(result=Opened Chrome and initiated a search for 'droidrun'.)
INFO:droidrun:👁️ OBSERVATION: Task completed: Opened Chrome and initiated a search for 'droidrun'.
INFO:droidrun:👁️ OBSERVATION: Goal achieved in 8 steps.===== Final Token Usage and Cost =====
Total Tokens Used: 10,988
Total API Calls: 8
Estimated Cost: $0.0011
===================================Summary: Task completed: Opened Chrome and initiated a search for 'droidrun'.
Execution completed with 26 steps

更多使用文档参考:https://www.droidrun.ai/

总结

体验了一下droidrun,感觉一言难尽,相比传统 App UI自动化来说:

1.执行测试的速度很慢,上面的脚本也才2个步骤

2.执行1次测试调用API会产生费用,Estimated Cost: $0.0011,而传统UI自动化没有这种成本,随着脚本的复杂度提高,产生的成本也不便宜

3.从测试效果比较也不如传统UI自动化测试

不知道其他LLM(OpenAI、Anthropic)的效果如何,支不支持DeepSeek,感兴趣的同学可以自行测试效果!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/89560.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/89560.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/89560.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

免费文件管理 智能转换GC-Prevue:PDF 转 Word 多种格式 一键完成

前言 在现代办公环境中,高效的数据处理和文档管理是提高工作效率的关键。GC-Prevue是一款专为Windows系统设计的办公辅助软件,软件下载地址安装包 它通过一系列实用的功能,帮助用户更高效地处理和管理文档,提升整体办公效率。 软…

Java SE--运算符和逻辑控制

大多数和c语言一样 新增补充&#xff1a; 一.运算符 1.左移&#xff08;<<&#xff09; 结果公式&#xff1a; n*2^x (n代表所要位移的数&#xff0c;x代表位移几位) 2.右移&#xff08;>>&#xff09; 结果公式&#xff1a; n/2*x (n代表所要位移的数&a…

如何配置core dump生成

文章目录 **一、临时配置&#xff08;当前会话有效&#xff09;**1. **设置core文件大小限制**2. **设置core文件命名格式&#xff08;可选&#xff09;** **二、永久配置&#xff08;所有会话生效&#xff09;**1. **修改系统限制配置**2. **修改内核参数** **三、高级配置选项…

小程序包上传大小超限制处理

背景。想要进行真机测试&#xff0c;体验版。但是单机上传操作之后。提示超大晓限制。上传操作 完成填写后上传 上传后超过限制。能看到图片下方有错误提示。可以根据提示处理包大小问题。 解决方案&#xff1a;待续

JS | 动态生成函数 和 保存局部变量

动态生成函数 和 保存局部变量&#xff0c;适用于 闭包 和 高阶函数&#xff0c;存在于异步编程、事件处理、回调函数以及函数式编程中。 动态生成函数&#xff1a;运行时创建函数。 闭包&#xff1a;创建一个可以访问外部作用域变量的函数。 Function 构造函数&#xff1a;使…

设计模式(七)

迭代器模式&#xff08;Iterator Pattern&#xff09;详解 一、核心概念 迭代器模式提供一种方法来顺序访问一个聚合对象中的各个元素&#xff0c;而又不暴露该对象的内部表示。该模式将遍历逻辑封装在迭代器对象中&#xff0c;使聚合对象和遍历逻辑分离。 核心组件&#xf…

24年OPPO秋季笔试题

257. 小欧过河 链接&#xff1a;https://kamacoder.com/problempage.php?pid1337 思路&#xff1a;这道题的实际需要求的就是在两个11之间&#xff0c;最多能有多少个0。可以记录在遍历序列的时候&#xff0c;记录有最多个0的1的两个下标&#xff0c;最后再返回其差值。要注…

处理Lombok的一个小BUG

对于Lombok报错的修改 一、问题描述 在使用IDEA创建spring boot项目时如果你勾选了Lombok&#xff0c;生成的Lombok会随着maven的刷新而改变处理器的扫描路径&#xff0c;从项目类变到自定义的处理器路径 二、原因与解决方法 原因就是这里写了Lombok的路径才会导致你每次刷新都…

【Java入门到精通】(一)Java发展历程与环境搭建指南

一、Java的发展 Java是在1991年由SUN公司的James Gosling&#xff08;Java之父&#xff09;及其团队所研发的一种编程语言&#xff0c;第一个版本耗时18个月&#xff0c;最开始命名为Oak&#xff08;一种橡树&#xff09;。Java现在广泛应用于各种大型互联网应用&#xff0c;其…

【RK3568+PG2L50H开发板实验例程】Linux部分/UAR读写案例

本原创文章由深圳市小眼睛科技有限公司创作&#xff0c;版权归本公司所有&#xff0c;如需转载&#xff0c;需授权并注明出处&#xff08;www.meyesemi.com) 1.1. 案例简介 本案例旨在介绍如何测试开发板上的 UART 串口通信功能。 开发板支持的串口及其对应的设备节点如下表所…

Webpack 中的 Loader 和 Plugin 全面详解

&#x1f3af; Webpack 中的 Loader 和 Plugin 全面详解 &#x1f4cc; 整理不易&#xff0c;记得收藏、点赞再加关注&#xff0c;后续还会更新更多实战文档&#xff01; Webpack 是现代前端构建体系的核心工具&#xff0c;其中 Loader 和 Plugin 是其功能扩展的两大支柱。它们…

主流分布式中间件及其选型

分布式架构中的中间件技术 在互联网公司的分布式架构中&#xff0c;中间件是支撑系统高可用、高并发、可扩展的核心组件。这些中间件针对分布式环境下的共性问题&#xff08;如通信、数据一致性、资源调度等&#xff09;提供标准化解决方案&#xff0c;极大降低了分布式系统的…

设备需求极致紧凑的空间体验,我们该如何解决?

在自动化集成过程&#xff0c;往往会碰到设备对控制系统体积有极致要求的情况&#xff0c;面对这样的挑战&#xff0c;如何解决&#xff1f; 项目背景与需求分析 在自动化集成过程&#xff0c;往往会碰到设备对控制系统体积有极致要求的情况&#xff0c;面对这样的挑战&#x…

Kotlin扩展函数与属性

扩展函数和属性是Kotlin中最具特色的功能之一&#xff0c;它们允许我们在不修改原有类的情况下为类添加新功能。这种设计既保持了类的封装性&#xff0c;又提供了强大的扩展能力。 一、扩展函数&#xff1a;为现有类添加新行为 1.1 基础扩展函数 扩展函数允许我们为任何类&am…

厨师上门做饭小程序源码php方案

厨师上门做饭小程序源码&#xff0c;开发语言后端php&#xff0c;前端uniapp。可二开定制 三个端&#xff1a;用户端师傅端小程序&#xff0c;pc管理后台。 一 用户端 1.单点大厨&#xff1a;选择厨师预约下单&#xff0c;查看厨师评价、厨师的套餐。 2.点套餐&#xff1a;选择…

LLM大模型如何访问MySQL业务数据库

目录 一、LLM大模型如何访问MySQL业务数据库 1.1 为什么需要SQL Agent? 1.2 什么是 create_sql_agent&#xff1f; 1.3 什么是SQLDatabaseToolkit? 二、SQL Agent智能体操作MySQL数据库 三、本地启动服务 验证效果 四、怎么提高SQL Agent智能体的回复准确性&#xff1…

MySQL(112)如何选择读写分离策略?

选择读写分离策略是实施读写分离的关键一步。常见的读写分离策略包括简单的读写分离和基于负载均衡的读写分离。为了实现这些策略&#xff0c;我们需要动态地选择数据源。下面详细介绍如何实现基于Spring Boot的读写分离&#xff0c;并结合代码示例展示不同策略的实现。 读写分…

日志-解决Linux因target is busy无法卸载硬盘/分区的问题 - PHP持续占用分区

效果图 写在前面 此次遇到的问题是&#xff0c;php-fpm持续占用设备/mnt/disk1&#xff0c;强制杀死php所有进程后&#xff0c;依然会自动产生新的进程再次霸占分区&#xff0c;导致设备无法卸载umount。思路是解决谁在不停的捣乱。 步骤 核心&#xff1a; 挂载文件系统到指定…

Linux系统权限维持篇

Openssh后门 重新安装自定义的openssh&#xff0c;达到记录账户密码&#xff0c;也可以采用万能密码连接的功能 1、登录方式 2、登录软件 3、登录机制 环境准备 yum -y install openssl openssl-devel pam-devel zlib zlib-devel yum -y install gcc gcc-c makewget http://c…

spring中maven缺少包如何重新加载,报错java: 程序包org.springframework.web.reactive.function不存在

错误原因分析 java: 程序包org.springframework.web.reactive.function不存在 这个错误是由于 项目中缺少 Spring WebFlux 相关依赖 导致的。org.springframework.web.reactive.function 包属于 Spring WebFlux 模块&#xff08;用于响应式 Web 开发&#xff09;&#xff0c;如…