Just-in-Time Memory: Learning to Curate Task-Adaptive Memory for LLM Agents

Yefan Zhou, Yang Li, Zeyu Leo Liu, Semih Yavuz, Shafiq JotyarXiv 2026

TL;DR

Just-in-Time Memory (JITMEM) fundamentally rethinks how LLM agents store and recall experiences. Instead of compressing past trajectories into fixed summaries at write-time, JITMEM retains raw, lossless trajectories and defers curation until read-time, when the specific downstream task is known. This task-adaptive approach eliminates premature information loss and collapses the long-horizon credit assignment problem in reinforcement learning into a simple, immediate reward signal.

What Problem Does This Paper Address?

Existing memory systems for Large Language Model (LLM) agents typically curate memory at write-time. Once an agent completes a task, the system immediately distills the trajectory into a fixed artifact—such as a textual reflection, a reusable workflow, or an executable skill—and saves it to a vector database.

However, this design suffers from two major flaws:

  1. Premature Information Loss: The agent must decide what is worth remembering before knowing what future tasks it will encounter. A single trajectory might contain multiple distinct lessons, and discarding details early means they can never be recovered if a future task requires them.
  2. Difficult Credit Assignment: Training a write-time memory curator via Reinforcement Learning (RL) is notoriously hard. The utility of a storage decision is only realized many steps later when a matching query finally retrieves it, creating a challenging long-horizon credit assignment problem.

Methods

JITMEM solves these issues by shifting memory curation from write-time to read-time. The framework consists of four main components:

  • Memory Bank: A passive episodic store that losslessly retains complete, unabstracted raw trajectories (observations and actions). An LLM-as-judge acts as a quality gate, ensuring only successful trajectories are written to the bank.
  • Retriever: A lightweight BM25 retriever that selects the top-$k$ raw trajectories based on the similarity of their task descriptions to the current task.
  • Memory Curator ($\pi_\phi$): The core novelty. At read-time, the curator jointly processes the current task description and the retrieved raw trajectories to synthesize a compact, task-conditioned payload (containing relevant strategies and specific guidance).
  • Agent Executor ($\pi_L$): A frozen, pretrained LLM that receives the curated payload prepended to its prompt and executes the task.
Figure 1: Overview of JITMEM. (a) Inference pipeline. Given the current task xt, the retriever fetches raw trajectories from the memory bank. The curator distills them conditioned on xt into a task-adaptive payload, which is injected into the executor’s context. After execution, an executor-as-judge assesses correctness, and successful trajectories are stored back to the bank. (b) Training pipeline. At each training step, a task is sampled and relevant trajectories are retrieved from a fixed training bank, then the curator generates multiple candidate payloads. The frozen executor attempts the task with each payload and returns the immediate task reward, which is used to update the curator via GRPO.

Curator Training

Because the curated payload is consumed immediately by the executor on the current task, the curator receives an immediate reward based on task success. The authors train the curator using Group Relative Policy Optimization (GRPO), entirely avoiding the need for complex task-grouping scaffolds or delayed utility signals.

Datasets

The authors evaluated JITMEM across three diverse agentic benchmarks:

  • ALFWorld: A text-based embodied environment requiring multi-step household chore execution.
  • WebShop: An e-commerce website environment where agents must navigate, search, and purchase products matching specific user constraints.
  • $\tau^2$-bench: A complex, multi-turn conversational tool-use benchmark spanning airline, retail, and telecom domains.

Key Insights and Ideas

  • Reconstructive Memory Mirrors Human Cognition: JITMEM aligns with cognitive science theories suggesting human episodic memory is reconstructive rather than a simple replay. The same past experience can yield completely different, task-tailored insights depending on the agent's current goal.
An example showing how the same retrieved past experience yields distinct, task-tailored payloads for different current tasks.
  • Zero-Shot Read-Time Curation is Powerful: Even without any RL training, a prompted zero-shot curator (JITMEM-base) consistently beats write-time baselines. This proves that task-conditioned context synthesis at read-time is inherently superior to query-independent write-time summaries.
  • Cross-Executor Transferability: Because the curator is decoupled from the executor, a curator trained on a smaller model (like Qwen3-8B) transfers seamlessly to much stronger executors (like Gemini-2.5-Pro or GPT-4) without retraining, significantly lowering deployment costs.

Key Results

JITMEM achieved substantial performance gains and token efficiencies over state-of-the-art write-time memory methods (like SkillOS and ReasoningBank):

  • Success Rate Improvements: RL-trained JITMEM outperformed the strongest baselines by 16.2 absolute success-rate (SR) points on ALFWorld, 16.3 points on WebShop, and 3.9 points on $\tau^2$-bench.
  • Context Compactness: JITMEM dramatically reduced the context window burden on the executor. Compared to write-time alternatives, it reduced input tokens by 50.3%–56.3% and cut down executor steps by 28.4%–31.4%.
  • Ablation Verification: Comprehensive ablations confirmed that task-adaptive conditioning, raw trajectory retention, and quality-filtered storage all contribute independently to the final performance gains.
Figure 2: Ablation of (a) training-free JITMEM-base and (b) RL-trained JITMEM on ALFWorld (top) and WebShop (bottom) across three executors. Each ablation bar removes one design choice, and the rightmost bar is the full method.

Limitations and Future Work

While highly effective, the authors note a few limitations:

  • Retriever Bottleneck: The system relies on a simple BM25 retriever over task descriptions, which could become a bottleneck as the memory bank scales up in size and diversity.
  • Computational Overhead: The framework introduces an additional LLM call per task (running the curator before the executor).
  • Static Payload Format: The payload structure is currently hand-designed and fixed per benchmark.

Future Directions: The authors suggest jointly optimizing the payload format alongside the policy, exploring dense retrievers, and extending read-time curation from a single pre-task step to dynamic, turn-by-turn adaptation during task execution.

Summary updated

BibTeX
@misc{zhou2026just,
  author = {Yefan Zhou and Yang Li and Zeyu Leo Liu and Semih Yavuz and Shafiq Joty},
  title = {{Just-in-Time Memory: Learning to Curate Task-Adaptive Memory for LLM Agents}},
  year = {2026},
  eprint = {2609.27334},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.27334},
}
Figure