fix precommit

This commit is contained in:
liuyongbin
2025-12-18 15:52:13 +08:00
parent 728c53f512
commit 4b30344f15
3 changed files with 292 additions and 38 deletions

View File

@@ -39,7 +39,11 @@ Phone Agent is a mobile intelligent assistant framework built on AutoGLM. It und
Python 3.10 or higher is recommended.
### 2. ADB (Android Debug Bridge)
### 2. Device Debug Tools
Choose the appropriate tool based on your device type:
#### For Android Devices - Using ADB
1. Download the official ADB [installation package](https://developer.android.com/tools/releases/platform-tools) and extract it to a custom path
2. Configure environment variables
@@ -53,7 +57,22 @@ Python 3.10 or higher is recommended.
- Windows configuration: Refer to [third-party tutorials](https://blog.csdn.net/x2584179909/article/details/108319973) for configuration.
### 3. Android 7.0+ Device or Emulator with `Developer Mode` and `USB Debugging` Enabled
#### For HarmonyOS Devices - Using HDC
1. Download HDC tool:
- From [HarmonyOS SDK](https://developer.huawei.com/consumer/en/download/)
2. Configure environment variables
- MacOS/Linux configuration:
```bash
# Assuming the extracted directory is ~/Downloads/harmonyos-sdk/toolchains. Adjust according to actual path.
export PATH=${PATH}:~/Downloads/harmonyos-sdk/toolchains
```
- Windows configuration: Add the HDC tool directory to the system PATH environment variable
### 3. Android 7.0+ or HarmonyOS Device with `Developer Mode` and `USB Debugging` Enabled
1. Enable Developer Mode: The typical method is to find `Settings > About Phone > Build Number` and tap it rapidly about 10 times until a popup shows "Developer mode has been enabled." This may vary slightly between phones; search online for tutorials if you can't find it.
2. Enable USB Debugging: After enabling Developer Mode, go to `Settings > Developer Options > USB Debugging` and enable it
@@ -63,7 +82,11 @@ Python 3.10 or higher is recommended.
![Permissions](resources/screenshot-20251210-120416.png)
### 4. Install ADB Keyboard (for Text Input)
### 4. Install ADB Keyboard (Required for Android Devices Only, for Text Input)
**Note: HarmonyOS devices use native input methods and do not require ADB Keyboard.**
If you are using an Android device:
Download the [installation package](https://github.com/senzhk/ADBKeyBoard/blob/master/ADBKeyboard.apk) and install it on the corresponding Android device.
Note: After installation, you need to enable `ADB Keyboard` in `Settings > Input Method` or `Settings > Keyboard List` for it to work.(or use command `adb shell ime enable com.android.adbkeyboard/.AdbIME`[How-to-use](https://github.com/senzhk/ADBKeyBoard/blob/master/README.md#how-to-use))
@@ -77,7 +100,9 @@ pip install -r requirements.txt
pip install -e .
```
### 2. Configure ADB
### 2. Configure ADB or HDC
#### For Android Devices
Make sure your **USB cable supports data transfer**, not just charging.
@@ -92,6 +117,20 @@ adb devices
# emulator-5554 device
```
#### For HarmonyOS Devices
Make sure your **USB cable supports data transfer**, not just charging.
Ensure HDC is installed and connect the device via **USB cable**:
```bash
# Check connected devices
hdc list targets
# Output should show your device, e.g.:
# 7001005458323933328a01bce01c2500
```
### 3. Start Model Service
You can choose to deploy the model service yourself or use a third-party model service provider.
@@ -188,20 +227,29 @@ Upon successful execution, the script will display the model's inference result
Set the `--base-url` and `--model` parameters according to your deployed model. For example:
```bash
# Interactive mode
# Android device - Interactive mode
python main.py --base-url http://localhost:8000/v1 --model "autoglm-phone-9b-multilingual"
# Specify model endpoint
# Android device - Specify task
python main.py --base-url http://localhost:8000/v1 "Open Maps and search for nearby coffee shops"
# HarmonyOS device - Interactive mode
python main.py --device-type hdc --base-url http://localhost:8000/v1 --model "autoglm-phone-9b-multilingual"
# HarmonyOS device - Specify task
python main.py --device-type hdc --base-url http://localhost:8000/v1 "Open Maps and search for nearby coffee shops"
# Use API key for authentication
python main.py --apikey sk-xxxxx
# Use English system prompt
python main.py --lang en --base-url http://localhost:8000/v1 "Open Chrome browser"
# List supported apps
# List supported apps (Android)
python main.py --list-apps
# List supported apps (HarmonyOS)
python main.py --device-type hdc --list-apps
```
### Python API
@@ -226,29 +274,47 @@ print(result)
## Remote Debugging
Phone Agent supports remote ADB debugging via WiFi/network, allowing device control without a USB connection.
Phone Agent supports remote ADB/HDC debugging via WiFi/network, allowing device control without a USB connection.
### Configure Remote Debugging
#### Enable Wireless Debugging on Phone
##### Android Devices
Ensure the phone and computer are on the same WiFi network, as shown below:
![Enable Wireless Debugging](resources/screenshot-20251210-120630.png)
#### Use Standard ADB Commands on Computer
##### HarmonyOS Devices
Ensure the phone and computer are on the same WiFi network:
1. Go to `Settings > System & Updates > Developer Options`
2. Enable `USB Debugging` and `Wireless Debugging`
3. Note the displayed IP address and port number
#### Use Standard ADB/HDC Commands on Computer
```bash
# Connect via WiFi, replace with the IP address and port shown on your phone
# Android device - Connect via WiFi, replace with the IP address and port shown on your phone
adb connect 192.168.1.100:5555
# Verify connection
adb devices
# Should show: 192.168.1.100:5555 device
# HarmonyOS device - Connect via WiFi
hdc tconn 192.168.1.100:5555
# Verify connection
hdc list targets
# Should show: 192.168.1.100:5555
```
### Device Management Commands
#### Android Devices (ADB)
```bash
# List all connected devices
adb devices
@@ -263,8 +329,26 @@ adb disconnect 192.168.1.100:5555
python main.py --device-id 192.168.1.100:5555 --base-url http://localhost:8000/v1 --model "autoglm-phone-9b-multilingual" "Open TikTok and browse videos"
```
#### HarmonyOS Devices (HDC)
```bash
# List all connected devices
hdc list targets
# Connect to remote device
hdc tconn 192.168.1.100:5555
# Disconnect specific device
hdc tdisconn 192.168.1.100:5555
# Execute task on specific device
python main.py --device-type hdc --device-id 192.168.1.100:5555 --base-url http://localhost:8000/v1 --model "autoglm-phone-9b-multilingual" "Open TikTok and browse videos"
```
### Python API Remote Connection
#### Android Devices (ADB)
```python
from phone_agent.adb import ADBConnection, list_devices
@@ -289,6 +373,27 @@ print(f"Device IP: {ip}")
conn.disconnect("192.168.1.100:5555")
```
#### HarmonyOS Devices (HDC)
```python
from phone_agent.hdc import HDCConnection, list_devices
# Create connection manager
conn = HDCConnection()
# Connect to remote device
success, message = conn.connect("192.168.1.100:5555")
print(f"Connection status: {message}")
# List connected devices
devices = list_devices()
for device in devices:
print(f"{device.device_id} - {device.connection_type.value}")
# Disconnect
conn.disconnect("192.168.1.100:5555")
```
### Remote Connection Troubleshooting
**Connection Refused:**
@@ -320,14 +425,15 @@ You can directly modify the corresponding config files to enhance model capabili
### Environment Variables
| Variable | Description | Default Value |
|---------------------------|---------------------------|----------------------------|
| `PHONE_AGENT_BASE_URL` | Model API URL | `http://localhost:8000/v1` |
| `PHONE_AGENT_MODEL` | Model name | `autoglm-phone-9b` |
| `PHONE_AGENT_API_KEY` | API key for authentication| `EMPTY` |
| `PHONE_AGENT_MAX_STEPS` | Maximum steps per task | `100` |
| `PHONE_AGENT_DEVICE_ID` | ADB device ID | (auto-detect) |
| `PHONE_AGENT_LANG` | Language (`cn` or `en`) | `en` |
| Variable | Description | Default Value |
|-----------------------------|---------------------------|----------------------------|
| `PHONE_AGENT_BASE_URL` | Model API URL | `http://localhost:8000/v1` |
| `PHONE_AGENT_MODEL` | Model name | `autoglm-phone-9b` |
| `PHONE_AGENT_API_KEY` | API key for authentication| `EMPTY` |
| `PHONE_AGENT_MAX_STEPS` | Maximum steps per task | `100` |
| `PHONE_AGENT_DEVICE_ID` | ADB/HDC device ID | (auto-detect) |
| `PHONE_AGENT_DEVICE_TYPE` | Device type (`adb` or `hdc`)| `adb` |
| `PHONE_AGENT_LANG` | Language (`cn` or `en`) | `en` |
### Model Configuration
@@ -399,6 +505,8 @@ This allows you to clearly see the AI's reasoning process and specific operation
## Supported Apps
### Android Apps
Phone Agent supports 50+ mainstream Chinese applications:
| Category | Apps |
@@ -411,6 +519,25 @@ Phone Agent supports 50+ mainstream Chinese applications:
Run `python main.py --list-apps` to see the complete list.
### HarmonyOS Apps
Phone Agent supports 60+ HarmonyOS native apps and system apps:
| Category | Apps |
|--------------------------|----------------------------------------------------------------------------------------|
| Social & Messaging | WeChat, QQ, Weibo, Feishu, Enterprise WeChat |
| E-commerce & Shopping | Taobao, JD.com, Pinduoduo, Vipshop, Dewu, Xianyu |
| Food & Delivery | Meituan, Meituan Waimai, Dianping, Haidilao |
| Travel & Navigation | 12306, Didi, Tongcheng, Amap, Baidu Maps |
| Video & Entertainment | Bilibili, Douyin, Kuaishou, Tencent Video, iQIYI, Mango TV |
| Music & Audio | QQ Music, Qishui Music, Ximalaya |
| Lifestyle & Social | Xiaohongshu, Zhihu, Toutiao, 58.com, China Mobile |
| AI & Tools | Doubao, WPS, UC Browser, CamScanner, Meitu |
| System Apps | Browser, Calendar, Camera, Clock, Cloud, File Manager, Gallery, Contacts, SMS, Settings |
| Huawei Services | AppGallery, Music, Video, Books, Themes, Weather |
Run `python main.py --device-type hdc --list-apps` to see the complete list.
## Available Actions
The Agent can perform the following actions: