agentleFS
topprismdatatopprismdata/cultivating-ml-agent/skills/examples/memory-hierarchy-management/SKILL.md

memory-hierarchy-management

Skill5 starsChanged 35 days agoMITView on GitHub

Use when context window is getting crowded, when agent needs to recall past experiences, or when starting a long-running task that spans multiple sessions. Triggers when you have 43+ skills and can't fit them all in context, when you need to decide "what should be in working memory right now", or when persisting new learnings for future sessions.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All 43 skills need to be in context (~25K chars) → leaves no room for actual work

    line 74
  2. Distinctive:

    No way to know "which skill is most relevant right now"

    line 76
  3. Distinctive:

    Only 5-20 items in working memory at any time

    line 79
  4. Distinctive:

    After learning something valuable worth preserving

    line 89
  5. Distinctive:

    When context window feels crowded

    line 90
  6. Distinctive:

    When you need to recall past experience ("have we tried X before?")

    line 91
  7. Distinctive:

    When working memory isn't full (overhead not worth it)

    line 96

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Memory Hierarchy Management (MemGPT-Style)

Context

With 43+ skills and growing, stuffing everything into the agent's context window is impossible and wasteful. The naive approach (read SKILL.md on demand) is slow and lossy. This skill provides a 3-layer memory architecture: Working Memory (limited, in-context), Archival Store (unlimited, OKF-indexed), Long-term Storage (filesystem). Recall is multi-strategy (keyword + importance + recency + frequency).

The core insight: context is RAM, vault is disk. We treat them differently.

Guidance

The 3 Layers

Working Memory (in-context, ≤8000 chars)
    ↑↓ auto-promote / LRU evict
Archival Store (OKF graph, unlimited)
    ↑↓ write to filesystem on persist
Long-term Storage (docs/ml-agent-memory/auto-search/)

When to Recall

from framework.src.memory import MemoryHierarchy

mem = MemoryHierarchy(okf_dir="docs/ml-agent-memory")
mem.bootstrap(extra_dirs=["skills/examples", "docs"])

# At decision points — recall relevant skills
items = mem.recall("time series walk-forward validation", k=5)
for item in items:
    print(f"[{item.type}] {item.id} (imp={item.importance})")

When to Remember

from framework.src.memory import MemoryItem

# High-importance → auto-archive
mem.remember(MemoryItem(
    id="auto-finding-2026-08-05-catboost-vs-xgboost",
    content="In S6E2, CatBoost OOF 0.8124 beat XGBoost 0.8003 (+0.012)",
    type="experiment",
    importance=0.8,
    tags=["tabular","catboost","s6e2"],
), persist=True)

Multi-Strategy Recall (Advanced)

from framework.src.memory.recall import multi_strategy_recall, RecallConfig

cfg = RecallConfig(
    use_keyword=True,
    use_recency=True,       # Decay old items
    use_importance=True,    # Promote high-imp
    use_access_frequency=True,  # Frequently-used stays
    recency_decay_days=30,
    final_top_k=5,
)
results = multi_strategy_recall(mem.archival, "tabular feature engineering", cfg)

Why This Matters

Without hierarchy:

  • All 43 skills need to be in context (~25K chars) → leaves no room for actual work
  • Agent forgets what worked yesterday
  • No way to know "which skill is most relevant right now"

With hierarchy:

  • Only 5-20 items in working memory at any time
  • Skills auto-promoted based on multi-strategy score
  • Important findings auto-persist to vault

ROI: 3-5x reduction in context usage; 2x improvement in skill relevance at decision points.

When to Apply

When to Use

  • Starting any new ML competition/task
  • After learning something valuable worth preserving
  • When context window feels crowded
  • When you need to recall past experience ("have we tried X before?")

When NOT to Use

  • Truly novel task with no history (no skills exist yet)
  • One-off quick question
  • When working memory isn't full (overhead not worth it)

Notes

  • Importance threshold: ≥0.7 items auto-archive; <0.5 stay in working only
  • Recall vs Read: recall = multi-strategy ranking; read = direct fetch (when you know exactly which skill you want)
  • Bootstrap once per session: indexing 43+ skills is slow; cache the index
  • Combine with knowledge_search: for new techniques not in vault, also call arxiv_search or kaggle_search
  • See also: runtime-self-reflection (uses memory hierarchy for anti-pattern storage)

References

  • Architecture: framework/src/memory/hierarchy.py
  • Recall strategies: framework/src/memory/recall.py
  • OKF integration: framework/src/memory/okf_index.py
  • Inspired by: MemGPT (Packer et al. 2023), Letta framework

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.