GitHub - langfengQ/AgentOCR: [ACL'26 Oral] AgentOCR is a token-efficient framework that compresses multi-turn agent history by rendering it into images and adopting RL-driven self-compression
Key Points
- 1AgentOCR addresses the challenge of excessive textual history in multi-turn LLM agent training by compressing observation-action sequences into compact rendered images.
- 2The system achieves over 50% token reduction while maintaining more than 95% performance through a segment optical caching mechanism that enables 20× faster rendering.
- 3By implementing agentic self-compression, the model learns to dynamically optimize its own compression rates during reinforcement learning, enhancing efficiency in complex embodied and search-based tasks.
AgentOCR is an innovative framework designed to mitigate the computational and context-window bottlenecks associated with the rapidly expanding textual histories generated during multi-turn LLM agent training. By shifting from purely textual observation-action representations to compact, rendered images, the system leverages the superior information density of visual tokens to achieve efficient history management.
Core Methodology
The methodology is built upon three foundational pillars that transition agent history from token-heavy strings to optimized visual representations:
- Visual Token Representation: Instead of storing raw textual logs, AgentOCR renders the observation-action history into compact image frames. This approach allows the LLM to process visual tokens, which are significantly more information-dense than standard textual tokens. The framework demonstrates a token consumption reduction of more than 50% while maintaining agent performance at over 95% of the original baseline.
- Segment Optical Caching: To overcome the overhead of real-time image rendering, the framework implements a segment decomposition strategy. The history is broken down into hashable segments that are stored in a visual cache. By utilizing this caching mechanism, the system achieves a 20× speedup in the rendering process, ensuring that the latency introduced by image generation does not impede the reinforcement learning (RL) training loop.
- Agentic Self-Compression: The system introduces an adaptive compression mechanism wherein the agent is trained to emit dynamic compression rates. Through compression-aware reward training, the agent learns to balance the trade-off between the preservation of critical state information and the degree of visual condensation. The objective is to maximize task performance given a constraint on token budget :
where and represent observations and actions, and denotes the learned rendering/compression function.
Infrastructure and Environment
AgentOCR is integrated with the veRL infrastructure to facilitate scalable multi-turn agent training. It supports two distinct task environments:- ALFWorld: Focused on embodied AI, utilizing PDDL and game files alongside MaskRCNN detectors to process state information.
- Search-based QA (Search-R1): Utilizes a dedicated retrieval server (built on Faiss-GPU and E5 embeddings) to handle information-intensive search tasks, necessitating a high-performance environment with significant GPU memory allocation (approximately 6GB per GPU for the retrieval server).
By combining visual tokenization with specialized caching and reward-driven compression, AgentOCR provides a robust solution for long-horizon agent tasks, effectively reconciling the competing demands of context-length constraints and the need for comprehensive historical state tracking.