AI自動化神器-DroidRun使用體驗

引言

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;如…