Loomia
Loomia Research / Working Memory

Working Memory in AI Agents: The Active State of Cognition

Working memory in AI agents is the limited, transient set of information currently available to active reasoning, planning, decision-making and behavior.

Loomia
Definition

Working memory in an AI agent is the bounded and dynamically updated cognitive state that holds information currently relevant to ongoing reasoning, goals, tasks, decisions and actions.

TL;DR

  • Working memory represents information currently active in an agent's cognitive process.
  • It is not equivalent to the model context window, prompt or conversation transcript.
  • Long-term memory can supply information to working memory through retrieval.
  • Working memory must operate under limited capacity, forcing selection, prioritization and replacement.
  • Attention, goals, current observations and retrieved memories all influence working-memory contents.
  • Poor working-memory management can create distraction, context pollution and inconsistent behavior.
  • For persistent AI agents, working memory connects durable state with the cognitive demands of the present moment.

What is working memory in an AI agent?

Working memory is the limited cognitive state containing information that is actively relevant to an agent's current processing.

An agent can possess large persistent stores of episodic and semantic memory, but only a small subset of information can usually participate directly in one reasoning or decision cycle.

Working memory represents that active subset together with other transient state such as the current observation, task, goals, intermediate reasoning state and recent decisions.

Its role is not simply to store information temporarily. It organizes the information that is currently available to cognition and therefore directly influences what the agent can reason about and act upon.

Working memory is not the context window

A model context window and an agent's working memory are related but conceptually different.

The context window is a technical capacity of the underlying model: the maximum amount of tokenized information that can participate in a model invocation.

Working memory is an architectural concept describing which information the agent currently treats as cognitively active.

An implementation may serialize working memory into the model context, but the context can also contain instructions, tool schemas, retrieved documents and other information that should not automatically be considered part of the agent's cognitive working state.

Working memory is not the prompt

A prompt is a representation supplied to a model invocation. Working memory is a persistent architectural abstraction that can exist across multiple invocations.

The system can construct a prompt from selected parts of working memory, retrieved long-term memories, system instructions and current input.

After the model responds, the agent can update working memory according to the result without preserving the complete prompt as active cognitive state.

This distinction prevents prompt construction from becoming the de facto memory architecture.

Working memory is not conversation history

Conversation history records previous messages. Working memory represents what currently matters to the active cognitive process.

A long conversation can contain far more information than the agent should keep cognitively active at one time.

Relevant facts or commitments from older messages can remain in long-term memory and be retrieved when needed, while working memory retains only information required for the current interaction or task.

Treating the entire transcript as working memory causes capacity to grow with conversation length and makes irrelevant historical information increasingly likely to interfere with current reasoning.

Working memory is bounded

Working memory is useful precisely because it is selective.

An agent with unlimited active state would eventually face the same retrieval and relevance problems as an unstructured long-term memory store.

Capacity limits can be expressed through token budgets, number of items, semantic groups, task slots or other architectural constraints.

The exact limit is implementation-specific, but a bounded working-memory model forces the system to decide which information deserves continued cognitive availability.

What can working memory contain?

Working memory can contain multiple categories of information depending on the agent architecture.

  • Current observations or user input.
  • Active goals and subgoals.
  • Current task state.
  • Relevant retrieved episodic memories.
  • Relevant retrieved semantic knowledge.
  • Intermediate decisions or reasoning artifacts.
  • Current plan or plan step.
  • Tool results required by ongoing work.
  • Important entities and relationships in the current situation.
  • Constraints, commitments or safety conditions relevant to the current action.

The working-memory lifecycle

Working memory continuously changes as the agent processes new information.

New observations can enter the active state. Retrieved memories can be activated. Completed subgoals can be removed. Intermediate reasoning can be replaced by conclusions. Tool results can remain active until their task relevance disappears.

A useful working-memory architecture therefore needs explicit update semantics rather than simply appending information forever.

The lifecycle includes admission, prioritization, maintenance, replacement and eventual removal from active cognition.

Admission into working memory

Not every available piece of information should enter working memory.

Admission can depend on relevance to the current goal, salience, urgency, source, task state, attention policies or explicit architectural rules.

Retrieved memories are especially important candidates because retrieval only identifies potentially useful historical information; working-memory admission determines whether that information becomes part of the active cognitive state.

Separating retrieval from admission prevents every retrieved candidate from automatically consuming limited working capacity.

Working memory and attention

Attention and working memory are closely related but not identical.

Working memory defines the information currently available to cognition. Attention can prioritize a subset of that active information for deeper processing during a particular cognitive operation.

An item may remain in working memory without being the immediate focus of attention, such as an active constraint or unresolved subgoal.

This distinction allows the architecture to maintain important background state while dynamically shifting focus between observations, goals, memories and decisions.

Working memory and memory retrieval

Memory retrieval is one of the primary mechanisms through which long-term memory influences working memory.

Retrieval identifies relevant episodic and semantic representations from persistent stores. Selected memories can then be admitted into the current active state.

The retrieval query itself can be constructed from working memory, creating a feedback loop: current active state determines what is retrieved, and retrieved memory changes the active state.

Careful architecture is required to prevent this loop from repeatedly reinforcing the same information while excluding alternative evidence.

Episodic memory in working memory

Retrieved episodic memories can provide concrete examples of previous experiences relevant to the current situation.

An agent might activate a previous failed attempt, a prior user interaction, a successful strategy or an unresolved event.

The episode becomes part of working memory only while it contributes to the present cognitive task.

Its durable representation remains in episodic memory even after it leaves the active state.

Semantic memory in working memory

Semantic memory supplies generalized knowledge to active cognition.

Facts, relationships, preferences, rules and learned propositions can be retrieved when the current task requires them.

Working memory does not need to contain the agent's entire semantic knowledge base. It contains only the subset currently relevant to reasoning or behavior.

This selective activation allows durable knowledge to scale independently from active cognitive capacity.

Goals and task state

Working memory is not limited to retrieved information. Current goals and task state are often among its most important contents.

An agent can use working memory to maintain what it is trying to accomplish, which step is currently active, what constraints apply and which results are still required.

Without persistent task representation, an agent can retrieve relevant facts yet still lose track of why those facts matter.

This makes working memory an important integration point between memory, planning, reasoning and action.

Updating working memory

Working memory should be updated intentionally after meaningful cognitive events.

An observation can invalidate an assumption. A completed action can resolve a subgoal. A tool result can replace an earlier estimate. A retrieved memory can introduce a constraint that changes the current plan.

Update policies can add, modify, reprioritize or remove active items.

The important property is that working memory reflects the agent's current cognitive situation rather than becoming a passive accumulation of everything encountered during the session.

Eviction and replacement

Because working memory is bounded, information eventually needs to leave the active state.

Eviction can occur because a task finishes, information becomes obsolete, another item has greater relevance or the cognitive budget is exhausted.

Leaving working memory does not necessarily mean forgetting. Important information can remain in episodic or semantic long-term memory and be retrieved again later.

This separation allows active cognition to remain compact without sacrificing persistent memory.

Compression within working memory

Sometimes multiple active items can be replaced by a more compact representation.

For example, several tool results can be summarized into a task status, or multiple resolved reasoning steps can be replaced by a conclusion needed for subsequent work.

Compression can preserve working capacity, but it introduces information loss.

Systems should avoid compressing away details that remain necessary for correctness, provenance or later decisions.

Working memory failure modes

Working memory can fail even when long-term memory and retrieval operate correctly.

  • Context pollution — irrelevant information remains active and distracts reasoning.
  • Premature eviction — information needed later in the current task is removed too early.
  • Active-state staleness — working memory retains assumptions invalidated by newer evidence.
  • Goal loss — the agent retains information but loses track of the objective that gives it meaning.
  • Redundancy — multiple equivalent items consume limited active capacity.
  • Retrieval flooding — too many retrieved memories overwhelm the active state.
  • Priority inversion — low-value information displaces critical constraints or commitments.
  • Cross-task contamination — state from one task influences another unrelated task.
  • Compression loss — summarization removes details required for correct later reasoning.
  • Untrusted activation — uncertain or adversarial memory enters active cognition without qualification.

The context pollution problem

More active information does not necessarily produce better reasoning.

Irrelevant memories, outdated task state, duplicated facts and resolved subgoals can consume capacity and create misleading associations.

Context pollution is particularly dangerous in language-model agents because all information serialized into a prompt can potentially influence generation.

Working-memory management should therefore optimize relevance and cognitive utility rather than simply maximizing the amount of available context.

Working-memory observability

Working memory should be observable as explicit agent state rather than existing only implicitly inside prompts.

Engineers should be able to inspect which items are active, why they entered the state, their source, priority, age and relationship to current goals.

Observability makes it possible to diagnose cases where the agent had the correct long-term memory but failed because the information never entered working memory or was displaced prematurely.

It also supports long-horizon evaluation by allowing cognitive-state transitions to be examined independently from model output.

Working memory as a security boundary

Information becomes especially behaviorally powerful when it enters active cognition.

A persistent memory can remain harmless while inactive but begin influencing reasoning immediately after retrieval and admission into working memory.

Working-memory admission should therefore respect provenance, authorization, trust and scope.

In multi-user or tool-using systems, preventing unauthorized or adversarial information from becoming active state is part of the agent's security architecture.

Relationship to persistent AI agents

Persistent agents require both durable history and a coherent present cognitive state.

Long-term memory preserves experience and knowledge across executions. Working memory represents the subset currently required to continue reasoning and action.

When an agent resumes after a process restart, durable state can be used to reconstruct an appropriate working state rather than replaying the entire history.

Working memory therefore provides the active surface through which persistent state becomes present behavior.

Relationship to cognitive continuity

Cognitive continuity requires more than long-term storage. The agent must reconstruct enough active context to continue behaving coherently across time.

Working memory contributes by maintaining current goals, relevant knowledge, recent observations and unresolved task state within the active cognitive process.

After interruptions or execution boundaries, retrieval can restore the information required to rebuild this active state.

Continuity therefore emerges from the interaction between durable memory, retrieval and working-memory reconstruction rather than from one permanently growing context.

Research foundations

Working memory originates as a concept in cognitive psychology describing limited-capacity systems involved in maintaining and manipulating information during active cognition.

Cognitive architectures have long treated working memory as distinct from long-term memory, allowing information to move between durable stores and current processing state.

Modern language-agent architectures increasingly reproduce a similar functional distinction even when implementation terminology differs: persistent memory stores large historical state, while a bounded subset is selected for active model context and reasoning.

The analogy should remain functional rather than literal. Artificial working memory is an architectural abstraction and does not imply that language models reproduce human working-memory mechanisms.

Engineering perspective

A production working-memory subsystem should be represented as explicit state with defined capacity, admission, update and eviction policies.

It should distinguish current observations, goals, retrieved memories, task state and intermediate cognitive artifacts instead of treating all prompt tokens as equivalent.

The architecture should also preserve source metadata so active information can be traced back to observations, episodic memory, semantic memory or tool results.

For persistent autonomous agents, working-memory engineering is fundamentally context engineering: controlling what information is active, why it is active and how long it remains behaviorally influential.

Terminology and scope

The term working memory originates in cognitive psychology and neuroscience.

Loomia uses the term functionally to describe the bounded and dynamically updated active information state of an AI agent.

This does not imply human-like cognition or consciousness. It describes an architectural role: maintaining the information required for current computational cognition while larger stores remain outside the active state.

FAQ

Frequently asked questions

What is working memory in an AI agent?

Working memory is the bounded and dynamically updated cognitive state that holds information currently relevant to ongoing reasoning, goals, tasks, decisions and actions.

Is working memory the same as an LLM context window?

No. The context window is a technical model capacity, while working memory is an architectural representation of information the agent currently treats as cognitively active.

Is the prompt an agent's working memory?

Not necessarily. A prompt can be constructed from working memory together with system instructions, retrieved documents, tool schemas and other information. Working memory can persist as explicit agent state across multiple prompts.

How does long-term memory enter working memory?

Memory retrieval identifies relevant episodic or semantic representations, after which admission policies can activate selected information in working memory.

What happens when working memory is full?

The agent must prioritize, compress, replace or evict active information according to relevance, goals, importance and current cognitive needs.

Does leaving working memory mean the agent forgot something?

No. Information can leave active cognition while remaining stored in long-term episodic or semantic memory for later retrieval.

Why is working memory important for persistent AI agents?

It provides the active cognitive state through which durable goals, knowledge and previous experience become relevant to the agent's current reasoning and behavior.

References

  1. [1]Working Memory — Psychology of Learning and Motivation (1974)
  2. [2]Working Memory: Theories, Models, and Controversies — Annual Review of Psychology (2012)
  3. [3]Cognitive Architectures for Language Agents — arXiv (2023)
  4. [4]MemGPT: Towards LLMs as Operating Systems — arXiv (2023)
Related reading