Marey
# Give your AI agents eyes β€” without burning through model calls. [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue?style=flat&logo=python&logoColor=white)](https://www.python.org/) [![Tests](https://img.shields.io/badge/tests-77%20passing-green?style=flat)](https://github.com/marey/marey) [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-261230?style=flat)](https://github.com/astral-sh/ruff) [![License](https://img.shields.io/badge/license-MIT-green?style=flat)](LICENSE) **Marey is a perceptual infrastructure layer for AI agents β€” a biologically-inspired vision pipeline that turns your screen into structured data, and your cursor into a precision instrument.**
--- ## The problem The naive way to give an agent eyes: snap a full screenshot every 500ms, shove it into a vision model, repeat until your wallet cries. - πŸ’Έ **Model calls burn money** β€” every full screenshot is a full inference - 🐌 **Every call is ~800ms** of latency before the agent even *sees* - 🀑 **It hallucinates tooltips** β€” the model reads UI text it was never meant to parse - πŸ”“ **It ships your entire screen** to a third party, every single frame ## The Marey way Marey models its pipeline on the **human eye**. It only looks closely when something is actually worth looking at β€” and it only sends a model the *few pixels that changed*, not the whole screen. - 🧠 **retina** β€” raw pixel capture (your photoreceptors) - πŸ‘€ **sentinel** β€” peripheral vision; only shouts when something *moves* - 🎯 **cortex** β€” "is this worth looking at?" (spinner? clock? **boring.**) - πŸ” **fovea** β€” actually read the text (Tesseract goes brrr) - πŸ—ΊοΈ **atlas** β€” builds a mental model of the screen - 🧠 **lobe** β€” thinks about what to do (cloud or local LLM) - 🦾 **reflex** β€” clicks, types, scrolls, with humanized cursor movement **Result: 90–95% fewer model calls than naive screenshot loops. Your API budget stays intact. Your agent stops hallucinating tooltips.** | Approach | Full screenshots / min | Model cost / hour | Latency | |---|---|---|---| | **Naive loop** | 120 (every 500ms) | πŸ’ΈπŸ’ΈπŸ’Έ | ~800ms / call | | **Marey** | ~6–12 (deltas only) | πŸ’Έ | ~150ms / ROI | | **Savings** | **90–95%** | **~90%** | **~5x faster** | --- ## How it works ``` ╔═══════════════════════════════════╗ β•‘ THE PHYSICAL WORLD β•‘ β•‘ (whatever's on your screen) β•‘ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•¦β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• β•‘ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ RETINA β”‚ captures pixels β”‚ (mss, 60fps raw) β”‚ via MSS backend β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ raw Frame β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SENTINEL β”‚ downsamples to 15% β”‚ (peripheral vision) β”‚ computes pixel diffs β”‚ adaptive FPS: 30/2 β”‚ temporal stability gate β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ROIs (regions that changed) β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CORTEX β”‚ suppresses noise (<2ms) β”‚ (salience scoring) β”‚ CLIP zero-shot scoring β”‚ rules β†’ CLIPβ†’ONNX β”‚ discards irrelevant ROIs β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ salient ROIs β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ FOVEA β”‚ 2-pass coordinate resolution β”‚ (high-res extract) β”‚ Tesseract OCR extraction β”‚ text Β· table Β· img β”‚ falls back to VLM if <60% β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ extracted content β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β” β”‚ ATLAS β”‚ β”‚ world model β”‚ SQLite / PostgreSQL β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚ enriched, filtered regions β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ LOBE β”‚ OpenRouter / LM Studio β”‚ (reasoning engine) β”‚ never sees full screenshots β”‚ cloud Β· local Β· hybrid β”‚ returns ActionPlan β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ActionPlan β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ REFLEX β”‚ click, type, scroll β”‚ (action executor) β”‚ pyautogui + verification β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ╔══════════════╩═══════════════════╗ β•‘ THE PHYSICAL WORLD β•‘ β•‘ (stuff happens on screen) β•‘ β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β• ``` Supporting cast: **nerve** (event bus) Β· **mesh** (parallel routing) Β· **memory** (context store) Β· **spine** (a11y enrichment) Β· **iris** (privacy shield) Β· **lens** (public SDK) Β· **sim** (hardware-free testing). --- ## Quick start ```bash # Install, configure pip install -e . cp .env.example .env # add your OpenRouter key (or LM Studio URL) ``` ```python import asyncio from marey.lens.client import MareyClient async def main(): client = MareyClient(goal="watch", backend="cloud") async for delta in client.stream(): print(f"πŸ‘€ {len(delta.delta)} things changed on screen") # delta has crops, text, positions β€” your agent's turn client.stop() asyncio.run(main()) ``` Want to see it move? `python gradio_test.py` opens the live pipeline dashboard, or run `python examples/basic_watch.py` for a 30-second screen watch. Full setup in [`docs/getting-started.md`](docs/getting-started.md). --- ## Why you'll trust it - **No full screenshots ever reach a model** β€” only structured deltas + tiny crops. Privacy-first by construction, with `iris` redaction on top. - **Deterministic coordinates** β€” 2-pass resolution means clicks land pixel-perfect, frame after frame. - **Humanized actions** β€” `reflex` moves the cursor along curved BΓ©zier paths with non-uniform velocity, so automation doesn't scream "bot". - **Swappable brain** β€” cloud (OpenRouter), local (LM Studio), or hybrid. No lock-in. - **Degrades gracefully** β€” every stage has a fallback; a missing model, camera, or DB never crashes the loop. --- ## Requirements | Thing | Why | |---|---| | **Python β‰₯ 3.11** | because `match` statements are beautiful | | **Tesseract OCR** | reads text off screens (install via `brew`/`apt`/`choco`) | | **An API key** | OpenRouter (cloud) or LM Studio (local) β€” pick your poison | --- ## Documentation | Doc | What's inside | |---|---| | [`docs/SKILL.md`](docs/SKILL.md) | The architecture bible β€” read this before coding | | [`docs/getting-started.md`](docs/getting-started.md) | Setup, .env, first watch, SDK | | [`docs/types.md`](docs/types.md) | All shared types with validation rules | | [`docs/interfaces.md`](docs/interfaces.md) | Every ABC, every method signature | | [`docs/dependencies.md`](docs/dependencies.md) | Who can import what (strict DAG) | | [`docs/config.md`](docs/config.md) | Tuning guide for every parameter | | [`docs/testing.md`](docs/testing.md) | How to test each module | | [`docs/roadmap.md`](docs/roadmap.md) | What's built, what's next | | [`docs/development.md`](docs/development.md) | Contribute β€” layout, workflow, conventions | ## Testing ```bash pytest tests/ -v ``` 77 tests, three tiers: fast isolated unit tests, an end-to-end pipeline test, and hardware-free simulation β€” so the whole loop is verifiable without touching a real screen. --- ## Anatomy of the codebase ``` marey/ # the good stuff β”œβ”€β”€ retina/ pixel capture (mss) β”œβ”€β”€ lobe/ reasoning (cloud/local/hybrid) β”œβ”€β”€ sentinel/ change detection β”œβ”€β”€ reflex/ action execution (pyautogui) β”œβ”€β”€ cortex/ salience scoring β”œβ”€β”€ lens/ public SDK (MareyClient) β”œβ”€β”€ fovea/ OCR extraction β”œβ”€β”€ mesh/ parallel mesh orchestration β”œβ”€β”€ atlas/ world model β”œβ”€β”€ memory/ context store β”œβ”€β”€ nerve/ event bus β”œβ”€β”€ sim/ hardware-free simulation β”œβ”€β”€ spine/ a11y enrichment β”œβ”€β”€ types/ shared dataclasses └── iris/ privacy filtering └── core/ logging, health, retries docs/ the spec library (source of truth) tests/ unit Β· integration Β· simulation examples/ runnable demos (basic_watch.py) scripts/ dev utilities (download_models.py, dry_run_test.py, …) ``` --- ## 🧠 Why "Marey"? Named after **Γ‰tienne-Jules Marey**, the 19th-century physiologist who invented chronophotography β€” the first technique to capture motion as a series of frames. He gave static pictures the ability to *see movement*. Same vibe. --- ## License MIT β€” go build something cool.
**Star ⭐ the repo if you want AI agents to stop burning money on full screenshots.**