Mobile Agent Guardian
A five-level safety and verification layer for embodied mobile agents that provides auditable, secure phone control through vision classification, verify-after-act loops, and cryptographic anchoring.
README
Mobile Agent Guardian
A five-level safety and verification layer for embodied mobile agents running in pi.
Mobile Agent Guardian turns raw Appium/MCP phone control into an auditable, verified protocol:
observe → classify → authorize → act → verify → record → anchor
It was designed for the unusual same-device flow where pi runs in Termux and controls that same Android phone through wireless ADB and Appium. It also works when Appium targets another Android or iOS device.
Architecture
┌──────────────────────────────────────┐
│ Planning Agent │
│ (decomposes tasks, delegates work) │
└────────┬────────────────┬────────────┘
│ delegation │ delegation
│ token │ token
┌────────▼────────┐ ┌────▼───────────┐
│ Mobile Worker │ │ Browser Worker │
│ (Appium MCP) │ │ (Playwright) │
└────────┬────────┘ └────┬───────────┘
│ │
┌────────▼────────────────▼───────────┐
│ Mobile Agent Guardian │
│ │
│ L1 Vision classifier │
│ L2 Verify-after-act loop │
│ L3 Playwright policy bridge │
│ L4 Cryptographic anchoring │
│ L5 Multi-agent delegation │
│ │
│ Policy · Audit chain · Redaction │
└──────────┬───────────────┬──────────┘
│ │
┌──────────▼──┐ ┌─────────▼──────────┐
│ Appium MCP │ │ Remote Playwright │
│ UiAutomator │ │ (Modal / headless) │
└──────┬──────┘ └─────────┬──────────┘
│ │
┌──────▼──────┐ ┌─────────▼──────────┐
│ Device │ │ Cloud Chromium │
│ (ADB/WiFi) │ │ (DOM + JS + Net) │
└─────────────┘ └────────────────────┘
Five levels
Level 1: Vision classifier (src/vision.ts)
Sends screenshots to an OpenAI-compatible vision endpoint for structured risk classification. Returns labels: login, credentials, consent, payment, destructive, safe. Falls back to text heuristics from accessibility output when no vision API is configured.
GUARDIAN_VISION_API_KEY=sk-... GUARDIAN_VISION_BASE_URL=https://api.openai.com/v1 GUARDIAN_VISION_MODEL=gpt-4o-mini
Level 2: Verify-after-act loop (src/verifier.ts)
After every non-trivial mutation, captures a post-action fingerprint, diffs against the pre-action state, and classifies the outcome as expected, unexpected, unchanged, failed, or timeout. Two consecutive unexpected outcomes freeze the verifier—blocking all further mutations until the human observes the screen or runs /mobile-guard unfreeze.
Level 3: Playwright bridge (src/playwright-bridge.ts)
Exposes guardian_browse for web DOM access through a remote Playwright MCP endpoint. All calls pass through Guardian's policy engine and are audited. Configure with:
GUARDIAN_PLAYWRIGHT_URL=https://your-workspace--pi-frontend-mcp-web.modal.run/mcp
Level 4: Cryptographic anchoring (src/anchor.ts)
Periodically posts the latest audit hash + sequence number to a remote append-only endpoint, signed with HMAC-SHA256 using a device-local secret. Enables third-party verification that no events were removed from the chain.
GUARDIAN_ANCHOR_URL=https://your-anchor-endpoint/api/anchor
GUARDIAN_ANCHOR_INTERVAL=50
Level 5: Multi-agent delegation (src/delegation.ts)
Authority tokens scope what sub-agents can do:
- Allowed tool patterns (glob syntax)
- Maximum risk ceiling (critical is never delegatable)
- TTL and usage limits
- Auto-revocation on policy violation (configurable violation threshold)
Tools: guardian_delegate, guardian_revoke, guardian_check_delegation.
Install
pi install git:github.com/salus-ryan/mobile-agent-guardian
Or test a checkout:
npm install
pi -e ./src/index.ts
Quick start
# Minimal: text heuristics only, no external dependencies
pi -e ./src/index.ts
# With vision classification
GUARDIAN_VISION_API_KEY=sk-... pi -e ./src/index.ts
# With remote Playwright
GUARDIAN_PLAYWRIGHT_URL=https://... pi -e ./src/index.ts
# Monitor mode (log without enforcing)
MOBILE_GUARD_MODE=monitor pi -e ./src/index.ts
Behavior
Observation and navigation remain low-friction. When screen content contains authentication, OAuth, credential, permission, financial, or destructive indicators, Guardian changes state:
- Classify: vision model or text heuristics label the screen.
- Gate: sensitive mutation requires a fresh observation (< 30s) and human confirmation.
- Act: the mutation executes.
- Verify: post-action fingerprint is compared against pre-action state.
- Freeze (if needed): two consecutive unexpected outcomes block further mutations.
- Record: every step is hashed into the tamper-evident audit chain.
- Anchor: periodically signed and posted to remote storage.
OAuth URLs trigger a human handoff boundary: the agent may open the provider, but subsequent taps or typing cross the guarded boundary.
Commands and tools
| Name | Type | Purpose |
|---|---|---|
/mobile-guard |
Command | Show state, verifier, audit integrity |
/mobile-guard unfreeze |
Command | Clear verifier freeze |
mobile_guard_status |
Tool | Model-callable status and audit verification |
guardian_browse |
Tool | Policy-gated remote Playwright navigation |
guardian_delegate |
Tool | Create scoped delegation token |
guardian_revoke |
Tool | Revoke a delegation token |
guardian_check_delegation |
Tool | Check token authorization |
Audit evidence
Logs are written with mode 0600 to:
~/.pi/agent/mobile-guardian/audit-YYYY-MM-DD.jsonl
Every record includes the previous record's SHA-256 hash. Editing, deleting, or reordering an interior event breaks verification. Raw page source and sensitive argument values are not stored; the log records hashes and byte counts.
Development
npm install
npm test # 27 tests
npm run typecheck
Status
Reference implementation. Not a substitute for Android device policy, app sandboxing, or careful review of OAuth consent.
See THREAT_MODEL.md for security boundaries and limitations.
License
Apache-2.0
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.