Hierarchical Agent Memory
v1.1.0Hierarchical memory architecture for single-agent systems. Replaces flat memory files with a tiered daily/weekly/monthly/yearly note structure and distillati...
Like a lobster shell, security has layers — review code before you run it.
License
SKILL.md
Agent Memory
Agents wake up fresh each session. Files are the only continuity. This skill provides a structure for writing, organizing, and retrieving memory that scales beyond a single flat file.
The Problem
A single MEMORY.md file grows until it degrades retrieval. Content in the middle of a large context window loses attention weight ("lost in the middle" effect). More files loaded at startup = more context consumed = worse salience for any single fact.
Architecture
File Hierarchy
workspace/
├── MEMORY.md # Lean index — project state, key decisions, cross-refs
├── memory/
│ ├── daily/
│ │ └── YYYY-MM-DD.md # Raw logs: what happened, decisions made, open threads
│ ├── weekly/
│ │ └── YYYY-WNN.md # ISO week summaries, synthesized from daily notes
│ ├── monthly/
│ │ └── YYYY-MM.md # Month summaries, synthesized from weekly notes
│ └── yearly/
│ └── YYYY.md # Year summaries, synthesized from monthly notes
Principles
- MEMORY.md stays lean. It is an index, not a journal. Project names, statuses, and pointers to detail files. Target: under 3KB.
- Daily notes are raw. Log everything worth remembering: sessions, decisions, work done, open threads. Timestamped entries.
- Higher tiers are synthesized. Weekly notes distill from daily. Monthly from weekly. Each tier drops detail and keeps patterns.
- Lazy load, don't dump. At session start, load only today + yesterday daily notes and the lean MEMORY.md. Use
memory_searchfor anything else. Never load all files upfront.
Daily Note Format
# YYYY-MM-DD
## Session Log
- HH:MM TZ — [channel/context] — brief summary
## Decisions
- Decision X made because Y
## Open Threads
- Thing still pending
Keep logs factual and searchable. Skip filler, capture decisions.
Weekly Summary Format
# YYYY-WNN (Mon DD – Sun DD)
## Key Events
- ...
## Decisions
- ...
## Patterns
- ...
Setup
On first run, create the directory structure:
mkdir -p memory/daily memory/weekly memory/monthly memory/yearly
If MEMORY.md exists and is large (>5KB), triage it:
- Move project detail into dedicated files under
memory/projects/or similar - Leave only an index with status + pointers in MEMORY.md
- Move historical entries into the appropriate
memory/daily/files by date
Session Startup
Before responding to the user:
- Read
MEMORY.md(lean index) - Read
memory/daily/YYYY-MM-DD.mdfor today and yesterday - That's it. Use
memory_searchfor anything older or deeper.
Do not load weekly/monthly/yearly files at startup. They exist for synthesis and search, not for routine context loading.
Session Logging
At the start of any meaningful session, append to memory/daily/YYYY-MM-DD.md:
## Session Log
- HH:MM TZ — [context] — brief summary of what was discussed/done
At session end (or periodically during long sessions), append:
- Work completed
- Decisions made
- Open threads
Distillation
Distillation moves knowledge up the hierarchy. Run it periodically (during heartbeats, cron, or on request).
Daily → MEMORY.md
When daily notes contain decisions, project state changes, or facts worth keeping long-term:
- Update MEMORY.md with the new state (not the history — just current status)
- Keep MEMORY.md as a living snapshot, not a changelog
Daily → Weekly (every 7 days)
- Read the past 7 daily notes
- Write
memory/weekly/YYYY-WNN.mdsummarizing: key events, decisions, patterns - Drop detail that doesn't matter at the week level
Weekly → Monthly (end of month)
- Read that month's weekly summaries
- Write
memory/monthly/YYYY-MM.mdsummarizing: themes, trajectory, significant changes - Drop per-week granularity
Monthly → Yearly (end of year)
Same pattern. Themes, major milestones, trajectory.
Pruning
During distillation, also prune:
- Remove outdated info from MEMORY.md (completed projects, resolved issues)
- Don't delete daily notes — they're the audit trail
- Weekly/monthly files can be updated if corrections are needed
Retrieval
When the user asks about something not in today's context:
memory_searchfirst — it covers all memory files- If search returns a hit, use
memory_getto pull the specific lines - If low confidence after search, say so — don't fabricate from fragments
Integration with Other Skills
- agent-session-state: Per-channel session files prevent cross-session writes to the same daily note. Use together.
- agent-provenance: Provenance headers on MEMORY.md and other long-lived files track who wrote what and when it was last reviewed.
Files
1 totalComments
Loading comments…
