PEEK: Context Map as an Orientation Cache for Long-Context LLM Agents

Zhuohan Gu, Qizheng Zhang, Omar Khattab, Samuel Madden

TL;DR

PEEK introduces a "context map"—a small, fixed-budget prompt cache that stores reusable "orientation knowledge" about a large, recurring external context (like a document corpus or code repository). By automatically distilling structural insights from an agent's execution trajectories, PEEK significantly boosts task accuracy while drastically reducing iterations and API costs compared to state-of-the-art prompt-learning frameworks.

What Problem Does This Paper Address?

When Large Language Model (LLM) agents are deployed in production, they are often tasked with repeatedly querying the same massive external context—such as a 50k-entry user feedback database or a massive codebase—to answer changing user requests.

Current context-management strategies fall short in this scenario:

  • Shared chats quickly become bloated and noisy.
  • RAG and context compaction provide only passive access to raw or condensed data.
  • Prompt-learning frameworks (like ACE) focus on task-level strategies rather than understanding the context itself.

The authors identify a missing quadrant in the agent state-space: actively maintaining a bounded, semantic artifact that captures orientation knowledge—how the context is organized, what it contains, and what schemas or constants remain useful across multiple distinct queries.

Figure 2: Design Space of Agent State. Context maps fill the active external-context quadrant.

Methods

PEEK implements an agent-level semantic cache called a context map that sits directly within the system prompt. Instead of relying on manual pre-population, PEEK automatically builds and maintains this map across queries using a programmable cache policy driven by three decoupled modules:

  1. The Distiller: Analyzes the agent's execution trajectory (reasoning steps, tool calls, and observations) to diagnose where it spent its time (orientation vs. task-specific work), tags existing map items (helpful, harmful, neutral, or stale), and extracts new transferable cache candidates.
  2. The Cartographer: Translates the Distiller's findings into structured edits (ADD, DELETE, REPLACE) using stable item IDs to keep updates localized and clean.
  3. The Evictor: Enforces a strict token budget (defaulting to 1,024 tokens) using priority-based eviction. It protects high-level context understanding and roadmaps while evicting parsing schemas or intermediate results first if the budget is exceeded.
Figure 3: The PEEK System. Inspired by caching in computer systems and the notion of peeking, PEEK caches orientation knowledge in a context map and updates it through a modular process consisting of a Distiller, a Cartographer, and an Evictor.

Datasets

The system was evaluated on two categories of long-context tasks that stress repeated context interaction:

  • OOLONG: A long-context reasoning and information aggregation benchmark. The authors focused on the three hardest splits: trec_coarse, agnews, and yahoo.
  • CL-bench: A challenging context-learning benchmark covering domain-specific knowledge, complex procedures, and laws.

The authors also attempted to retrofit standard QA datasets like BrowseComp-Plus, FanOutQA, and QuALITY, but detailed why they failed (either due to disjoint, manufactured contexts or contexts being too short to create cache pressure), highlighting the need for native benchmarks in this sub-field.

Key Insights and Ideas

  • Orientation vs. Task Strategy: Just as a human data analyst keeps a lightweight cheat sheet of a database's schema and quirks, LLM agents benefit far more from caching context-specific "orientation knowledge" than generic task-level rules.
  • Decoupling Diagnosis from Editing: Collapsing the Distiller and Cartographer into a single monolithic LLM call degrades performance by 7.7% on average. Separating the analysis of what was learned from the planning of how to edit the map prevents non-contextual facts from leaking into the cache.
  • Presence Over Precise Size: Ablation studies showed that having a context map matters far more than its exact size; even a highly constrained budget of 512 tokens yielded massive improvements over base models.

Key Results

PEEK consistently outperformed strong baselines (including RAG, MemAgent, and ACE) across all benchmarks:

  • On OOLONG: PEEK improved accuracy by 6.3% to 34.0% over baselines, while using 93–145 fewer iterations and incurring 1.7–5.8× lower cost than the state-of-the-art framework ACE.
  • On CL-bench: PEEK improved the solving rate by 6.0–14.0% and rubric accuracy by 7.8–12.1%, at a 1.4× lower cost than ACE.
  • Strong Generalization: These performance gains held true when swapping the base model (from GPT-5-mini to GPT-5.5 or Qwen3-Coder-Next-FP8) and the agent architecture (from RLM to OpenAI Codex), proving PEEK is not tied to a specific model family.
Figure 1: Performance Snapshot (GPT-5-mini as the Base LM). PEEK (our system) consistently achieves the highest scores across long-context tasks compared with strong baselines.

Limitations and Future Work

  • Dependency on Reusable Knowledge: PEEK’s utility depends entirely on the nature of the context; if an agent's interaction with a document reveals no reusable structural insights, the cache provides little value.
  • Agent-Specific Utility: Because different agent architectures interact with contexts differently, a map optimized by one agent might vary in usefulness if handed off to another.
  • Future Directions: The authors suggest exploring adaptive cache sizing, training a specialized model for the Distiller module, maintaining multi-cache collections for parallel agents, and designing new benchmarks specifically tailored for repeated queries over a single massive context.

Summary updated

Abstract

Large language model (LLM) agents increasingly operate over long and recurring external contexts, like document corpora and code repositories. Across invocations, existing approaches preserve either the agent's trajectory, passive access to raw material, or task-level strategies. None of them preserves what we argue is most needed for repeated same-context workloads: reusable orientation knowledge (e.g., what the context contains, how it is organized, and which entities, constants, and schemas have historically been useful) about the recurring context itself. We introduce PEEK, a system that caches and maintains this orientation knowledge as a context map: a small, constant-sized artifact in the agent's prompt that gives it a persistent peek into the external context. The map is maintained by a programmable cache policy with three modules: a Distiller that extracts transferable knowledge from inference-time signals, a Cartographer that translates it into structured edits, and a priority-based Evictor that enforces a fixed token budget. On long-context reasoning and information aggregation, PEEK improves over strong baselines by 6.3-34.0% while using 93-145 fewer iterations and incurring 1.7-5.8x lower cost than the state-of-the-art prompt-learning framework, ACE. On context learning, PEEK improves solving rate and rubric accuracy by 6.0-14.0% and 7.8-12.1%, respectively, at 1.4x lower cost than ACE. These gains generalize across LMs and agent architectures, including OpenAI Codex, a production-grade coding agent. Together, these results show that a context map helps long-context LLM agents interact with recurring external contexts more accurately and efficiently.
BibTeX
@inproceedings{gu2026peek,
  author = {Zhuohan Gu and Qizheng Zhang and Omar Khattab and Samuel Madden},
  title = {{PEEK: Context Map as an Orientation Cache for Long-Context LLM Agents}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=ENGBo0bbcF},
}

Loading related content...

Figure