@@ -246,6 +246,110 @@ news.ycombinator.com (REAL)
246246 Monthly Savings: $11,557.63
247247```
248248
249+ ### Run LLM Action Demo
250+
251+ Test that Predicate snapshots work for real browser automation with an LLM.
252+
253+ ** Setup:**
254+
255+ 1 . Copy the example env file:
256+ ``` bash
257+ cp .env.example .env
258+ ```
259+
260+ 2 . Edit ` .env ` and add your OpenAI API key:
261+ ``` bash
262+ # .env
263+ OPENAI_API_KEY=sk-your-openai-api-key-here
264+
265+ # Optional: for ML-ranked snapshots
266+ PREDICATE_API_KEY=sk-your-predicate-api-key-here
267+ ```
268+
269+ 3 . Run the demo:
270+ ``` bash
271+ npm run demo:llm
272+
273+ # With visible browser and element overlay (for debugging)
274+ npm run demo:llm -- --headed --overlay
275+ ```
276+
277+ ** Alternative LLM providers:**
278+ ``` bash
279+ # Anthropic Claude
280+ ANTHROPIC_API_KEY=sk-... npm run demo:llm
281+
282+ # Local LLM (Ollama)
283+ SENTIENCE_LOCAL_LLM_BASE_URL=http://localhost:11434/v1 npm run demo:llm
284+ ```
285+
286+ ** Flags:**
287+ - ` --headed ` - Run browser in visible window (not headless)
288+ - ` --overlay ` - Show green borders around captured elements (requires ` --headed ` )
289+
290+ This demo compares:
291+ - ** Tokens** : A11y tree vs Predicate snapshot input size
292+ - ** Latency** : Total time including LLM response
293+ - ** Success** : Whether the LLM correctly identifies the target element
294+
295+ ** Example output:**
296+ ```
297+ ======================================================================
298+ LLM Browser Navigation COMPARISON: A11y Tree vs. Predicate Snapshot
299+ ======================================================================
300+ Using OpenAI provider
301+ Model: gpt-4o-mini
302+ Running in headed mode (visible browser window)
303+ Overlay enabled: elements will be highlighted with green borders
304+ Predicate snapshots: REAL (ML-ranked)
305+ ======================================================================
306+
307+ Task: Click first news link on HN
308+
309+ [A11y Tree] Click first news link on HN
310+ Chose element: 48
311+ Tokens: 35191, Latency: 3932ms
312+ [Predicate] Click first news link on HN
313+ Chose element: 48
314+ Tokens: 864, Latency: 2477ms
315+
316+ Task: Click More link on HN
317+
318+ [A11y Tree] Click More link on HN
319+ Chose element: 1199
320+ Tokens: 35179, Latency: 2366ms
321+ [Predicate] Click More link on HN
322+ Chose element: 11
323+ Tokens: 861, Latency: 1979ms
324+
325+ Task: Click search on Example.com
326+
327+ [A11y Tree] Click search on Example.com
328+ Chose element: 7
329+ Tokens: 272, Latency: 492ms
330+ [Predicate] Click search on Example.com
331+ Chose element: 6
332+ Tokens: 44, Latency: 6255ms
333+
334+ ======================================================================
335+ RESULTS SUMMARY
336+ ======================================================================
337+
338+ ┌─────────────────────────────────────────────────────────────────────┐
339+ │ Metric │ A11y Tree │ Predicate │ Δ │
340+ ├─────────────────────────────────────────────────────────────────────┤
341+ │ Total Tokens │ 70642 │ 1769 │ -97% │
342+ │ Avg Tokens/Task │ 23547 │ 590 │ │
343+ │ Total Latency (ms) │ 6790 │ 10711 │ -58% │
344+ │ Success Rate │ 3/3 │ 3/3 │ │
345+ └─────────────────────────────────────────────────────────────────────┘
346+
347+ Key Insight: Predicate snapshots use ~97% fewer tokens
348+ while achieving the same task success rate.
349+ ```
350+
351+ > ** Note:** Latency includes network time for ML ranking via the Predicate gateway. Token savings translate directly to cost savings—97% fewer tokens = 97% lower LLM costs.
352+
249353### Build
250354
251355``` bash
@@ -267,7 +371,8 @@ predicate-snapshot-skill/
267371│ ├── snapshot.ts # PredicateSnapshotTool implementation
268372│ └── act.ts # PredicateActTool implementation
269373├── demo/
270- │ └── compare.ts # Token comparison demo
374+ │ ├── compare.ts # Token comparison demo
375+ │ └── llm-action.ts # LLM action comparison demo
271376├── SKILL.md # OpenClaw skill manifest
272377└── package.json
273378```
0 commit comments