# iOS Agent Harness




**A natural-language GUI agent that runs on the iPhone itself.** Say what you want; it looks at
the screen, taps its way there, checks its own work, and keeps going until the task is done.
```
You: "Search Bilibili for Black Myth: Wukong and play the first video"
Agent: open Bilibili → tap search → type query → tap first result → playing ✓
```
One task, streaming live: each 🔧 is a tool call, each bubble is a role's
output — Manager naming the next subgoal, Reflector judging whether the last action landed.
## What makes it different
- **It runs on the phone, not next to it.** No Mac tethered over USB, no ADB-equivalent driving
it from a host. The agent loop lives in a `launchd` daemon on the device — close the app, switch
apps, kill the app, and the task keeps running.
- **Zero integration with the apps it drives.** It reads the screen and injects touches. Target
apps need no SDK, no accessibility opt-in, no scripting hooks — it works the same on native
UIKit, H5 webviews, and Unity-drawn game UI.
- **It's iOS.** Most open GUI agents target Android or the desktop, for a good reason: doing this
on iOS requires a jailbreak. This repo is the jailbreak-side plumbing, worked out and documented.
## Quick start
You need a jailbroken iPhone with ZXTouch and Activator installed, a Mac with Xcode, and an API
key for an OpenAI-compatible model endpoint. Full list under [Requirements](#requirements).
```bash
# 1. credentials — never compiled into the binary, pushed to the device at deploy time
cp scripts/agent-config.example.json scripts/agent-config.local.json
cp scripts/device-ssh.env.example scripts/device-ssh.local.env
$EDITOR scripts/agent-config.local.json scripts/device-ssh.local.env
# 2. build and deploy the daemon
make -C iOSAgentHarness/Agentd # compiles + ldid-signs agentd
./scripts/deploy-rootless.sh # or deploy-rooted.sh for unc0ver / checkra1n
# 3. build and install the app
cd iOSAgentHarness && xcodegen generate && open IOSAgentHarness.xcodeproj # then ⌘R
```
Confirm the daemon came up and found its credentials:
```bash
ssh mobile@ "launchctl list | grep com.hf.agentd"
ssh mobile@ "grep LLMConfig /var/mobile/Documents/agent.log" # expect: 已加载配置
```
Then open AgentApp, create a task, and type what you want. Detailed walkthrough, including the
TrollStore IPA needed for the Siri entry point, is in
[docs/project-guide/deployment.md](docs/project-guide/deployment.md).
## How it works
Two processes on the device. **AgentApp** (Swift/UIKit) is a thin client that renders events —
it makes no decisions and touches no private APIs. **agentd** (Objective-C, launchd-managed) runs
the agent loop, calls the models, and executes tools. They talk JSON Lines over TCP 6001, so any
number of UIs can attach to one running task.
Every capability that requires the jailbreak — screenshots via Activator, touch injection via
ZXTouch, app launching via `SpringBoardServices` — is funnelled through a single file,
[`Shared/Bridge/SystemBridge.m`](iOSAgentHarness/Shared/Bridge/SystemBridge.m).
**The loop is split across three roles**, each with its own prompt and its own view of the screen:
| Role | Sees | Decides |
|---|---|---|
| **Manager** | downscaled screenshot + step history | the next single atomic subgoal |
| **Executor** | full-resolution screenshot with a coordinate grid | which tool to call, with what arguments |
| **Reflector** | the before/after screenshot pair | whether that actually worked |
The Reflector returns one of four verdicts, and each drives a different recovery path: success,
wrong page (swipe back and replan), nothing changed (retry with a hint), or captcha (hand off to
a solver). Splitting these apart is what makes failures recoverable — a single-prompt agent that
mis-taps has no idea it mis-tapped. Entry point:
[`Agentd/AgentPipeline.m`](iOSAgentHarness/Agentd/AgentPipeline.m).
**Two models, split by job.** A strong reasoning model plans. A small vision model does nothing
but *grounding* — turning "tap the search box" into pixel coordinates. Coordinate arithmetic is a
poor use of expensive reasoning tokens, and the small model is better at it anyway.
**Skills** teach the agent app-specific flows. A skill is a Markdown file; only its name and
"when to use" line sit in the system prompt, and the model pulls the body on demand — so unused
skills cost almost nothing. Drop a `.md` into
[`Agentd/skills/`](iOSAgentHarness/Agentd/skills/) and rebuild;
[`safari-web-search.md`](iOSAgentHarness/Agentd/skills/safari-web-search.md) is a working example
that doubles as an annotated template.
## Related work
GUI agents are a crowded field. The honest positioning:
| Project | Platforms | Runs where |
|---|---|---|
| [Mobile-Agent](https://github.com/X-PLUG/MobileAgent) (Alibaba Tongyi Lab) | Android, desktop, browser | host-side Python driving the device |
| [AppAgent](https://github.com/TencentQQGYLab/AppAgent) (Tencent) | Android | host-side |
| [UI-TARS](https://github.com/bytedance/UI-TARS) (ByteDance) | desktop, mobile, browser | host-side; ships its own GUI model |
| Anthropic computer use / OpenAI Operator | desktop, browser | remote VM |
| **this project** | **iOS** | **on-device daemon** |
The planning / acting / reflecting split is close in spirit to Mobile-Agent's multi-agent
decomposition — that idea isn't novel here. What's different is the runtime shape: the agent is a
resident daemon on the phone rather than a script on a laptop driving it, which is only possible
because a jailbreak grants LaunchDaemon, private APIs, and an escape from the sandbox.
## Requirements
**Mac** — Xcode with command-line tools, plus:
```bash
brew install xcodegen ldid hudochenkov/sshpass/sshpass
```
Python 3 is only needed for the debug and trace-replay scripts.
**Jailbroken iPhone** — developed and tested on iOS 16.5 with Dopamine (rootless). Rooted
jailbreaks (unc0ver / checkra1n) have a parallel set of paths and plists. The deployment target is
iOS 12.0, but only the above configuration has real mileage. Required device packages:
| Package | Used for |
|---|---|
| [ZXTouch](https://github.com/xuan32546/IOS13-SimulateTouch) | touch injection (listens on port 6000) |
| Activator | triggering system screenshots and the home button |
| ElleKit / Substrate | injecting ZXTouch into SpringBoard (rootless only) |
**Models** — any OpenAI-compatible endpoint for the reasoning model, and optionally a Qwen3-VL
endpoint (ModelScope or DashScope) for grounding.
## Repository layout
```
iOSAgentHarness/
AgentApp/ Swift UI client (UIKit, frame layout, iOS 12 compatible)
Agentd/ Objective-C daemon: agent loop, LLM clients, tools, skills
Shared/Bridge/ SystemBridge — every private API / jailbreak call lives here
Shared/IPC/ wire protocol, mirrored in Swift and ObjC
Tests/ XCTest unit tests
scripts/ deploy, debug, and trace-replay tooling
docs/ architecture and subsystem guides
```
## Documentation
Start with **[docs/architecture-overview.md](docs/architecture-overview.md)** — how everything
fits together and why each tradeoff was made. From there:
[app shell and IPC](docs/project-guide/app-shell.md) ·
[system bridge](docs/project-guide/bridge.md) ·
[deployment](docs/project-guide/deployment.md) ·
[scripts](docs/project-guide/scripts.md) ·
[original design vision](docs/design.md) ·
[UI visual spec](docs/design_handoff_ios_agent_console/README.md)
The docs are written in Chinese; the code and its comments are the source of truth either way.
## Known limitations
- **Slow.** Three to four model round-trips per step puts each action at 10–15 seconds.
- **Blind to what isn't on screen.** Screenshot-driven perception is robust across H5 and
custom-drawn UI, where accessibility labels are usually missing — but it can't read state that
isn't rendered.
- **Narrow jailbreak coverage.** Only iOS 16.5 / Dopamine has been exercised properly.
- **The daemon has no unit tests.** The Objective-C loop is verified by running it plus the
trace-replay tooling; XCTest only covers the Swift side.
- **Payments are blocked by design.** `SafetyGuard` refuses taps on payment elements, and both
the Manager and Executor prompts are instructed to stop at checkout.
## Responsible use
This injects synthetic touch events into apps you did not write, on a device whose security model
has been deliberately disabled. Use it on **your own devices and your own accounts**, for
automation, testing, and research.
It includes CAPTCHA solvers, which exist because automated regression runs against your own test
accounts get interrupted by anti-bot challenges. Do not point them at services you don't own or
aren't authorized to test — defeating another party's anti-automation measures may violate their
terms of service and, depending on where you are, the law.
Jailbreaking voids your warranty and weakens platform security. What you build with this is your
responsibility.
## License
[MIT](LICENSE) · [中文文档](README.zh-CN.md)