TUTORIAL 12

Memory Management

You've completed 3 sprints. Memory files need maintenance. Learn to keep the AI's knowledge healthy and efficient.

โฑ ~15 min ยท Hands-on

/agile-memory-recall /agile-memory-remember /agile-memory-learn /agile-setup-health
Scenario

Three sprints have passed. The team has shipped a profile page, notifications, and an admin dashboard. Along the way, decisions were made, conventions were established, and lessons were learned. But memory files have drifted โ€” some are stale, some are missing new conventions. Time to do memory maintenance.

Step 1: Recall Current Memory State

Start by seeing what the AI currently "knows." The memory index is the table of contents for all project knowledge.

/agile-memory-recall

.memory/MEMORY_INDEX.md

Memory Index โ€” Task Manager App
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

Semantic Memory (what the project IS):
  ๐Ÿ“„ .memory/semantic/project.md        Project brief, name, tech stack
  ๐Ÿ“„ .memory/semantic/architecture.md   System design, module map
  ๐Ÿ“„ .memory/semantic/conventions.md    Coding standards, naming, patterns
  ๐Ÿ“„ .memory/semantic/codebase.md       File structure, key entry points
  ๐Ÿ“„ .memory/semantic/testing.md        Test strategy, coverage targets
  ๐Ÿ“„ .memory/semantic/deployment.md     Environments, CI/CD pipeline config

Episodic Memory (what HAPPENED):
  ๐Ÿ“„ .memory/episodic/decisions.md      ADRs and key technical decisions
  ๐Ÿ“„ .memory/episodic/learnings.md      Sprint retro learnings, insights
  ๐Ÿ“„ .memory/episodic/incidents.md      Production incidents and post-mortems

Domain Knowledge:
  ๐Ÿ“„ .memory/semantic/domain/api.md            API endpoint reference
  ๐Ÿ“„ .memory/semantic/domain/database.md       Schema, migrations, indexes
  ๐Ÿ“„ .memory/semantic/domain/design.md         UI component library reference
  ๐Ÿ“„ .memory/semantic/domain/integrations.md   Third-party service configs

Step 2: Understand Memory Types

Not all memory is created equal. Understanding the two types helps you maintain them correctly.

Semantic Memory โ€” What the Project IS

Semantic Memory:
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Nature:     Stable facts about the project
  Changes:    Rarely โ€” only on major refactors
  Examples:   Architecture, conventions, tech stack
  Update:     REPLACE outdated content with current truth
  Risk:       Goes stale silently if not verified

  Files:
    .memory/semantic/project.md       โ€” "TaskFlow: REST API for task management"
    .memory/semantic/architecture.md  โ€” "We use React + Express + PostgreSQL"
    .memory/semantic/conventions.md   โ€” "All components use PascalCase"
    .memory/semantic/codebase.md      โ€” "Auth module lives in src/api/auth/"
    .memory/semantic/testing.md       โ€” "80% coverage minimum, Jest + RTL"

Episodic Memory โ€” What HAPPENED

Episodic Memory:
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Nature:     Events, decisions, learnings over time
  Changes:    Sprint-scoped โ€” entries archived to sprint files at sprint end
  Examples:   ADRs, retro notes, incident reports
  Update:     ADD new entries within the sprint; at sprint end, /agile-sprint-retro archives all to .memory/episodic/sprints/sprint_NNN.md
  Risk:       Max ~10 entries per file per sprint; bounded to current sprint

  Files:
    .memory/episodic/decisions.md   โ€” "ADR-007: Use SSE for notifications"
    .memory/episodic/learnings.md   โ€” "Integration tests caught 3 bugs unit tests missed"
    .memory/episodic/incidents.md   โ€” "2026-03-15: Payment timeout due to DB lock"
Key Difference

Semantic memory is updated in place โ€” you replace old facts with current ones. Episodic memory is sprint-scoped โ€” entries accumulate during the sprint (max ~10 per file), then /agile-sprint-retro archives them to .memory/episodic/sprints/sprint_NNN.md and resets the active files to template state.

Step 3: Check Memory Health

Every memory file has a last_verified date in its frontmatter. If it's older than 30 days or a major refactor happened, the file is considered stale.

/agile-setup-health
Memory Health Check
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

  .memory/semantic/architecture.md  โš ๏ธ  last verified: 45 days ago
                               3 new modules added since then

  .memory/semantic/conventions.md   โœ…  last verified: 12 days ago
                               up to date

  .memory/semantic/codebase.md      โœ…  last verified: 8 days ago
                               up to date

  .memory/semantic/testing.md       โŒ  last verified: 90 days ago
                               coverage target changed, new test patterns

  .memory/semantic/deployment.md    โœ…  last verified: 15 days ago
                               up to date

  .memory/episodic/decisions.md     โœ…  sprint-scoped, 7 entries (current sprint)
  .memory/episodic/learnings.md     โœ…  sprint-scoped, 12 entries (current sprint)
  .memory/episodic/incidents.md     โœ…  sprint-scoped, 2 entries (current sprint)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Stale files: 2 (.memory/semantic/architecture.md, .memory/semantic/testing.md)
  Action: Verify and update stale files
Stale Memory Is Dangerous

If .memory/semantic/architecture.md says "monolith" but you refactored to microservices, the AI will generate code for the wrong architecture. Stale memory causes wrong decisions. Always fix stale files before starting new work.

Step 4: Fix Stale Memory

Read the stale file, verify against current code, update the content, and refresh the last_verified date.

Updating .memory/semantic/architecture.md

Verification โ€” .memory/semantic/architecture.md
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

  Checking against codebase...

  โŒ Missing: ProfileService module (added Sprint 4)
  โŒ Missing: NotificationService module (added Sprint 5)
  โŒ Missing: AdminService module (added Sprint 6)
  โœ… Correct: UserService, AuthService, OrderService
  โœ… Correct: Tech stack (React, Express, PostgreSQL)
  โœ… Correct: API structure and routing

  Action: Added 3 missing modules to .memory/semantic/architecture.md
  Updated: last_verified โ†’ 2026-04-04

Updating .memory/semantic/testing.md

Verification โ€” .memory/semantic/testing.md
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

  Checking against current test setup...

  โŒ Wrong: Coverage target says 75% (now 80%)
  โŒ Missing: Integration test patterns for SSE endpoints
  โŒ Missing: Soft-delete test conventions
  โœ… Correct: Jest + React Testing Library
  โœ… Correct: Unit test file naming (*. test.ts)

  Action: Updated coverage target, added new patterns
  Updated: last_verified โ†’ 2026-04-04

Step 5: Save a New Convention

During Sprint 3, the team discovered an inconsistency: some API responses used snake_case keys, others used camelCase. They agreed on a convention. Save it.

/agile-memory-remember

New Convention Saved

Saving to: .memory/semantic/conventions.md
Type: Semantic (project convention)

New entry:
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  ## API Response Format
  All API responses use camelCase keys.
  Example: { "userId": 1, "firstName": "Jane" }
  NOT:     { "user_id": 1, "first_name": "Jane" }

  Enforced by: ESLint rule + Zod response schemas
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ… Saved to .memory/semantic/conventions.md

Step 6: Capture a Sprint Learning

Sprint 3's retrospective surfaced an important insight. Capture it in episodic memory.

/agile-memory-learn

Learning Captured

Saving to: .memory/episodic/learnings.md
Type: Episodic (sprint-scoped, archived at sprint end)

New entry:
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  ## Sprint 3 Learning โ€” 2026-04-04
  Integration tests caught 3 bugs that unit tests missed:
    1. Auth middleware not applied to new profile routes
    2. S3 upload failing silently on invalid MIME type
    3. Soft-delete not cascading to user sessions

  Action: Increase integration test coverage for all
  new API endpoints. Add to Definition of Done checklist.
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ… Appended to .memory/episodic/learnings.md

Step 7: Lazy Loading in Action

The AI doesn't load all memory at once. It selectively loads based on what you're doing.

Task-Based Memory Loading

When you say: "Fix the login bug"
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  AI loads:
    โœ… .memory/semantic/codebase.md      โ†’ find auth module location
    โœ… .memory/semantic/testing.md       โ†’ know test conventions
    โœ… .memory/episodic/incidents.md     โ†’ check for related past incidents
  AI skips:
    โญ๏ธ .memory/semantic/deployment.md   โ†’ not relevant to bug fix
    โญ๏ธ .memory/semantic/domain/design.md โ†’ not a frontend task
    โญ๏ธ .memory/semantic/domain/integrations.md โ†’ not an integration issue

When you say: "Plan the notification architecture"
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  AI loads:
    โœ… .memory/semantic/architecture.md  โ†’ current system design
    โœ… .memory/episodic/decisions.md     โ†’ past ADRs (SSE decision)
    โœ… .memory/semantic/codebase.md      โ†’ module structure
  AI skips:
    โญ๏ธ .memory/episodic/incidents.md    โ†’ not an incident
    โญ๏ธ .memory/semantic/testing.md      โ†’ planning, not implementing
    โญ๏ธ .memory/semantic/domain/database.md โ†’ not a data task
Why Lazy Loading Matters

Loading all memory wastes context window tokens and can confuse the AI with irrelevant information. Selective loading keeps the AI focused and efficient. The .memory/MEMORY_INDEX.md is the only file loaded at every conversation start โ€” it tells the AI where to find everything else.

Step 8: What NOT to Save

Not everything belongs in memory. Over-saving creates noise and staleness.

Save vs. Skip

โœ… SAVE to memory:
  - Architecture decisions (ADRs)
  - Team conventions and coding standards
  - Module locations and entry points
  - Recurring bug patterns
  - Deployment configurations

โŒ DO NOT save:
  - Exact code snippets (they go stale instantly)
  - Information derivable from git log
  - Temporary debug state or experiment notes
  - Dependency version numbers (check package.json)
  - PR review comments (they live in GitHub)
The Staleness Test

Before saving anything, ask: "Will this be true in 30 days?" If yes, save it. If it's likely to change with the next code change, don't โ€” it will become stale and mislead the AI.

Progressive Loading Levels

Memory loads in levels, from lightest to deepest. Most tasks never need Level 3.

๐Ÿ“‹
Level 0 .memory/MEMORY_INDEX.md only
๐Ÿ—‚๏ธ
Level 1 route by task type
๐Ÿ“„
Level 2 specific sections
๐Ÿ“š
Level 3 historical, only when asked

Loading Levels Explained

Level 0 โ€” Always loaded (conversation start)
  โ†’ .memory/MEMORY_INDEX.md
  โ†’ Just the table of contents, no file content

Level 1 โ€” Loaded by task type (automatic)
  โ†’ Bug fix? Load .memory/semantic/codebase.md + .memory/semantic/testing.md
  โ†’ Architecture? Load .memory/semantic/architecture.md + .memory/episodic/decisions.md
  โ†’ Frontend? Load .memory/semantic/architecture.md + .memory/semantic/domain/design.md

Level 2 โ€” Loaded on demand (specific need)
  โ†’ Need database schema? Load .memory/semantic/domain/database.md
  โ†’ Need API docs? Load .memory/semantic/domain/api.md

Level 3 โ€” Historical (only when explicitly asked)
  โ†’ "What happened in Sprint 1?" โ†’ Load full .memory/episodic/learnings.md
  โ†’ "Any past incidents with payments?" โ†’ Load .memory/episodic/incidents.md

What You Practiced

Knowledge Check

What is the ONLY memory file loaded at conversation start?