How raulvidis/hermes-android works
1. High-level topology
- The repo implements a two-sided Android remote-control system:
- an Android bridge app on the phone
- a Python toolset/relay layer on the Hermes server side
- The phone does not accept inbound connections; it connects outward to the server over a WebSocket. The server exposes an HTTP interface used by the AI agent/tooling.
2. Primary control flow
- The main data path is: AI agent → server tools → relay → phone bridge → Android Accessibility APIs.
- The phone returns device state back through the same path, including accessibility tree data, screenshots, foreground app info, and event/notification state.
3. Android bridge app boundary
- hermes-android-bridge/ is the runtime that lives on the device.
- It is a Kotlin/Android app built around:
- BridgeAccessibilityService for UI inspection and UI actions
- BridgeNotificationListener for notification capture
- BridgeServer / BridgeRouter for local HTTP development or bridge endpoints
- RelayClient for outbound connection to the Hermes server
4. Interaction execution layer on Android
- ActionExecutor, ScreenReader, and ScreenNode form the UI automation core.
- This layer translates remote commands into Android accessibility interactions such as tap, type, swipe, scroll, back/home/recent keys, and reading the current screen tree.
- The architecture is intentionally accessibility-driven rather than UI-scraping driven.
5. Device state capture on Android
- ScreenRecorder handles screenshot capture.
- EventStore and NotificationStore track recent device events and notifications for retrieval by the agent.
- These stores suggest the bridge is stateful on-device, not purely stateless RPC.
6. Session setup and trust
- PairingManager handles pairing-code-based authentication.
- The pairing code is the trust bootstrap for linking a phone to a Hermes server; once paired, the server address is entered into the app and the device keeps an outbound relay connection.
- This is a security boundary: the app grants broad device-control capability only after pairing.
7. Lifecycle, visibility, and power management
- BridgeApplication and MainActivity provide the Android app shell and setup UI.
- StatusOverlay gives a persistent on-device status indicator.
- WakeLockManager keeps the bridge alive during active control sessions.
- The presence of these pieces indicates the app is meant to behave like a service, not just a foreground UI.
8. Server-side Python tool layer
- hermes-android-plugin/, tools/, and tests/ contain the Python side.
- This layer publishes the android_* tools consumed by hermes-agent; the README notes the production copy lives in the hermes-agent repo, while this repo is for development/testing.
- The plugin packaging (plugin.yaml, skill.md, skills/android/SKILL.md) is what makes the tools installable into Hermes.
9. Relay and transport responsibility on the server
- The server-side relay is responsible for connecting agent tool calls to the Android bridge over the network.
- The README indicates a WebSocket + HTTP relay on port 8766, with pairing/authentication and rate limiting.
- The contrib/ directory includes a daemon/service wrapper (hermes-relay-daemon.py, hermes-android-relay.service) for persistent relay operation.
10. Repository packaging and deployment model
- The repo is split into two deployable units:
- an Android Gradle project under hermes-android-bridge/
- a Python package/plugin at the root and under hermes-android-plugin/
- This separation reflects the real boundary in the system: device runtime vs. server integration.
11. Testing and validation
- tests/ covers the Python relay/tool behavior.
- Android behavior is built/tested through the Gradle project.
- The tests are centered on the server-side control plane, which is the part most likely to be reused inside hermes-agent.
12. External dependency boundary
- The bridge app depends on Android platform services: AccessibilityService, notification access, and screenshot capture APIs.
- The system also depends on the Hermes server/agent ecosystem; this repo is not a standalone phone-control product by itself.
13. What to show in an architecture diagram
- Draw three main boxes:
- Android phone runtime: accessibility service, relay client, screenshot/event/notification capture
- Hermes server: relay + android_* tools/plugin
- Hermes agent: invokes tools and receives device state
- Connect them with an outbound WebSocket from phone to server and an HTTP/tool invocation path from agent to server.
- Mark the Android AccessibilityService boundary as the point where remote commands become real device actions.
Main entry points: BridgeAccessibilityService.kt Accessibility · android_tool.py Android tools · android_relay.py Android relay · BridgeApplication.kt Bridge app
Components 23
Android bridge
Device-side Kotlin app that runs on the phone and executes accessibility-driven control.
- Bridge app · Android runtime shell and setup UI.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/BridgeApplication.kt - Main screen · User-facing setup and configuration entrypoint.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/MainActivity.kt - Pairing · Bootstraps trust with pairing-code authentication.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/auth/PairingManager.kt - Relay client · Outbound connection from phone to Hermes server.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/client/RelayClient.kt - Accessibility · Receives remote UI commands and inspects the screen tree.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeAccessibilityService.kt - Notifications · Captures device notifications for remote retrieval.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/service/BridgeNotificationListener.kt - Action exec · Translates remote commands into taps, typing, scrolling, and key actions.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ActionExecutor.kt - Screen reader · Builds readable state from the current accessibility tree.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/executor/ScreenReader.kt - Screen node · Structured representation of accessibility tree elements.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/model/ScreenNode.kt - Screenshots · Captures device screenshots for the agent.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/media/ScreenRecorder.kt - Event store · Keeps recent device events on-device.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/event/EventStore.kt - Notification store · Keeps recent notifications on-device.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/notification/NotificationStore.kt - Status overlay · Persistent on-device status indicator.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/overlay/StatusOverlay.kt - Wake lock · Keeps the bridge alive during active sessions.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/power/WakeLockManager.kt - Bridge server · Local HTTP bridge endpoint and development server.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeServer.kt - Router · Routes bridge requests to device capabilities.
hermes-android-bridge/app/src/main/kotlin/com/hermesandroid/bridge/server/BridgeRouter.kt
Server tools
Python relay and plugin layer that exposes Android control tools to the Hermes ecosystem.
- Android tools · Public android_* tool surface used by the Hermes agent.
hermes-android-plugin/android_tool.py - Android relay · Server-side relay between tool calls and the phone bridge.
hermes-android-plugin/android_relay.py - Plugin spec · Packaged plugin metadata for Hermes installation.
hermes-android-plugin/plugin.yaml - Skill docs · Tool usage and skill packaging metadata.
hermes-android-plugin/skill.md - Android skill · Android-specific skill definition.
skills/android/SKILL.md
Packaging
Repo-level packaging, install, and daemonization assets.
- Relay daemon · Persistent relay process for server deployment.
contrib/hermes-relay-daemon.py - Systemd unit · Service definition for running the relay as a daemon.
contrib/hermes-android-relay.service
Connections 23
- Main screen → Pairing: starts pairing · The setup UI initiates trust bootstrap.
- Pairing → Relay client: enables · Paired devices open the outbound relay connection.
- Relay client → Android relay: connects · Phone sends state and receives commands through the server relay.
- Android relay → Android tools: serves tools · Relay backs the android_* tool interface exposed to the agent.
- Android tools → Accessibility: invokes actions · Tool calls become device-control commands.
- Accessibility → Action exec: delegates · Accessibility service hands remote intents to the automation core.
- Action exec → Screen reader: reads state · Action layer requests current screen structure before or after actions.
- Screen reader → Screen node: produces · Readable accessibility output is normalized into screen nodes.
- Accessibility → Screenshots: captures · Device screenshots are collected for remote consumption.
- Accessibility → Event store: records · Recent device events are persisted locally.
- Notifications → Notification store: records · Notifications are stored for later retrieval.
- Accessibility → Notifications: listens with · Notification access is part of the bridge runtime.
- Bridge app → Bridge server: hosts · The Android app includes a local HTTP bridge surface.
- Bridge server → Router: routes · Requests are dispatched to bridge capabilities.
- Bridge app → Status overlay: shows · Persistent overlay communicates bridge status.
- Bridge app → Wake lock: keeps alive · Power management supports long-running sessions.
- Android relay → Relay daemon: deploys as · Relay can run as a persistent service wrapper.
- Relay daemon → Systemd unit: configured by · System service file supports deployment.
- Plugin spec → Android tools: packages · Plugin metadata exposes the tool surface to Hermes.
- Skill docs → Android tools: documents · Skill docs describe the tool behavior.
- Android skill → Android tools: specializes · Android-specific skill content narrows the toolset.
- Android relay → Relay client: bridges · Server relay connects tool invocation to the phone's outbound channel.
- Accessibility → Screen reader: inspects · Accessibility boundary is where remote intent becomes UI state access.