4-Tier Memory Architecture Hierarchy & Promotion Rules
| Memory Tier | Retention Lifetime | Typical Content & Granularity | Promotion Condition | Context Injection Weight |
|---|---|---|---|---|
| Tier 1: Buffer | Single turn to active session (transient) | Raw user messages, tool execution logs, unverified brainstorms | High utility feedback or explicit task milestone completion | 1.0x (Default active turn context only) |
| Tier 2: Episodic | Days to weeks (session history retention) | Completed task summaries, bug investigations, error stack traces | Recurring pattern observed across 2+ independent sessions | 1.0x baseline ranking weight in retrieval |
| Tier 3: Semantic | Project lifecycle (months to permanent) | Architectural decisions, team coding rules, verified data models | Salience score >= 0.70 and verified production stability | 1.25x priority recall boost in context engine |
| Tier 4: Core | Permanent / immutable project invariants | Security standards, compliance constraints, critical architecture invariants | Explicit administrative authorization and PRD approval | 1.50x priority recall multiplier with guaranteed packing |
The Flat Memory Anti-Pattern: Why Raw Turn Storage Causes Hallucination
Early memory implementations for AI agents treated storage as a flat vector bucket, automatically embedding every user input and assistant response. This naive approach creates severe prompt poisoning in software development. A developer casually asking "What if we rewrote our backend in Rust next quarter?" would have that speculative question saved as an authoritative fact. Days later, the agent would start proposing Cargo builds for a Python codebase.
- Flat storage conflates speculative brainstorms with approved production requirements.
- Verbose debugging logs and transient compiler traces overwhelm long-term index retrieval.
- Unfiltered memory ingestion leads to compounding hallucinations and chaotic drift.
The 4-Tier Memory Taxonomy: Buffer, Episodic, Semantic, and Core
To prevent cognitive pollution, modern agent architectures implement a 4-tier memory hierarchy inspired by cognitive psychology. The Buffer tier holds ephemeral turn data that evaporates when the session ends. The Episodic tier records discrete milestone events and bug fix histories. The Semantic tier stores generalized architectural knowledge, API contracts, and schema definitions. Finally, the Core tier protects immutable system invariants and security rules that must never be violated.
- Buffer isolates noisy working memory during interactive development turns.
- Episodic captures structured event histories for post-mortem analysis and debugging.
- Semantic holds cross-session architectural consensus and coding standards.
- Core enforces non-negotiable compliance rules with top context prioritization.
The Consolidation Engine: Deduplication, Superseding, and Promotion
Memory does not remain static; it undergoes continuous refinement through automated consolidation loops. At the conclusion of execution sessions or during CI merges, the consolidation engine analyzes newly stored memories. Redundant traces are merged, superseded decisions are flagged with invalidation edges, and high-salience episodic memories that recur across multiple sessions are promoted into the Semantic tier.
- Automated deduplication prevents index bloat from repetitive task outputs.
- Superseding logic actively suppresses outdated architectural assumptions.
- Salience-based promotion ensures only verified, high-value patterns reach Semantic status.
Automated Multi-Tier Memory Consolidation and Elevation
javascript// Running periodic maintenance to consolidate memories and elevate tiers
const consolidationReport = await mcpClient.callTool({
name: 'consolidate',
arguments: {
namespace: 'code/billing-engine',
},
});
console.log(consolidationReport.content[0].text);
// Output:
// - Deduplicated 14 redundant episodic bug traces
// - Linked 3 superseded database migration decisions
// - Promoted "All billing mutations must acquire distributed redis lock" to Semantic tier (salience: 0.85)
Frequently Asked Questions
What is the difference between episodic and semantic memory in AI agents?
Episodic memory records specific chronological events and task outcomes, while semantic memory generalizes these into durable rules and facts across sessions.
How does tiering prevent an agent from implementing abandoned ideas?
Speculative thoughts remain trapped in the transient Buffer tier, expiring unless validated and promoted to Semantic tier by consolidation passes.
What are Core memories and when should they be used?
Core memories represent non-negotiable architectural invariants and compliance constraints, receiving top ranking priority during context injection.
Install Persistent Memory for Your Coding Agent
Sub-15ms deterministic recall, AST symbol navigation, and 70%+ token savings across Claude Code, Cursor, Codex CLI, and Windsurf.
npx -y @kolivri/memoreal-mcp setup