feat(memory): add core memory skill, update Apollo prompt and Obsidian skill

- Add skills/memory/SKILL.md: dual-layer memory orchestration
- Update prompts/apollo.txt: add memory management responsibilities
- Update skills/obsidian/SKILL.md: add memory folder conventions
This commit is contained in:
m3tm3re
2026-02-12 20:02:51 +01:00
parent 0d6ff423be
commit 1719f70452
3 changed files with 307 additions and 0 deletions

201
skills/memory/SKILL.md Normal file
View File

@@ -0,0 +1,201 @@
---
name: memory
description: "Dual-layer memory system (Mem0 + Obsidian CODEX). Use when: (1) storing information for future recall ('remember this'), (2) auto-capturing session insights, (3) recalling past decisions/preferences/facts, (4) injecting relevant context before tasks. Triggers: 'remember', 'recall', 'what do I know about', 'memory', session end."
compatibility: opencode
---
# Memory
Dual-layer memory system for persistent AI agent context. Memories are stored in BOTH Mem0 (semantic search) AND Obsidian CODEX vault (human-readable, versioned).
## Overview
**Architecture:**
- **Mem0 Layer** (`localhost:8000`): Fast semantic search, operational memory
- **Obsidian Layer** (`~/CODEX/80-memory/`): Human-readable notes, version controlled, wiki-linked
**Cross-Reference:**
- `mem0_id` in Obsidian frontmatter links to Mem0
- `obsidian_ref` in Mem0 metadata links to vault file
## Prerequisites
1. **Mem0 running** at `http://localhost:8000` - Verify with `curl http://localhost:8000/health`
2. **Obsidian MCP configured** - See [references/mcp-config.md](references/mcp-config.md)
3. **Vault structure** - `80-memory/` folder with category subfolders
## Memory Categories
| Category | Definition | Examples |
|----------|------------|----------|
| `preference` | Personal preferences (UI, workflow, communication style) | Dark mode, async communication, detailed responses |
| `fact` | Objective information about user/work (role, tech stack, constraints) | Job title, preferred languages, system architecture |
| `decision` | Architectural/tool choices made (with rationale) | Using React over Vue, PostgreSQL over MySQL |
| `entity` | People, organizations, systems, concepts | Key contacts, important APIs, domain concepts |
| `other` | Everything else | General learnings, context notes |
## Workflow 1: Store Memory (Explicit)
When user says "remember this" or "store this":
### Steps
1. **Classify category** - Determine which of the 5 categories applies
2. **Store in Mem0** - POST to `/memories`:
```bash
curl -X POST http://localhost:8000/memories \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "[memory content]"}],
"user_id": "m3tam3re",
"metadata": {
"category": "preference",
"source": "explicit"
}
}'
```
3. **Create Obsidian note** - Use memory template in `80-memory/<category>/`:
- Set `mem0_id` from Mem0 response
- Set `source: explicit`
4. **Update Mem0 with Obsidian ref** - Add `obsidian_ref` to metadata
### Example
```
User: "Remember that I prefer detailed explanations with code examples"
Agent:
1. Category: preference
2. Mem0: Store with category=preference, source=explicit
3. Obsidian: Create 80-memory/preferences/prefers-detailed-explanations.md
4. Cross-reference IDs
```
## Workflow 2: Recall Memory
When user asks "what do I know about X":
### Steps
1. **Search Mem0** - POST to `/search`:
```bash
curl -X POST http://localhost:8000/search \
-H "Content-Type: application/json" \
-d '{
"query": "[search query]",
"user_id": "m3tam3re"
}'
```
2. **Return results** - Include Obsidian note paths from `obsidian_ref` metadata
3. **Optionally read full note** - Use Obsidian REST API for complete context
### Example
```
User: "What do you know about my UI preferences?"
Agent:
1. Search Mem0 for "UI preferences"
2. Return: "You prefer dark mode (80-memory/preferences/prefers-dark-mode.md)"
```
## Workflow 3: Auto-Capture (Session End)
Automatically extract and store valuable memories at session end.
### Process
1. **Scan conversation** for memory-worthy content:
- Preferences stated
- Decisions made
- Important facts revealed
- Entities mentioned
2. **Select top 3** highest-value memories
3. **For each**: Store in Mem0 AND create Obsidian note (source: "auto-capture")
4. **Present to user**: "I captured these memories: [list]. Confirm or reject?"
### Memory-Worthy Signals
- "I prefer..." / "I like..." / "I hate..." → preference
- "We decided to use..." / "Chose X because..." → decision
- "My role is..." / "We use..." / "The system is..." → fact
- Names, companies, tools mentioned repeatedly → entity
## Workflow 4: Auto-Recall (Session Start)
Inject relevant memories before starting work.
### Process
1. **On session start**, search Mem0 with user's first message/topic
2. **If relevant memories found** (score > 0.7), inject as context:
```markdown
<relevant-memories>
- [preference] User prefers dark mode in all apps
- [fact] User's tech stack: TypeScript, React, Node.js
</relevant-memories>
```
3. **Limit to top 5** most relevant memories
## Error Handling
### Mem0 Unavailable
```bash
# Check health first
curl http://localhost:8000/health
# If fails: Skip all memory operations, warn user
```
Response: "Mem0 is not running. Memory features unavailable. Start with: [instructions]"
### Obsidian Unavailable
- Store in Mem0 only
- Log that Obsidian sync failed
- Continue with degraded functionality
### Both Unavailable
- Skip memory entirely
- Continue without memory features
- Warn user: "Memory system unavailable"
## Integration
### How Other Skills Use Memory
```bash
# Load memory skill to access workflows
# Use mem0-memory skill for direct Mem0 API calls
# Use obsidian skill for direct vault operations
```
### Apollo Agent
Apollo is the primary memory specialist. When complex memory operations needed, delegate to Apollo with memory skill loaded.
### Skill Handoff
| From Skill | Handoff Pattern |
|------------|----------------|
| Any skill | Load `memory` skill, call store/recall workflows |
| mem0-memory | Direct Mem0 API, optionally sync to Obsidian |
| obsidian | Direct vault operations, use memory template |
## Quick Reference
| Operation | Mem0 API | Obsidian Path |
|-----------|----------|---------------|
| Store | POST /memories | 80-memory/<category>/*.md |
| Search | POST /search | Search 80-memory/ |
| Get | GET /memories/{id} | Read note by path |
| Update | PUT /memories/{id} | Update note |
| Health | GET /health | Check REST API |
## See Also
- [references/mcp-config.md](references/mcp-config.md) - Obsidian MCP server configuration
- `~/p/AI/AGENTS/skills/mem0-memory/SKILL.md` - Mem0 REST API details
- `~/p/AI/AGENTS/skills/obsidian/SKILL.md` - Obsidian vault operations
- `~/CODEX/AGENTS.md` - Vault conventions and memory folder docs

View File

@@ -218,6 +218,7 @@ curl -X POST "http://127.0.0.1:27124/create-note" \
| Research note | research | Save research findings with tags |
| Project note | task-management | Link tasks to project notes |
| Plan document | plan-writing | Save generated plan to vault |
| Memory note | memory | Create/read memory notes in 80-memory/ |
## Best Practices
@@ -229,6 +230,102 @@ curl -X POST "http://127.0.0.1:27124/create-note" \
6. **Escape special characters** - URL-encode paths with spaces or symbols
7. **Backup vault** - REST API operations modify files directly
---
## Memory Folder Conventions
The `80-memory/` folder stores dual-layer memories synced with Mem0.
### Structure
```
80-memory/
├── preferences/ # Personal preferences (UI, workflow, communication)
├── facts/ # Objective information (role, tech stack, constraints)
├── decisions/ # Choices with rationale (tool selections, architecture)
├── entities/ # People, organizations, systems, concepts
└── other/ # Everything else
```
### Naming Convention
Memory notes use kebab-case: `prefers-dark-mode.md`, `uses-typescript.md`
### Required Frontmatter
```yaml
---
type: memory
category: # preference | fact | decision | entity | other
mem0_id: # Mem0 memory ID (e.g., "mem_abc123")
source: explicit # explicit | auto-capture
importance: # critical | high | medium | low
created: 2026-02-12
updated: 2026-02-12
tags:
- memory
sync_targets: []
---
```
### Key Fields
| Field | Purpose |
|-------|---------|
| `mem0_id` | Links to Mem0 entry for semantic search |
| `category` | Determines subfolder and classification |
| `source` | How memory was captured (explicit request vs auto) |
| `importance` | Priority for recall ranking |
---
## Memory Note Workflows
### Create Memory Note
When creating a memory note in the vault:
```bash
# Using REST API
curl -X POST "http://127.0.0.1:27124/create-note" \
-H "Content-Type: application/json" \
-d '{
"path": "80-memory/preferences/prefers-dark-mode.md",
"content": "---\ntype: memory\ncategory: preference\nmem0_id: mem_abc123\nsource: explicit\nimportance: medium\ncreated: 2026-02-12\nupdated: 2026-02-12\ntags:\n - memory\nsync_targets: []\n---\n\n# Prefers Dark Mode\n\n## Content\n\nUser prefers dark mode in all applications.\n\n## Context\n\nStated during UI preferences discussion on 2026-02-12.\n\n## Related\n\n- [[UI Settings]]\n"
}'
```
### Read Memory Note
Read by path with URL encoding:
```bash
curl -X GET "http://127.0.0.1:27124/read-note?path=80-memory%2Fpreferences%2Fprefers-dark-mode.md"
```
### Search Memories
Search within memory folder:
```bash
curl -X GET "http://127.0.0.1:27124/search?q=dark%20mode&path=80-memory"
```
### Update Memory Note
Update content and frontmatter:
```bash
curl -X PUT "http://127.0.0.1:27124/update-note" \
-H "Content-Type: application/json" \
-d '{
"path": "80-memory/preferences/prefers-dark-mode.md",
"content": "# Updated content..."
}'
```
---
## Error Handling
Common HTTP status codes: