Working Memory Management: A Comprehensive Guide for AI Agents

Working Memory Management: A Comprehensive Guide for AI Agents

Introduction

Working memory (WM) is the cognitive system responsible for the temporary maintenance and manipulation of information in support of ongoing cognition and action [7]. For AI agents, working memory serves as the active workspace where current task context, recent observations, and intermediate reasoning steps are held for immediate access. As one researcher aptly described, working memory is like a "mental sketchpad or desktop, allowing us to comprehend, retrieve and manipulate information in our heads" [11].

Effective working memory management is a critical bottleneck for long-horizon agent tasks. Left unmanaged, working memory can quickly become saturated with irrelevant or outdated information, degrading reasoning quality and derailing the agent from its primary objective [5]. As one framework observes, "the critical bottleneck for long-horizon tasks shifts from merely expanding memory capacity to actively curating its contents" [5].

This guide explores the foundations of working memory management for AI agents, examining core concepts, key techniques, and practical implementation strategies.

What Is Working Memory in AI Agents?

Working memory is the structured sequence of historical observations available within a session to drive decision-making [5]. Unlike long-term memory, which stores knowledge across sessions, working memory is transient and task-specific—once the task or dialogue session concludes, the content can be discarded [7]. This distinction helps avoid clutter in persistent memory layers while ensuring coherence during complex interactions such as multi-step problem solving [7].

Working memory has been categorized into two types [3]:

  • Context memory: Treats the context window as the short-term memory of LLMs, extending context beyond inherent limitations through techniques like MemGPT's hierarchical memory management [12].
  • Active working memory: Involves fetching and integrating relevant external knowledge to hold essential information during operation. This includes sliding window mechanisms that capture and summarize recent feedback [12].

Core Components of Working Memory Management

Working memory management in AI agents follows a structured approach inspired by human cognitive processes and practical engineering frameworks.

1. Write Operations

Working memory write operations store information from interactions. Unlike long-term memory, the write process for working memory is typically a complete coverage operation—the agent replaces the entire working memory content with updated state information [2]. This ensures the working memory remains a focused, minimal representation of the current session state.

Key principles for effective write operations include:

  • Keep it concise: Working memory should remain small (typically less than 500 words) [2].
  • Structure clearly: Use structured formats (e.g., JSON with defined schemas) for consistency [2].
  • Store only current state: Working memory is not a logging system—it stores what is relevant right now [2].
  • Update only on change: Avoid updating working memory every turn—only update when the state meaningfully changes [2].

2. Removal and Clearance Operations

In human cognition, working memory updating involves a two-component process: outdated information is actively removed, and updated information is encoded to replace it [9]. Research has established that removal is an item-specific operation—people can selectively remove specific items from working memory rather than clearing the entire workspace [9].

For AI agents, this translates to several important management strategies:

  • Partial updates: When only a subset of the working memory needs updating, the agent should remove only the specific items being replaced. Partial updates require item-specific removal, which is more computationally intensive but preserves valid context [9].
  • Complete clearance: When the entire working memory needs replacement, the agent can perform a rapid "memory wipe" without item-by-item removal. This is more efficient for complete resets [9].
  • Strategic prioritization: Agents should prioritize information by utility. Research on human working memory shows that "value-directed prioritization is effortful, under top-down strategic control" [7]. High-value items receive more maintenance, while low-value items may be cleared more readily.

3. Retrieval and Read Operations

Working memory retrieval must balance utility, efficiency, and faithfulness [3]. Key considerations include:

  • Automatic loading: Working memory content should load automatically at the beginning of each dialogue turn without requiring the LLM to explicitly request it [2].
  • Scope isolation: Support scope isolation (thread vs. resource) to ensure the right information reaches the right agent [2].
  • Coherence-driven retrieval: Recent research shows that coherence-driven retrieval provides superior memory coverage compared to embedding-based approaches [10]. Systems like Amory use narrative structures to retrieve contextually relevant information.

Working Memory vs. Long-Term Memory

Feature Working Memory Long-Term Memory
Persistence Transient; discarded after session [7] Persistent; retained across sessions
Size Small (< 500 words) [2] Large (unlimited in principle)
Loading Automatic per turn [2] Requires retrieval mechanisms
Update method Complete coverage (overwrite) [2] Append, add, or modify individual items
Structure Structured (Schema-validated) [2] Flexible; can be unstructured
Purpose Current session state [7] Knowledge base, history

Hierarchical Working Memory Management

HiAgent: Subgoal-Based Chunking

HiAgent introduces a hierarchical approach to working memory management that uses subgoals as memory chunks [3]. Inspired by human problem-solving strategies, the framework:

  • Prompts LLMs to formulate subgoals before generating executable actions [3]
  • Enables proactive replacement of previous subgoals with summarized observations
  • Retains only action-observation pairs relevant to the current subgoal [3]

In experiments across five long-horizon tasks, HiAgent achieved a twofold increase in success rate and reduced the average number of steps required by 3.8 [3].

Amory: Narrative-Driven Working Memory

Amory is a working memory framework that actively constructs structured memory representations through agentic reasoning during offline time [10]. Key features include:

  • Organizing conversational fragments into episodic narratives
  • Consolidating memories with momentum
  • Semanticizing peripheral facts into semantic memory

Amory achieved considerable improvements over previous state-of-the-art on the LOCOMO benchmark, with performance comparable to full context reasoning while reducing response time by 50% [10].

Memory-as-Action: Autonomous Context Curation

Memory-as-Action reframes working memory management as a learnable, intrinsic capability where an agent actively manages its working memory by executing explicit editing operations [5]. This approach enables the agent to learn when to retain, compress, or discard segments of history, and insert summaries to maintain coherence.

This formulation allows an agent, trained via reinforcement learning, to balance memory curation against long-term task objectives under given resource constraints [5]. However, memory editing actions break the standard assumption of a continuously growing prefix in LLM interactions—creating "trajectory fractures" that disrupt causal continuity [5].

Dynamic Context Policy Optimization (DCPO) addresses this by segmenting trajectories at memory action points and applying trajectory-level advantages to the resulting action segments [5].

Practical Implementation

Working Memory as a Middleware

Working memory can be implemented as a middleware component that automatically loads and updates session state [2]. Key configuration options include:

  • Enable/disable: Control whether working memory is active
  • Scope: Thread (per-session) or Resource (cross-session sharing) [2]
  • Schema: JSON Schema validation to ensure data consistency [2]

Agent-Controlled Updates

Working memory updates are typically agent-controlled—the agent explicitly calls an update tool to modify its working memory [2]. This gives the LLM agency over what to retain and what to clear, enabling adaptive context management.

Key Design Considerations

  • Maintain small size: Working memory should be concise (< 500 words) [2]
  • Use structured data: Validate with schemas to ensure consistency [2]
  • Distinguish scope: Use thread scope for individual sessions, resource scope for shared contexts [2]
  • Strategic prioritization: Allocate maintenance effort based on item utility [1]
  • Support item-specific removal: Enable selective clearance while preserving valid context [9]

Related Concepts

  • AI Agent Memory Architectures — The broader landscape of memory systems for AI agents
  • Episodic Memory for AI Agents — Personal experiences and event-based recall
  • Semantic Memory Systems — Facts, concepts, and general knowledge
  • Procedural Memory in Agents — Skills, procedures, and "how-to" knowledge
  • Context Engineering — Managing context windows and prompt construction
  • AI Agent Architecture — Foundation Agent, Core Components, Agent Systems

Conclusion

Working memory management is essential for AI agents operating over long horizons. As one framework observes, "the critical bottleneck for long-horizon tasks shifts from merely expanding memory capacity to actively curating its contents" [5].

Effective working memory management requires strategic control over write, removal, and read operations. The most successful approaches combine hierarchical organization (using subgoals as chunks), coherence-driven retrieval, and autonomous context curation through learnable memory actions [3] [5] [10].

For developers building production AI agents, working memory management is not an optional enhancement—it is a foundational capability that determines whether agents can maintain focus, avoid context saturation, and deliver coherent long-horizon reasoning.

Related Articles

References

  1. Chatham, Christopher H., et al. Working memory management and predicted utility. Frontiers in Behavioral Neuroscience. 2013.
  2. Aster Cloud. Agent + Working Memory: A Complete Example. Go Packages. 2026.
  3. Hu, Mengkang, et al. HiAgent: Hierarchical Working Memory Management for Solving Long-Horizon Agent Tasks. ACL. 2025.
  4. Europe PMC. Strategic Control of Working Memory Operations in Dynamic Reward-based Learning. Europe PMC. 2025.
  5. Zhang, Yuxiang, et al. Memory as Action: Autonomous Context Curation for Long-Horizon Agentic Tasks. arXiv. 2025.
  6. Allen, Richard J., et al. Getting value out of working memory through strategic prioritisation. Quarterly Journal of Experimental Psychology. 2025.
  7. Zeppieri, Stefano. MMAG: Mixed Memory-Augmented Generation for Large Language Models Applications. arXiv. 2025.
  8. Xie, Xiaohui, et al. Agent Communication Gateway for Semantic Routing and Working Memory. IETF Internet-Draft. 2026.
  9. Ecker, Ullrich K.H., et al. Working memory updating involves item-specific removal. Journal of Memory and Language. 2014.
  10. Zhou, Yue, et al. Amory: Building Coherent Narrative-Driven Agent Memory through Agentic Reasoning. EACL. 2026.
  11. Human Factors 101. Working memory: A user's guide. Human Factors 101. 2018.
  12. Weis, Loïc, et al. Foundation Agents: A Unified Framework for Intelligent Systems. arXiv. 2025.

Comments