# ๐ฎ Lucy
### Your screen-aware AI companion for Android
**Lucy sees your screen, understands what's on it, and taps, types and swipes for you โ all from a voice command.**
[](https://github.com/alzin/lucy-screen-agent/releases/latest)
[](https://github.com/alzin/lucy-screen-agent/releases)
[](https://github.com/alzin/lucy-screen-agent/actions/workflows/ci.yml)
[](LICENSE)
[](https://flutter.dev)
[](https://developer.android.com)
[](https://ai.google.dev)
[](CONTRIBUTING.md)
[](https://ko-fi.com/alzin)

[Download](#-download--install) ยท [Quick Start](#-quick-start) ยท [How It Works](#-how-it-works) ยท [Contributing](CONTRIBUTING.md) ยท [Troubleshooting](#-troubleshooting)
---
### ๐ฌ Lucy in action
https://github.com/user-attachments/assets/2fd60821-7cae-42f9-aa20-763938b61d23
> *"There's an e-mail called 'my manager' in my e-mail list. I want you to send an
> e-mail with the subject 'Today's agenda' mentioning the team meeting at 10 AM."*
Lucy finds the contact, opens the compose screen, fills in the recipient, subject
and body, and sends it. Every tap and keystroke is hers.
---
> [!IMPORTANT]
> Lucy is an **experimental research project**. To work, she needs two of the most powerful permissions Android offers: **screen capture** and an **accessibility service** that can tap and type on your behalf. Read [Privacy & Security](#-privacy--security) before you install, and prefer a spare or test device.
---
## ๐ Table of Contents
- [What is Lucy?](#-what-is-lucy)
- [Features](#-features)
- [Download & Install](#-download--install)
- [How It Works](#-how-it-works)
- [Requirements](#-requirements)
- [Quick Start](#-quick-start)
- [Using Lucy](#-using-lucy)
- [Building & Releasing](#-building--releasing)
- [Project Structure](#-project-structure)
- [Troubleshooting](#-troubleshooting)
- [Privacy & Security](#-privacy--security)
- [Roadmap](#-roadmap)
- [Contributing](#-contributing)
- [Support the Project](#-support-the-project)
- [License](#-license)
---
## ๐ฎ What is Lucy?
Most voice assistants are limited to the apps their vendor integrated with. Lucy takes a different approach: instead of using APIs, **she uses the phone the way you do**.
Say *"Open WhatsApp and send Sarah a message saying I'm running late."* Lucy will:
1. ๐ Transcribe your voice
2. ๐ธ Take a screenshot of whatever is currently on screen
3. ๐ฒ Read the Android **accessibility tree** โ every button, label and text field with exact pixel bounds
4. ๐ค Send the screenshot **and** the UI tree to Google Gemini, which replies with a single next action
5. โก Execute that action through the accessibility service โ a real tap, a real keystroke
6. ๐ Take a fresh screenshot and repeat until the task is done
7. ๐ Speak the result back to you, in your language
Because Lucy works at the screen level, she works with **any app on your phone** โ no integration required.
### Who Lucy is for
Lucy started with a simple problem: **driving**. On a long drive you constantly want small things from your phone โ reply to a message, skip to another playlist, re-route to a petrol station โ and every one of them normally means picking the phone up. Lucy lets you ask out loud and keep both hands on the wheel.
That turned out to be one case out of several. The common thread is *your hands are busy, or using them is hard*:
| | |
|---|---|
| ๐ **Driving** | Reply, navigate and change music by voice, without reaching for the phone. |
| โฟ **Limited dexterity** | Tremor, arthritis, RSI, paralysis, or a temporary cast โ Lucy does the tapping. Screen readers describe a screen; Lucy actually operates it. |
| ๐ฉโ๐ณ **Hands full or dirty** | Cooking, workshop, gardening, gloves in winter, carrying a child or the shopping. |
| ๐ด **Unfamiliar with the phone** | Say what you want instead of hunting through five levels of settings menus. |
| ๐ **Tedious multi-step chores** | Anything buried eight taps deep across three apps becomes one sentence. |
| ๐งฉ **Apps with no automation** | No API, no Shortcuts support, no integration? Doesn't matter โ Lucy drives the UI itself. |
> [!WARNING]
> Lucy is a hands-free convenience, **not a safety device**. She is experimental and can act on the wrong element. If you use her while driving, set the command running before you move off and keep your eyes on the road โ never read or correct her mid-drive. Obey your local road traffic laws; in many countries, including Japan, operating or looking at a phone screen while the vehicle is moving is an offence regardless of how the phone is controlled.
---
## โจ Features
| | |
|---|---|
| ๐ฃ๏ธ **Voice-driven** | Speech-to-text in, text-to-speech out. No typing required. |
| ๐๏ธ **Screen-aware** | Combines a JPEG screenshot with a structured accessibility tree, so the model sees *and* reads the screen. |
| ๐ฏ **No hallucinated taps** | The model taps elements **by ID**, never by guessed coordinates. Real pixel bounds are resolved on the Dart side from the accessibility tree. |
| ๐ **Trilingual** | English ๐ฌ๐ง, Japanese ๐ฏ๐ต and Arabic ๐ธ๐ฆ โ with language detection and matching TTS/STT locales. |
| ๐ **Agentic loop** | Observe โ decide โ act โ re-observe, up to 50 steps per command. |
| ๐ **Always interruptible** | A persistent "Stop Lucy" notification cancels the agent instantly, even while she's inside another app. |
| ๐จ **Live transcript** | Every screenshot, action and reply is shown in a scrollable conversation view. |
| ๐ **Bring your own key** | Your Gemini API key stays on your device. No backend, no telemetry, no account. |
---
## ๐ฅ Download & Install
Every release ships a ready-to-install APK. You don't need Flutter, Android Studio,
or a computer at all โ just your phone.
That link never changes and always serves the **newest stable build**. If you want a
smaller download or a specific version, pick one from the
[Releases page](https://github.com/alzin/lucy-screen-agent/releases):
| File | Who it's for |
|---|---|
| `lucy-latest.apk` | The newest stable build, always at the same URL. Installs on any device. |
| `lucy-vX.Y.Z-arm64-v8a.apk` | **Most people** โ any Android phone from roughly 2017 onwards. Smallest download. |
| `lucy-vX.Y.Z-universal.apk` | Every CPU variant in one file. Larger, but installs anywhere. |
| `lucy-vX.Y.Z-armeabi-v7a.apk` | Older 32-bit phones. |
| `lucy-vX.Y.Z-x86_64.apk` | Emulators and x86 tablets. |
Each release also attaches `SHA256SUMS.txt` if you'd like to verify what you downloaded.
### Installing the APK
1. Tap the downloaded `.apk` โ from your notification shade, or in **Files โ Downloads**.
2. Android asks whether to allow installs from your browser or file manager. Allow it (**Settings โ Install unknown apps**), then tap **Install**.
3. Play Protect may warn that the developer is unknown. That's expected for any app not distributed through the Play Store โ tap **Install anyway** if you're happy to proceed.
### Then three more steps
Installing is only the beginning; Lucy is inert until she has her permissions and a key. The app walks you through each one:
| | | Where |
|---|---|---|
| โฟ | Enable Lucy's **accessibility service** โ this is how she taps and types | [Step 8](#-quick-start) |
| ๐ธ | Grant **screen capture** when the mic button asks | [Step 9](#-quick-start) |
| ๐ | Paste a free **Gemini API key** from [AI Studio](https://aistudio.google.com/app/apikey) | [Steps 6โ7](#-quick-start) |
> [!WARNING]
> Release APKs are currently signed with a **debug key**, so the signature isn't stable between builds. If you already have Lucy installed, **uninstall her before installing a newer version** โ otherwise Android refuses the update with `INSTALL_FAILED_UPDATE_INCOMPATIBLE`. See [docs/RELEASING.md](docs/RELEASING.md#signing).
Would rather build it yourself and read the code first? That's the [Quick Start](#-quick-start) below โ very reasonable, given what Lucy is allowed to do.
---
## ๐ง How It Works
```mermaid
flowchart TD
A([๐ค User speaks]) --> B[speech_to_text
transcription]
B --> C{{AgentController
agent loop}}
C -->|1 ยท observe| D[MediaProjection
screenshot โ JPEG]
C -->|1 ยท observe| E[AccessibilityService
UI tree โ JSON]
D --> F[[Google Gemini
vision + reasoning]]
E --> F
F -->|strict JSON:
one action + speak + done| G{done?}
G -->|no ยท 2 ยท act| H[AccessibilityService
tap / type / swipe / back / home]
H -->|3 ยท re-observe| C
G -->|yes| I[flutter_tts
speaks the answer]
I --> J([๐ User hears the result])
style F fill:#8E75B2,color:#fff
style C fill:#6C63FF,color:#fff
```
### The two sources of truth
Vision alone is unreliable for UI automation โ models guess coordinates and miss by 40 pixels. Lucy solves this by giving Gemini **both** a picture and a map:
```jsonc
// What Gemini receives alongside the screenshot
{
"package": "com.whatsapp",
"elements": [
{ "id": 5, "type": "Button", "text": "Send", "clickable": true,
"bounds": { "cx": 1012, "cy": 2180, "w": 120, "h": 120 } },
{ "id": 6, "type": "EditText", "desc": "Type a message", "editable": true,
"bounds": { "cx": 520, "cy": 2180, "w": 860, "h": 120 } }
]
}
```
Gemini replies with `{"type": "tap", "element": 5}` โ an **ID**, not a coordinate. Lucy looks up the real bounds and dispatches a gesture there. This single design choice is what makes the agent reliable.
### Available actions
| Action | Parameters | Effect |
|---|---|---|
| `open_app` | `package` | Launch an app by package name |
| `tap` | `element` | Tap the accessibility element with that ID |
| `type` | `text` | Type into the focused input field |
| `swipe` | `startX`, `startY`, `endX`, `endY` | Scroll or swipe |
| `back` | โ | Press the system back button |
| `home` | โ | Press the system home button |
| `wait` | `ms` | Pause before the next observation |
After each action Lucy waits for the screen to actually settle โ a package change, a UI-tree change, or a newly focused text field โ instead of sleeping a fixed amount of time.
---
## ๐ Requirements
| | Minimum | Notes |
|---|---|---|
| **Flutter** | Dart SDK `^3.11.1` | Verified on Flutter `3.47.1` / Dart `3.13.1` |
| **Android device** | Android 7.0 (API 24) | Targets API 36. **A physical device is strongly recommended** โ emulators often lack a usable STT/TTS engine |
| **JDK** | 17 | Bundled with recent Android Studio |
| **Gemini API key** | free tier works | Get one at [aistudio.google.com](https://aistudio.google.com/app/apikey) |
> [!NOTE]
> **Android only.** Screen capture and the action layer are implemented in Kotlin against Android APIs. There is no iOS target โ iOS does not permit this kind of system-wide control.
---
## ๐ Quick Start
### Step 1 โ Install Flutter
If you don't have Flutter yet, follow the [official install guide](https://docs.flutter.dev/get-started/install), then verify your setup:
```bash
flutter doctor
```
Make sure the **Android toolchain** row has a green check. Everything else (iOS, web, desktop) is irrelevant for Lucy.
### Step 2 โ Clone the repository
```bash
git clone https://github.com/alzin/lucy-screen-agent.git
```
```bash
cd lucy-screen-agent
```
### Step 3 โ Install dependencies
```bash
flutter pub get
```
### Step 4 โ Connect your Android device
1. On your phone, open **Settings โ About phone** and tap **Build number** seven times to unlock Developer options.
2. Go to **Settings โ Developer options** and enable **USB debugging**.
3. Plug the phone into your computer and accept the debugging prompt.
4. Confirm your computer can see it:
```bash
flutter devices
```
### Step 5 โ Run the app
```bash
flutter run
```
The first build downloads Gradle dependencies and can take several minutes. Later runs are much faster.
### Step 6 โ Get a Gemini API key
1. Open [Google AI Studio](https://aistudio.google.com/app/apikey).
2. Sign in and click **Create API key**.
3. Copy the key โ it starts with `AIza...`.
### Step 7 โ Add your key to Lucy
In the app, tap the ๐ **key icon** in the top bar, paste your key and hit **Save**. It is stored locally with `shared_preferences` and never leaves your device except in requests to Google's Gemini API.
### Step 8 โ Enable the accessibility service
Lucy cannot start without this โ it's how she taps and types.
1. The app shows an **"Accessibility Required"** screen on first launch. Tap **Open Settings**.
2. Navigate to **Installed apps** (wording varies by manufacturer) **โ Lucy**.
3. Toggle it **on** and accept the system warning.
4. Return to Lucy with the back button โ she detects the change automatically.
### Step 9 โ Grant screen capture
Tap the ๐ค **microphone button**. Android shows a **"Start recording or casting?"** dialog โ tap **Start now**. This grants the `MediaProjection` permission Lucy uses to screenshot.
### Step 10 โ Talk to her
Say something like:
> *"Open the calculator and work out 47 times 12."*
Watch the conversation view fill up with screenshots and actions. ๐
---
## ๐ฎ Using Lucy
### Example commands
| | Command |
|---|---|
| ๐ฑ | *"Open YouTube and search for lofi hip hop."* |
| โ๏ธ | *"Go to settings and turn on Bluetooth."* |
| ๐ | *"What's on my screen right now?"* |
| ๐ฌ | *"Open WhatsApp and message Mom that I'll call tonight."* |
| โฐ | *"Set an alarm for 7 in the morning."* |
Lucy asks *"Do you need any further help?"* after each completed task. Answer **"no"** (or "stop", "nothing") and she shuts down cleanly.
### Switching language ๐
Tap the ๐ **language selector** in the top bar to pick **English**, **ๆฅๆฌ่ช** or **ุงูุนุฑุจูุฉ**. This sets the speech-recognition locale.
Lucy also **detects the language you actually spoke** and replies in it โ the AI tags each response with a language code, and the app switches its TTS voice and follow-up prompts to match. Your choice persists across restarts.
### Stopping the agent ๐
Three ways, in order of urgency:
1. **The red stop button** in the app โ tap the mic button while she's running.
2. **The "Stop Lucy" notification** โ swipe down from anywhere, even inside another app, and tap **Stop Lucy**. This is the one you want when she's off doing something in a different app.
3. **Force-stop the app** from Android settings โ the nuclear option.
Lucy also stops herself automatically after **50 steps** on a single command, so she can never loop forever.
---
## ๐ฆ Building & Releasing
### Published releases are automatic
Nobody builds or uploads an APK by hand. [`.github/workflows/release.yml`](.github/workflows/release.yml) watches `main` and reads the `version:` in [`pubspec.yaml`](pubspec.yaml). When the semantic part โ everything before the `+` โ has no matching `vX.Y.Z` tag yet, it analyzes, tests, builds and publishes a GitHub Release with every APK attached.
So the version bump is the trigger, not the merge: merges that leave it alone produce no release, and bumping only the build number after the `+` doesn't either. Full details, including how to cut one, live in **[docs/RELEASING.md](docs/RELEASING.md)**.
### Building a release APK locally
```bash
flutter build apk --release
```
The APK lands in `build/app/outputs/flutter-apk/app-release.apk`. Without a keystore this is signed with the debug key โ fine for testing on your own device, not for distribution.
Signing it with your own key
**1. Create a keystore**
```bash
keytool -genkey -v -keystore lucy-release.jks -keyalg RSA -keysize 2048 -validity 10000 -alias lucy
```
**2. Create `android/key.properties`**
```properties
storePassword=
keyPassword=
keyAlias=lucy
storeFile=
```
Build again and Gradle picks it up automatically.
> [!WARNING]
> `key.properties`, `*.jks` and `*.keystore` are in `.gitignore`. **Never commit them.** Anyone with your keystore can publish updates impersonating your app.
To sign the *published* releases too, the same keystore goes into four repository secrets โ see [docs/RELEASING.md](docs/RELEASING.md#signing).
Building an App Bundle for the Play Store
```bash
flutter build appbundle --release
```
---
## ๐ Project Structure
```
lucy-screen-agent/
โโโ lib/
โ โโโ main.dart # App entry point, theme, LucyApp widget
โ โโโ screens/
โ โ โโโ home_screen.dart # Conversation UI, mic button, API-key dialog,
โ โ # accessibility gate, language selector
โ โโโ services/
โ โโโ agent_controller.dart # โญ The brain: agent loop, state machine,
โ โ # action execution, language handling
โ โโโ ai_service.dart # Gemini client, system prompt, JSON parsing
โ โโโ voice_service.dart # speech_to_text + flutter_tts wrapper
โ โโโ screen_capture_service.dart # Dart side of the platform channel
โ
โโโ android/app/src/main/kotlin/com/poc/screen_aware_ai/
โ โโโ MainActivity.kt # Method-channel host, MediaProjection consent
โ โโโ ScreenCaptureService.kt # Foreground service: VirtualDisplay โ JPEG
โ โโโ ScreenActionService.kt # AccessibilityService: UI tree + gestures
โ โโโ OverlayService.kt # Persistent "Stop Lucy" notification
โ
โโโ test/ # Widget tests
โโโ docs/
โ โโโ ARCHITECTURE.md # Deep dive for contributors
โ โโโ RELEASING.md # How versions become downloadable APKs
โโโ .github/workflows/
โโโ ci.yml # Format, analyze, test, debug APK
โโโ release.yml # Publishes a Release when the version bumps
```
**Data flow in one line:** `home_screen.dart` โ `agent_controller.dart` โ (`ai_service.dart` โ Gemini) โ `screen_capture_service.dart` โ `MethodChannel` โ Kotlin services โ Android.
๐ New contributors should read **[docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)** โ it explains the agent loop, the platform-channel contract, and how to add a new action.
---
## ๐ง Troubleshooting
"Accessibility Required" screen won't go away
Some manufacturers (Xiaomi, Oppo, Vivo, Samsung) bury accessibility toggles or silently revoke them.
- Look under **Settings โ Accessibility โ Installed apps / Downloaded apps โ Lucy**.
- On MIUI/ColorOS you may also need to disable battery optimisation for Lucy and enable **Autostart**.
- Fully close and reopen the app after enabling โ Lucy re-checks on resume, but a cold start is a reliable reset.
"Screen capture permission denied" or blank screenshots
- Tap the mic button again and accept the **"Start now"** dialog.
- On Android 14+, the MediaProjection token is **single-use**. If you switch away for a long time, Lucy re-requests permission automatically โ accept it again.
- Some apps set `FLAG_SECURE` (banking apps, Netflix) and their screens come back black. This is enforced by Android and cannot be worked around.
Lucy doesn't hear me / listening times out
- Grant the **microphone** permission (Android asks on first use).
- Make sure a speech-recognition engine is installed โ usually the *Google* app โ **Settings โ Voice**.
- Check that the language selected in the top bar matches the language you're speaking; the STT locale is set from it.
- Lucy retries listening 3 times, then stops and asks you to tap the mic again.
"โ ๏ธ Please set your Gemini API key first"
Tap the ๐ icon and paste a valid key from [AI Studio](https://aistudio.google.com/app/apikey). If it still fails, your key may be rate-limited or restricted โ check the quota page in AI Studio.
Lucy taps the wrong thing
This usually means the accessibility tree is incomplete โ some apps (games, or apps with poor semantics) expose very little. Check the conversation view: if the action summary shows a `tap` on an element that doesn't match, the UI tree given to the model was misleading. Please [open an issue](https://github.com/alzin/lucy-screen-agent/issues) with the app name and what you asked for.
Gradle build fails on first run
- Confirm JDK 17: `java -version`.
- Wipe and retry: `flutter clean`, then `flutter pub get`, then `flutter run`.
- `android/local.properties` is generated by Flutter and gitignored โ if it's missing, running `flutter run` once recreates it.
---
## ๐ Privacy & Security
Please read this before installing. Lucy is powerful precisely because she has deep access.
**What leaves your device**
- ๐ธ **Screenshots** (downscaled to max 1280px, JPEG quality 72) are sent to the **Google Gemini API** on every step of an active task.
- ๐ฒ The **accessibility tree** โ including any text visible on screen โ is sent with them.
- ๐ค **Voice** is transcribed by Android's speech recognizer, subject to your device's own settings.
**What does not**
- Lucy has **no backend**. There is no analytics, no crash reporting, no account, no server operated by this project.
- Your **API key** is stored locally in `shared_preferences` and only ever sent to Google.
**What this means in practice**
> [!CAUTION]
> While a task is running, **anything visible on your screen may be sent to Google** โ including messages, emails, banking screens and notifications. The accessibility service can also read text fields and dispatch taps. Don't run Lucy while sensitive information is on screen, and review [Google's Gemini API terms](https://ai.google.dev/gemini-api/terms) to understand how prompt data is handled on your tier.
**Recommendations**
- โ
Use a spare device, a test profile, or Android's Work Profile.
- โ
Stop Lucy (via the notification) before opening anything sensitive.
- โ
Revoke the accessibility service when you're not actively using the app.
- โ Never commit your API key, keystore, or `key.properties`.
Found a security issue? Please read **[SECURITY.md](SECURITY.md)** โ don't open a public issue.
---
## ๐บ๏ธ Roadmap
Ideas that would make great contributions. Comment on an issue or open one to claim it:
- [ ] ๐ **Confirmation gate** for destructive actions (sending messages, purchases, deletions)
- [ ] ๐งฉ **Pluggable AI backends** โ OpenAI, Anthropic, or a local model behind the `AiService` interface
- [ ] ๐ซ **App allowlist/blocklist** so Lucy can never touch chosen apps
- [ ] ๐พ **Persistent conversation history** across restarts
- [ ] ๐ **More languages** (see [CONTRIBUTING.md](CONTRIBUTING.md#-adding-a-language) โ it's a ~20-line change)
- [ ] ๐งช **Test coverage** for the `AgentController` state machine
- [ ] ๐ **Token/cost counter** in the UI
- [ ] โฟ **Better UI-tree extraction** for apps with weak accessibility semantics
---
## ๐ค Contributing
**Contributions are very welcome** โ this project is early and there's a lot of low-hanging fruit.
๐ Start with **[CONTRIBUTING.md](CONTRIBUTING.md)**. It covers the dev setup, code style, the PR process, and walkthroughs for adding a new agent action or language.
Good first issues are labelled [`good first issue`](https://github.com/alzin/lucy-screen-agent/labels/good%20first%20issue).
By participating you agree to the [Code of Conduct](CODE_OF_CONDUCT.md).
---
## โ Support the Project
Lucy is free, open source, and developed in spare time. If she saves you some of yours, you can chip in:
Support is entirely optional and buys no priority on issues or pull requests โ it just keeps the API bills paid and the roadmap moving. Starring the repo and filing good bug reports helps just as much.
---
## ๐ License
Released under the [MIT License](LICENSE).
---
**Built with Flutter and Google Gemini.**
If Lucy is useful to you, consider leaving a โญ โ it genuinely helps others find the project.
[Report a bug](https://github.com/alzin/lucy-screen-agent/issues/new?template=bug_report.yml) ยท [Request a feature](https://github.com/alzin/lucy-screen-agent/issues/new?template=feature_request.yml)