Agent memory is expensive. What if it remembered in pictures?
Every AI agent pays a hidden tax: carrying its whole history back into context at every step. What if it remembered in pictures instead?
Siddhartha Lahiri · · 2 min read

Every AI agent has a hidden tax: its own memory.
On a multi-turn task, an agent carries its entire history — every observation, action, and tool result — back into context at every step. That history never stops growing. A single search task can blow past 10,000 tokens. The agent spends more and more just re-reading its own past, gets slower and pricier, and eventually hits the context wall. A paper called AgentOCR has a clever fix: stop storing history as text. Render it as an image.
Why pixels beat text
A picture of text is far denser than the text itself — roughly 10× fewer tokens for the same information.
The intuition: text has no zoom knob. Every character costs the same, so the bill only climbs. An image's cost is tied to its size, not its content — keep the canvas fixed, pack more in, and a huge history collapses into a nearly flat token budget.

Text tokens climb with history. Visual tokens stay flat — pixels win at scale
How it actually works
Two pieces make the idea practical, and the agent runs them in a loop every step:

- Segment caching — don't redraw the whole history each step. Cache the rendered pieces, draw only what's new. 20×+ faster rendering.
- Self-compression — the agent picks its own compression rate each step, learning via reinforcement learning to compress hard on easy moments and stay sharp when detail matters. The efficiency reward only pays out when the task succeeds — so it can never trade accuracy for cheaper tokens.
The result
Keeps >95% of text-agent performance — at 50–80% fewer tokens. Same capability, a fraction of the context cost.
Want to run it yourself?
Open-source (Apache-2.0), runs on local open-weight models (Qwen2.5-VL), with ready-to-run scripts for both benchmarks. Install → prepare environments → train.

From install to training loop
One honest cost note: AgentOCR cuts serving cost, but the RL training is what you pay for up front — and there's no pre-trained checkpoint yet. The smaller 3B model is the cheap path; 7B buys a few accuracy points for double the GPUs.

Serve-only or train it? Which model?
Where it's hard
- It's not plug-and-play. Untrained, it does worse than a text agent — only RL training closes the gap.
- Compression has a cliff. Safe to ~55% savings, then accuracy drops sharply (text-dense tasks hit it sooner).
- Text-history only, for now. Screenshots, plots, and tables aren't handled yet.
The bigger idea
Why not go further and feed the model actually compressed data — just zip the history? The catch is instructive: a zip is brittle (flip one bit and it won't decompress), while an image degrades gracefully — blur it and the model still reads most of it. That's the whole reason pixels work where literal compression fails.
But the spirit is right, and it's already a frontier: training models to work on dense representations instead of verbose token streams. Pixels are just the first scheme that degrades gracefully. The interesting question is what comes next.
References
What's your take — is visual memory a real path forward, or a clever detour?
First published on LinkedIn. Join the discussion there →


