TL;DR
Just-In-Time Agent Memory (JAM) shifts AI agent memory from static, "Ahead-of-Time" compression to a dynamic, query-conditioned research process at runtime. By combining a hierarchical offline "page-store" with a trained iterative Researcher, JAM achieves state-of-the-art performance on long-context benchmarks while being significantly more efficient than previous agentic memory approaches.
What Problem Does This Paper Address?
Most current AI agents use Ahead-of-Time (AOT) memory systems. These systems compress or summarize past interactions before a user even asks a question. While this saves on serving costs, it’s inherently request-agnostic. If the compression process discards a fine-grained detail that later becomes crucial for a specific query, that information is lost forever.
Furthermore, fixed retrieval pipelines often struggle when evidence is dispersed across evolving, temporally interdependent histories. The authors argue that agent memory shouldn't just be about storing the past, but about constructing the right context for a specific query at runtime.
Methods
The authors introduce Just-In-Time Agent Memory (JAM), a framework consisting of two primary components:
- The Memorizer (Offline): Instead of aggressive compression, the Memorizer organizes raw history into a hierarchical workspace. It chunks data, generates concise "memos" for each session, and groups related sessions into directories. Each directory contains a
READMEthat acts as a navigational summary, allowing the agent to "map" the memory without reading every word. - The Researcher (Online): When a query arrives, the Researcher agent performs iterative research. It uses a Thinking-Exploration-Reflection loop, employing tools like
search(hybrid BM25/dense retrieval),open(reading directory READMEs), andbrowse(reading specific files) to assemble the necessary evidence.
To make this work, the authors developed a two-stage training pipeline:
- Verified Trajectory SFT: A strong teacher model generates successful research paths, which are then used to fine-tune the Researcher.
- Hint-guided GRPO: They use Group Relative Policy Optimization (a form of Reinforcement Learning) to refine the agent's search behavior. To solve the "sparse reward" problem (where the agent only knows if it succeeded at the very end), they inject "hints" during training to guide the agent toward missing information.
Datasets
The paper introduces Memory-Gym, a massive, scalable data synthesis pipeline designed to train memory agents.
- Memory-Gym: Covers 9 task types (e.g., attribute extraction, provenance tracing, state evolution) across 6 diverse domains: Web, Books, Dialogue, News, Academic Papers, and Government Reports. It produced over 16,000 high-quality training instances.
- Evaluation Benchmarks: The authors tested JAM on LoCoMo (long-term conversation), LongMemEval (interactive memory), NarrativeQA (long-document reasoning), and HotpotQA (multi-hop reasoning).
- Cross-Domain Transfer: They also evaluated on LongCodeQA to see if memory behaviors learned on text would transfer to code repositories.
Key Insights and Ideas
- JIT > AOT: The core "aha moment" is that preserving raw data in a navigable structure is better than pre-summarizing it. By deferring context construction until the query is known, the agent avoids information loss.
- Hierarchical Navigation: Using a file-system-like structure (folders and READMEs) allows the agent to perform "coarse-to-fine" searching. It can quickly rule out entire branches of memory, making the research process much faster than linear scanning.
- Transferable Search Skills: Perhaps most surprisingly, the research behaviors learned from synthetic data in Memory-Gym transferred effectively to entirely new domains, like software engineering (LongCodeQA), without any domain-specific fine-tuning.
- Efficiency via Agentic Control: Unlike "brute force" long-context models that process everything, JAM's Researcher can stop as soon as it reflects that it has "sufficient" evidence, saving significant tokens.
Key Results
- Superior Performance: Despite using a smaller backbone (Qwen3.5-4B), JAM outperformed much larger trained baselines (7B-14B models) across most benchmarks.
- Efficiency Gains: Compared to the previous state-of-the-art agentic memory (MemAgent), JAM reduced online query latency by 76.2% (from 58.08s to 13.81s) while actually improving accuracy (F1 score from 46.13 to 52.09 on LoCoMo).
- Context Scaling: JAM showed remarkable stability as context grew. On HotpotQA, while other methods degraded as distractor information increased (up to 224k tokens), JAM’s performance remained steady.
Limitations and Future Work
- Fixed Memorizer: Currently, the Memorizer is fixed while the Researcher is trained. The authors suggest that joint optimization (training both together) could yield even better results.
- Teacher Dependency: The initial SFT stage relies on high-quality trajectories from a teacher model; the system's "ceiling" might be limited by the teacher's reasoning capabilities.
- Offline Latency: While online serving is fast, the one-time offline construction of the hierarchical workspace still takes time (though it is faster than several AOT baselines). Future work could look into making this construction even more lightweight.
Summary updated