A Local, Firewall-Protected, Accessibility-Based Android Agent designed for high-security environments (GrapheneOS) using the Jamba-Reasoning-3B model via JNI.
The system is defined by three strict boundaries:
- Component:
AgentAccessibilityService - Role: Passive collection of UI state
- Security: No business logic - pure observation
- Component:
native-lib.cpp(JNI) with C++23 modules - Role: Host to llama.cpp instance running Jamba-3B
- Security Layers:
- Ingress: Regex sanitizer strips control tokens
- Context: Wraps user data in XML tags
- Egress: GBNF grammar enforces strict JSON output
- Component:
ActionDispatcher - Role: Parses validated JSON from the Cortex
- Security: Checks actions against safe list, requires physical Volume Up confirmation for destructive actions
app/
├── src/main/
│ ├── cpp/ # Native C++23 code
│ │ ├── sentinel.cppm # C++23 module
│ │ ├── native-lib.cpp # JNI bridge
│ │ └── CMakeLists.txt # Build config
│ ├── java/com/mazzlabs/sentinel/
│ │ ├── core/ # Native bridge
│ │ ├── service/ # Accessibility service
│ │ ├── security/ # Action firewall
│ │ ├── input/ # Voice input
│ │ ├── overlay/ # Floating button
│ │ ├── tts/ # Text-to-speech
│ │ └── ui/ # Configuration UI
│ ├── assets/
│ │ └── agent.gbnf # JSON grammar
│ └── res/ # Android resources
└── build.gradle.kts
- Android Studio: Ladybug (2024.2.1) or newer
- Android NDK: r27+ (for C++23 module support)
- CMake: 3.28+
- Target SDK: 34 (Android 14)
- Min SDK: 34
- Device: ARM64 (arm64-v8a)
./scripts/setup_llama.shDownload a GGUF model (e.g., Jamba-Reasoning-3B-Q4_K_M.gguf) and copy to device:
adb push jamba-3b-q4.gguf /data/local/tmp/./scripts/deploy.shOr manually:
./gradlew assembleDebug
adb install -r app/build/outputs/apk/debug/app-debug.apk
adb push app/src/main/assets/agent.gbnf /data/local/tmp/- Enable Service: Open Sentinel Agent → Enable accessibility service
- Load Model: Enter model path → Load Model
- Activate: Tap floating overlay button or use voice trigger
- Command: Speak or type your command
- Confirm: For destructive actions, press Volume Up to confirm
- Strips LLM control tokens (
<|system|>,[INST], etc.) - Blocks dangerous shell commands (
rm -rf,dd, etc.) - XML-escapes user content to prevent injection
- GBNF grammar ensures ONLY valid JSON output
- Restricted action vocabulary:
CLICK,SCROLL,TYPE,HOME,BACK,WAIT,NONE
- Heuristic analysis of action targets
- Dangerous actions require physical Volume Up confirmation
- Safe list for benign operations
- 100% on-device processing
- No network permissions
- No data exfiltration possible
The grammar enforces this JSON structure:
{
"action": "CLICK|SCROLL|TYPE|HOME|BACK|WAIT|NONE",
"target": "optional element identifier",
"text": "optional text for TYPE",
"direction": "UP|DOWN|LEFT|RIGHT for SCROLL",
"confidence": 0.0-1.0,
"reasoning": "explanation"
}MIT License - See LICENSE file
- llama.cpp - Inference engine
- GrapheneOS - Security-focused Android