# Give your AI agents eyes β without burning through model calls.
[](https://www.python.org/)
[](https://github.com/marey/marey)
[](https://github.com/astral-sh/ruff)
[](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.**