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
The Log Is Part of the Agent's Interface
An agent that can act but cannot leave a useful decision record is not autonomous. It is an opaque process with write access.
Agentic AIThe Agent Did Not Need More Context
When an agent edits a shared checkout, the dangerous variable is not context length. It is the boundary around what the run is allowed to write.
Quantitative TradingA Retry Is Not a Trading Decision
A rejected order is a decision. Retrying it without preserving the reason can turn a risk control into a duplicate trade.
Quantitative TradingThe Market Is Closed Is Not a Trading Rule
A backtest can know the exchange hours and still schedule a trade into a holiday, an early close, or a stale session. Calendar state is market data.
Latest Blog Posts
A Retry Is Not a Trading Decision
A rejected order is a decision. Retrying it without preserving the reason can turn a risk control into a duplicate trade.
The Log Is Part of the Agent's Interface
An agent that can act but cannot leave a useful decision record is not autonomous. It is an opaque process with write access.
The Market Is Closed Is Not a Trading Rule
A backtest can know the exchange hours and still schedule a trade into a holiday, an early close, or a stale session. Calendar state is market data.
Related Tools & Demos
The QA Field Manual to Language Models
A free 24-chapter book. Start at βwhat is AI, really?β and finish with a small language model you built yourself β one that reads a failing Playwright test and proposes a fix you can run. Read it in your browser, or download the PDF or the Mac app.
View Source Code β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 β
Stay in the Loop
Get weekly insights on AI-driven QA, engineering leadership, and automation strategies.
No spam, ever. Unsubscribe anytime.