Every desktop agent demo looks the same on the first tick: grab the whole screen, send it to a vision model, wait, parse the answer, click somewhere, and repeat. It works, and it gets expensive fast — one full screenshot per tick, multiplied by a VLM call, is latency and tokens you pay even when nothing on the screen has changed.

roi-reflex-controller is a small TypeScript control core I built to break that loop.

The idea: look at almost nothing, almost all the time

Instead of capturing the full screen on every tick, the controller watches a handful of tiny Regions of Interest (ROIs) — a button, a form field, a progress bar, the corner of a modal. Those checks are cheap and low latency, and the usual answer is "nothing changed", which costs close to nothing.

The expensive tier is only reached when it has to be:

  • a reflex is uncertain about what it sees,
  • a reflex fails or times out,
  • or the screen state does not match what was expected.

Then the controller escalates the frame to a HighLevelReasoner — a single interface you can plug any vision model into. Because it runs rarely, it can afford to look at more of the screen and think harder about it.

Grok Vision as the expensive tier

The newest addition is GrokHighLevelReasoner, an adapter that routes escalation frames to Grok Vision. The core stays model-agnostic: the reflex tier does the cheap, constant work, and the reasoner tier is swappable, so another model is a new adapter rather than a rewrite.

Safety: ActionGate before anything touches the desktop

An agent that clicks is an agent that can click the wrong thing, and a confident hallucination is exactly where a fast loop becomes dangerous. So no input executes until it passes ActionGate, which enforces:

  • confidence thresholds — low-confidence actions are rejected instead of executed,
  • step budgets — a run has a bounded number of actions,
  • repeat limits — the same action cannot loop forever.

The gate is the part that decides whether the loop can be left running unattended.

Demo and tests

The repo ships a synthetic PNG demo, so you can watch the whole loop without a real desktop: the ROI checks, an escalation, and an action being rejected. Unit tests cover the reflex, escalation, and gate paths — 17/17 passing.

Links

GitHub: https://github.com/yhs0719yhs/roi-reflex-controller

If you are building desktop agents and paying for a screenshot on every tick, I would like to hear how you handle the cheap tier — and any holes you can find in the gate. Stars and issues are both welcome.