Memory Systems for Long-Running Agents: Episodic, Semantic, and Working Context

Human software engineers do not reset their cognitive state to blank zero when they sit down to code in the morning. They draw upon a multi-tiered memory architecture: working memory (the function currently being debugged), semantic memory (language syntax and library patterns), and episodic memory (the specific design choices and bug resolutions completed over past weeks).

For autonomous AI agents to sustain multi-day, long-horizon software projects, they must move beyond stateless prompt loops to Three-Tier Memory Architectures.

MERMAID
flowchart TD
    subgraph Agent Runtime
        LLM["Agent Reasoning Core"]
        Working["Tier 1: Working Memory (Active Context Window / Scratchpad)"]
    end
    
    subgraph Persistent Storage
        Episodic["Tier 2: Episodic Memory (Changelogs, Past Decisions, Git History)"]
        Semantic["Tier 3: Semantic Memory (Domain AST Graph, Shared Coding Standards)"]
    end
    
    LLM <--> Working
    Working <-->|Retrieve Relevant Past Slices| Episodic
    Working <-->|Query Symbols & Rules| Semantic
    Working -->|Consolidate & Persist at Turn End| Episodic
✦

1. Deconstructing the Memory Tiers

Memory Tier Storage Medium Retention Horizon Primary Function
Tier 1: Working Context LLM Context Window ($32\text{k} - 128\text{k}$) Current Turn / Task Active file diffs, immediate compile outputs, step instructions
Tier 2: Episodic Memory Append-Only Vector/Relational DB Weeks to Months Previous bug fixes, user design corrections, architectural decisions
Tier 3: Semantic Memory AST Code Graph & Vector Index Permanent Public APIs, project architecture rules, style guidelines
✦

2. Memory Consolidation and Sleep Cycles

If an agent simply dumps every conversation turn into episodic memory, the index quickly becomes contaminated with outdated assumptions and dead-end experiments.

To maintain memory hygiene, production agent harnesses implement Consolidation Cycles (inspired by biological sleep):

* What was the core problem?

* Which attempted approaches failed and why?

* What was the final accepted fix?

✦

3. Implementation Blueprint for Agent Engineers