An Efficient Context-Dependent Memory Framework for LLM-Centric Agents

Pengyu Gao, Jinming Zhao, Xinyue Chen, Yilin LongNAACL 2025

Abstract

Large Language Model (LLM) agents often struggle with long-term memory and efficient retrieval in complex environments. This paper introduces CDMem (Context-Dependent Memory), a framework that organizes agent experiences into a graph-structured index based on task and environment cues. By mimicking the human "context-dependent effect," CDMem enables more precise retrieval of relevant knowledge. Evaluated on ALFWorld and ScienceWorld benchmarks, CDMem achieves state-of-the-art success rates, demonstrating significant improvements in learning efficiency and hallucination mitigation.

Introduction

While LLMs are excellent reasoners, turning them into autonomous agents that can navigate and manipulate environments remains difficult. A major bottleneck is memory. Existing agents often use "flat" memory pools or basic reflection mechanisms, which suffer from inefficiency and irrelevance. Retrieving information from unorganized pools is computationally expensive, and agents often recall "noisy" past experiences that lead to hallucinations or repetitive errors.

Conceptual overview of CDMem, mimicking human context-dependent memory by indexing experiences by task and environment cues.

Humans solve this using context-dependent memory: we recall specific information more easily when the current environment or task matches the context in which that information was first learned. CDMem replicates this efficiency by organizing knowledge into a graph-structured index based on task and environment "cues."

The CDMem Framework

The CDMem architecture consists of three core components designed to transform raw trial history into actionable, structured knowledge.

The CDMem architecture, illustrating the multistage encoding process for online learning and the context-dependent retrieval mechanism for inference.

1. Multistage Memory Encoding

Instead of saving raw logs, CDMem processes information through three filters:

  • Expert Encoding: Compresses raw trajectories into concise "knowledge chunks" from a domain-expert perspective, removing noise and focusing on essential actions.
  • Short-term Encoding: Reflects on recent trials within a specific task to identify "shortcuts" (the most efficient path to success) and categorize failure types.
  • Long-term Encoding: Aggregates insights across multiple tasks to form high-level, abstract knowledge (e.g., "microwaves can heat food").

2. Context-Dependent Storage

Knowledge is stored in a graph-structured index consisting of two main dictionaries: the Env-Index, which stores environmental insights like object properties and room layouts, and the Task-Index, which stores task-specific trajectories and success/failure insights.

3. Context-Dependent Retrieval

During inference, the agent identifies its current "cues" (task and environment type) to query the graph. It retrieves the most relevant "exemplars" (past successful trajectories) and "insights" (rules of thumb). A non-LLM sorting algorithm using cosine similarity re-ranks these insights to ensure the most relevant information appears in the agent's prompt.

Experimental Evaluation

The authors evaluated CDMem on two popular interactive decision-making benchmarks: ALFWorld (synthetic household tasks) and ScienceWorld (complex scientific reasoning). CDMem outperformed state-of-the-art online learning methods across the board:

  • ALFWorld: Achieved an 85.8% success rate using GPT-4o-mini, surpassing the previous best (AutoGuide-Online) by 9%. With the full GPT-4o model, the success rate reached 90.0%.
  • ScienceWorld: Achieved a score of 56.0, a significant jump over AutoGuide’s 44.8.
  • Learning Curve: CDMem showed a much steeper improvement between the first and second trials compared to other methods, proving it learns from its mistakes more effectively.

Key Insights

  • The "Expert" Filter is Crucial: Summarizing raw trajectories before learning prevents the agent from being overwhelmed by redundant steps. In ALFWorld, removing this step caused the success rate to drop from 85.8% to 72.3%.
  • Generalization: By separating environmental insights from task insights, the agent can generalize better. For example, learning how a microwave works while "cooking an egg" allows the agent to apply that knowledge later when "heating a potato."
  • Hallucination Mitigation: Environmental insights significantly reduced agent hallucinations by providing a better understanding of the world state.

Conclusion

CDMem provides a robust framework for memory-centric agents, though it currently relies on predefined task and environment categories. Future work may focus on allowing agents to autonomously discover these categories and exploring the scalability of the graph-structured index in open-world environments.

Summary updated

BibTeX
@inproceedings{gao2025efficient,
  author = {Pengyu Gao and Jinming Zhao and Xinyue Chen and Yilin Long},
  title = {{An Efficient Context-Dependent Memory Framework for LLM-Centric Agents}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-industry.80},
}
Figure