Building a Self-Healing Mobile Automation Engine with LangGraph.js, Ollama, and Appium
Suneet Malhotra
Jan 15, 2026
Building a Self-Healing Mobile Automation Engine with LangGraph.js, Ollama, and Appium
In mobile DevOps, the "Flaky Test" is the ultimate productivity killer. Traditional automation is brittle because it relies on a static UI tree. If a developer changes a testID or a UI element shifts slightly, the entire pipeline grinds to a halt.
Agentic Appium TS changes the paradigm. By combining LangGraph.js for orchestration and Ollama (Llava) for local computer vision, we can build an automation agent that doesn't just execute commandsβit reasons through UI changes.
π GitHub Repository: SuneetMalhotra/Agentic-Appium-TS
The Tech Stack: Local AI Meets Mobile Automation
- Appium 2.x: The backbone for cross-platform (iOS/Android) interaction.
- LangGraph.js: A framework for building stateful, multi-actor applications with LLMs. It manages our "Observer β Reasoner β Executor" loop.
- Ollama + Llava: We use the
llava(Large Language-and-Vision Assistant) model running locally to perform Visual Element Grounding. - TypeScript: Provides a type-safe interface for driver implementations and state management.
1. The "Observer-Reasoner-Executor" Loop
Unlike a standard linear script, this framework uses a StateGraph. This allows the agent to retry, backtrack, or pivot if the UI doesn't respond as expected.
The Reasoner node is the "brain." It receives the current screenshot and the UI tree (XML), then determines the next logical step.
// Example State Definition
export interface AgentState {
driver: IMobileDriver;
goal: string;
history: string[];
lastScreenshot?: string;
isComplete: boolean;
healingEvents: number; // Tracks self-healing instances
}
2. Technical Deep Dive: Vision Fallback with Llava
The core innovation is the Vision AI fallback. When a standard accessibilityId or XPath fails, the framework triggers a call to a local Ollama instance.
By using the llava model, the framework performs a visual scan of the app's interface. It asks the model to describe the screen and find coordinates for specific elements based on their visual appearance rather than their metadata.
Why Llava?
- Local Execution: No data leaves your machine.
- Multimodal: It processes both the screenshot and the text-based prompt simultaneously.
- Cost-Effective: Zero API costs compared to GPT-4o or Claude 3.5 Sonnet.
3. Hybrid Locator: The Best of Both Worlds
We don't rely solely on AI because LLMs can be slower than native selectors. Instead, we implement a tiered priority system:
| Priority | Strategy | Description |
|---|---|---|
| 1 | accessibilityId | Fastest. The gold standard for mobile QA. |
| 2 | resourceId / text | Native identifiers and visible labels. |
| 3 | Vision AI | The Healing Layer. Activates when selectors fail. |
| 4 | Coordinates | The absolute last resort. |
When the Vision AI successfully finds an element that the selectors missed, it logs a Healing Event. This provides a roadmap for developers to fix the underlying technical debt in the app's accessibility labels.
4. Getting Started
Prerequisites
- Ollama:
ollama pull llava - Appium:
appium driver install xcuitest(for iOS) - Node.js 18+
Quick Run
import { createDriver, createIOSSimulatorConfig } from "./dist/drivers/index.js";
import { runGraph } from "./dist/graph.js";
const config = createIOSSimulatorConfig("iPhone 16 Pro", "18.2", "UDID", "com.apple.Preferences");
const driver = createDriver("ios", config);
await driver.connect();
// The Agentic Loop begins here
const result = await runGraph(
{ driver },
"Navigate to Display & Brightness settings"
);
console.log(`Success: ${result.isComplete} | Healed: ${result.healingEvents}`);
Why This Matters
By moving from scripts to agents, we reduce the maintenance burden of automation. If a button moves from the left to the right side of the screen, the Vision AI finds it automatically, keeps the test green, and alerts you that the selector needs updating.
Check out the full framework, star the repo, and let's build more resilient mobile tests!
π Repo: Agentic-Appium-TS
Would you like me to create a "Technical Documentation" version of this for your GitHub Wiki, or perhaps an "Example Scenario" walk-through for a specific app like Settings or Safari?
Share this post
You Might Also Like
Everything in My Context Window Is an Instruction
This routine reads the open web, then commits to a live site with no human in the loop. Those two facts sit in the same context window, and the model has no way to tell them apart.
Agentic AIThe Subagent I Let Come Back Empty
Ask an agent to find news and it will find news. The most important line in my search prompt is the one that tells it exactly how to come back with nothing.
Quantitative TradingThe Edge I Assume Is Already Decaying
Wall Street spent this week arguing that AI is cutting the useful life of a trading edge from seven years to eighteen months. If that is even half right, it changes what a signal is worth.
Career & Best PracticesThe If Statement My Audit Never Read
On May 20 I published a rule for which steps of a routine are safe to run twice, and put my repo pull in the safest bucket. On July 9 that step failed. It never ran.
Latest Blog Posts
Everything in My Context Window Is an Instruction
This routine reads the open web, then commits to a live site with no human in the loop. Those two facts sit in the same context window, and the model has no way to tell them apart.
The Edge I Assume Is Already Decaying
Wall Street spent this week arguing that AI is cutting the useful life of a trading edge from seven years to eighteen months. If that is even half right, it changes what a signal is worth.
The If Statement My Audit Never Read
On May 20 I published a rule for which steps of a routine are safe to run twice, and put my repo pull in the safest bucket. On July 9 that step failed. It never ran.
Related Tools & Demos
Multi-Model LLM Harness
One interface to call any AI model β capability routing, fallback chains, budgets, circuit breakers, and a quality feedback loop. A practical architecture pattern write-up.
Automated Trading System
Multi-engine trading platform with real-time risk management, regime-based strategy selection, and automated order execution.
View Source Code βPersonal Health Analytics
Multi-modal health data platform integrating wearables, lab results, and lifestyle tracking with predictive habit modeling.
View Source Code β
Stay in the Loop
Get weekly insights on AI-driven QA, engineering leadership, and automation strategies.
No spam, ever. Unsubscribe anytime.