Hierarchical memory management for AI agents. Three layers — daily notes, active context, and long-term memory — with periodic distillation to keep knowledge fresh and relevant.
AI agents lose context between sessions and after context compaction. Without structured memory:
memory/
├── YYYY-MM-DD.md # Daily notes (raw, append-only)
├── active_context.md # Working memory (current tasks, blockers)
├── channel_context/ # Per-channel conversation summaries (optional)
│ └── {channel-name}.md
└── pending_tasks.json # Task tracker (structured)
MEMORY.md # Long-term memory (curated, distilled)
memory/YYYY-MM-DD.md)Raw log of what happened each day. Append-only, minimal editing.
# 2026-04-01
## Tasks
- Implemented login flow for project X
- Fixed timezone bug in cron scheduler
## Decisions
- Chose SQLite over JSON for data storage (performance at scale)
- API rate limit: 100 req/min with exponential backoff
## Learned
- Library Y requires v3+ for async support
- Browser cookies are not shared across profiles
## Blockers
- Waiting on API key approval from service Z
Rules:
memory/ directory if it doesn't existYYYY-MM-DD.mdmemory/active_context.md)Working memory — what's in progress right now. Updated as tasks start, complete, or block.
# Active Context
## In Progress
- **Project X login flow**: OAuth integration, 70% complete
- Next: token refresh logic
## Blocked / Waiting
- **API key for service Z**: Requested 2026-03-30, awaiting approval
## Recently Completed
- **Timezone fix**: Deployed, cron jobs now fire correctly (2026-04-01)
Rules:
MEMORY.md)Curated knowledge distilled from daily notes. The agent's permanent memory.
# Long-Term Memory
## Systems Built
- **Data pipeline**: SQLite-based, runs daily at 6 AM, stores in project.db
- **Monitoring**: 3-tier alert system (info → warning → critical)
## Lessons Learned
1. SQLite > JSON for anything over 100 records
2. Always set explicit timeouts on HTTP requests
3. Browser automation: check for virtual scroll before scraping
## Key Decisions
- Chose framework A over B (reason: better async support, MIT license)
- API integration uses webhook push, not polling
Rules:
~/.secrets/service.env")memory/channel_context/{name}.md)For multi-channel setups (Slack, Discord, etc.), maintain per-channel summaries so context survives compaction.
# channel-name
## Current Topics
- Discussing migration plan for database X
- Reviewing PR #42
## Recent Decisions
- Approved new CI pipeline config (2026-04-01)
## Unresolved
- Performance regression in endpoint /api/users — investigating
Rules:
memory/pending_tasks.json)Structured tracking for tasks that must not be forgotten.
{
"lastUpdated": "2026-04-01T10:00:00Z",
"tasks": [
{
"id": "unique-id",
"title": "Short description",
"status": "in_progress",
"priority": "high",
"createdAt": "2026-04-01T09:00:00Z",
"note": "Additional context"
}
]
}
Valid statuses: pending, in_progress, blocked, done
At the beginning of every session, load context in this order:
memory/active_context.md — what's in progressmemory/YYYY-MM-DD.md (today + yesterday) — recent eventsMEMORY.md — long-term knowledge (main/private sessions only)memory/channel_context/{name}.mdmemory/pending_tasks.json — unfinished tasksDo not respond to messages until context is loaded. "I don't know what you're talking about" is never acceptable when the answer is in these files.
| Write it down | Skip it |
|---|---|
| --- | --- |
| Decisions and their reasoning | Routine operations that went smoothly |
| Errors and how they were fixed | Intermediate debugging steps |
| Key facts about the environment | Information already in code comments |
| User preferences and patterns | Temporary values that change hourly |
| Lessons that prevent future mistakes | Obvious things any model would know |
~/.secrets/service.env"Periodically consolidate daily notes into long-term memory. Recommended: weekly or when daily notes accumulate (3+ unprocessed files).
Read MEMORY.md to understand current state. Note what's already captured.
Read recent daily notes (memory/YYYY-MM-DD.md) that haven't been consolidated yet.
For each daily note, extract what deserves long-term storage:
Add these to the appropriate section in MEMORY.md.
Remove from MEMORY.md:
Record when distillation last ran to avoid redundant work:
In memory/heartbeat-state.json (or a similar state file):
{
"lastConsolidatedAt": "2026-04-01T10:00:00Z"
}
Distillation can be triggered by:
This skill manages what gets stored. A retrieval skill like session-recall (which searches transcripts, memory files, and channel context) manages how to find it. They complement each other:
Using both together provides full coverage: structured storage + intelligent retrieval.
```bash
# Using the bundled script (recommended)
./scripts/init_memory.sh
# Or manually
mkdir -p memory/channel_context
touch memory/active_context.md
echo '{"lastUpdated":"","tasks":[]}' > memory/pending_tasks.json
```
AGENTS.md or session start routine:```
Before responding, read:
```
The system grows organically from here.
共 1 个版本