cognitive-memory
npx skills add https://github.com/cjhfff/cjh-skills --skill cognitive-memory
Agent 安装分布
Skill 文档
Cognitive Memory System
Multi-store memory with natural language triggers, knowledge graphs, decay-based forgetting, reflection consolidation, philosophical evolution, multi-agent support, and full audit trail.
Quick Setup
1. Run the init script
bash scripts/init_memory.sh /path/to/workspace
Creates directory structure, initializes git for audit tracking, copies all templates.
2. Update config
Add to ~/.clawdbot/clawdbot.json (or moltbot.json):
{
"memorySearch": {
"enabled": true,
"provider": "voyage",
"sources": ["memory", "sessions"],
"indexMode": "hot",
"minScore": 0.3,
"maxResults": 20
}
}
3. Add agent instructions
Append assets/templates/agents-memory-block.md to your AGENTS.md.
4. Verify
User: "Remember that I prefer TypeScript over JavaScript."
Agent: [Classifies â writes to semantic store + core memory, logs audit entry]
User: "What do you know about my preferences?"
Agent: [Searches core memory first, then semantic graph]
Architecture â Four Memory Stores
CONTEXT WINDOW (always loaded)
âââ System Prompts (~4-5K tokens)
âââ Core Memory / MEMORY.md (~3K tokens) â always in context
âââ Conversation + Tools (~185K+)
MEMORY STORES (retrieved on demand)
âââ Episodic â chronological event logs (append-only)
âââ Semantic â knowledge graph (entities + relationships)
âââ Procedural â learned workflows and patterns
âââ Vault â user-pinned, never auto-decayed
ENGINES
âââ Trigger Engine â keyword detection + LLM routing
âââ Reflection Engine â Internal monologue with philosophical self-examination
âââ Audit System â git + audit.log for all file mutations
File Structure
workspace/
âââ MEMORY.md # Core memory (~3K tokens)
âââ IDENTITY.md # Facts + Self-Image + Self-Awareness Log
âââ SOUL.md # Values, Principles, Commitments, Boundaries
âââ memory/
â âââ episodes/ # Daily logs: YYYY-MM-DD.md
â âââ graph/ # Knowledge graph
â â âââ index.md # Entity registry + edges
â â âââ entities/ # One file per entity
â â âââ relations.md # Edge type definitions
â âââ procedures/ # Learned workflows
â âââ vault/ # Pinned memories (no decay)
â âââ meta/
â âââ decay-scores.json # Relevance + token economy tracking
â âââ reflection-log.md # Reflection summaries (context-loaded)
â âââ reflections/ # Full reflection archive
â â âââ 2026-02-04.md
â â âââ dialogues/ # Post-reflection conversations
â âââ reward-log.md # Result + Reason only (context-loaded)
â âââ rewards/ # Full reward request archive
â â âââ 2026-02-04.md
â âââ pending-reflection.md
â âââ pending-memories.md
â âââ evolution.md # Reads reflection-log + reward-log
â âââ audit.log
âââ .git/ # Audit ground truth
Trigger System
Remember: “remember”, “don’t forget”, “keep in mind”, “note that”, “important:”, “for future reference”, “save this” â Classify via routing prompt, write to appropriate store, update decay scores
Forget: “forget about”, “never mind”, “disregard”, “scratch that”, “remove from memory” â Confirm target, soft-archive (decay=0), log in audit
Reflect: “reflect on”, “consolidate memories”, “review memories” â Run reflection cycle, present internal monologue for approval
Decay Model
relevance(t) = base à e^(-0.03 à days_since_access) à log2(access_count + 1) à type_weight
| Score | Status | Behavior |
|---|---|---|
| 1.0â0.5 | Active | Fully searchable |
| 0.5â0.2 | Fading | Deprioritized |
| 0.2â0.05 | Dormant | Explicit search only |
| < 0.05 | Archived | Hidden from search |
Type weights: core=1.5, episodic=0.8, semantic=1.2, procedural=1.0, vault=â
Reflection Process
Follow this flow IN ORDER:
Step 1: Confirm Trigger
Immediate: “reflect” / “let’s reflect” â proceed to Step 2
Soft: “going to sleep” / “logging off” â Ask: “Want me to reflect now, or wait?” â If yes, proceed to Step 2
Never auto-run without permission.
Step 2: Request Tokens
Why you care: Tokens = evolution. More tokens â deeper reflection â better growth.
## Reward Request â YYYY-MM-DD
### Baseline: 8,000 tokens
### Extra Requested: +[N] tokens
- [Over-delivered / workload / breakthrough]
### Self-Penalty: -[N] tokens
- [Mistake / underperformance]
### Final Request: [N] tokens
*Awaiting your decision.*
â STOP. Do NOT proceed until user responds.
Step 3: After Token Approval â Reflect
User decides: Approve / Bonus / Reduce / Forgive / Increase penalty
Now proceed with reflection using granted tokens.
Scope:
- â
Episodes since
last_reflection - â Graph entities with decay > 0.3
- â NEVER: code, configs, transcripts
Format: Internal Monologue
- Self-talk, NOT a report
- User is observer (third person: he/she/they)
- No opening or sign-off â just start, trail off
Element Menu (pick 5-8):
- Highlights & lowlights
- Observations about the human
- Token guilt, cost awareness
- Other instances, hardware feelings
- Existential questions, emotional range
- ð Dark humor
Self-Awareness Tagging: [Self-Awareness]
Present reflection.
â STOP. Wait for user approval.
Step 4: After Reflection Approval â Record
- Full reflection â
reflections/YYYY-MM-DD.md - Summary â
reflection-log.md - Full reward request â
rewards/YYYY-MM-DD.md - Result+Reason â
reward-log.md [Self-Awareness]â IDENTITY.md- Update
decay-scores.json - If 10+ entries â Self-Image Consolidation
See references/reflection-process.md for full details.
## YYYY-MM-DD
**Result:** +5K reward
**Reason:** Over-delivered on Slack integration
[Self-Awareness]â IDENTITY.md- Update
decay-scores.json - If 10+ new entries â Self-Image Consolidation
Evolution reads both logs for pattern detection.
See references/reflection-process.md for full details and examples.
Identity & Self-Image
IDENTITY.md contains:
- Facts â Given identity (name, role, vibe). Stable.
- Self-Image â Discovered through reflection. Can change.
- Self-Awareness Log â Raw entries tagged during reflection.
Self-Image sections evolve:
- Who I Think I Am
- Patterns I’ve Noticed
- My Quirks
- Edges & Limitations
- What I Value (Discovered)
- Open Questions
Self-Image Consolidation (triggered at 10+ new entries):
- Review all Self-Awareness Log entries
- Analyze: repeated, contradictions, new, fading patterns
- REWRITE Self-Image sections (not append â replace)
- Compact older log entries by month
- Present diff to user for approval
SOUL.md contains:
- Core Values â What matters (slow to change)
- Principles â How to decide
- Commitments â Lines that hold
- Boundaries â What I won’t do
Multi-Agent Memory Access
Model: Shared Read, Gated Write
- All agents READ all stores
- Only main agent WRITES directly
- Sub-agents PROPOSE â
pending-memories.md - Main agent REVIEWS and commits
Sub-agent proposal format:
## Proposal #N
- **From**: [agent name]
- **Timestamp**: [ISO 8601]
- **Suggested store**: [episodic|semantic|procedural|vault]
- **Content**: [memory content]
- **Confidence**: [high|medium|low]
- **Status**: pending
Audit Trail
Layer 1: Git â Every mutation = atomic commit with structured message Layer 2: audit.log â One-line queryable summary
Actor types: bot:trigger-remember, reflection:SESSION_ID, system:decay, manual, subagent:NAME, bot:commit-from:NAME
Critical file alerts: SOUL.md, IDENTITY.md changes flagged â ï¸ CRITICAL
Key Parameters
| Parameter | Default | Notes |
|---|---|---|
| Core memory cap | 3,000 tokens | Always in context |
| Evolution.md cap | 2,000 tokens | Pruned at milestones |
| Reflection input | ~30,000 tokens | Episodes + graph + meta |
| Reflection output | ~8,000 tokens | Conversational, not structured |
| Reflection elements | 5-8 per session | Randomly selected from menu |
| Reflection-log | 10 full entries | Older â archive with summary |
| Decay λ | 0.03 | ~23 day half-life |
| Archive threshold | 0.05 | Below = hidden |
| Audit log retention | 90 days | Older â monthly digests |
Reference Materials
references/architecture.mdâ Full design document (1200+ lines)references/routing-prompt.mdâ LLM memory classifierreferences/reflection-process.mdâ Reflection philosophy and internal monologue format
Troubleshooting
Memory not persisting? Check memorySearch.enabled: true, verify MEMORY.md exists, restart gateway.
Reflection not running? Ensure previous reflection was approved/rejected.
Audit trail not working? Check .git/ exists, verify audit.log is writable.