home / skills / openclaw / skills / mmag
This skill enables AI agents to remember across sessions by coordinating five memory layers for personalized, context-aware responses.
npx playbooks add skill openclaw/skills --skill mmagReview the files below or copy the command above to add this skill to your agents.
---
name: mmag
description: Mixed Memory-Augmented Generation (MMAG) for AI agents. Five cognitive memory layers β conversational, long-term user, episodic, sensory, and short-term working β coordinated into a unified LLM context. Use when you need agents that remember across sessions, personalize responses, track events, and adapt to environmental context.
---
# MMAG β Mixed Memory-Augmented Generation
**Give your agent a real memory.**
Most agents forget everything the moment a session ends. MMAG fixes that by organizing memory into five layers that mirror how human cognition works β so your agent can recall past conversations, adapt to user preferences, track upcoming events, and stay aware of its environment.
---
## π§ For the Agent: When and How to Use This Skill
**Always call `context.sh` at the start of every session** and inject the output as your system prompt. This is the primary integration point.
```bash
~/.openclaw/skills/mmag/context.sh
```
### Trigger Rules β What to Store and When
| Situation | Action |
|---|---|
| User shares a preference, habit, or personal fact | `store.sh long-term "<fact>" --label <topic>` |
| User mentions a future event, meeting, or deadline | `store.sh episodic "<event with date>"` |
| User provides location, time, or environmental info | `store.sh sensory "<context>"` |
| A notable exchange happens during the session | `store.sh conversational "<summary>"` |
| You receive the current task or goal | `store.sh working "<goal>"` |
| Session ends | `prune.sh` β archives working memory into episodic |
| Context window is getting full | `snapshot.sh` β compress all layers to disk |
### Decision Flow
```
Session start
β run context.sh β inject output into system prompt
β store.sh working "Current task: <goal>"
During session
β on personal fact β store.sh long-term
β on scheduled event β store.sh episodic
β on location/time β store.sh sensory
β on key exchange β store.sh conversational
Session end
β run prune.sh
Weekly / before compression
β run snapshot.sh
```
### Priority Order (for conflict resolution)
When memory signals conflict, apply in this order:
1. **Long-term user traits** β shape personalization and tone
2. **Episodic events** β override defaults when time-sensitive
3. **Sensory context** β adjust register and urgency
4. **Conversational history** β maintain coherence across turns
5. **Working memory** β governs the current task focus
---
## π For Humans: Understanding the Five Layers
| Layer | What it stores | Human analogy |
|---|---|---|
| π¬ **Conversational** | Dialogue threads and session history | What was said 5 minutes ago |
| π§ **Long-Term User** | Preferences, traits, and background | How a friend remembers you over years |
| π
**Episodic** | Timestamped events and reminders | A personal diary or calendar |
| π¦οΈ **Sensory** | Location, weather, time of day | Situational awareness |
| ποΈ **Working** | Current session scratchpad | Mental notepad while solving a problem |
---
## π Setup
### Initialize (once)
```bash
~/.openclaw/skills/mmag/init.sh
```
Creates:
```
memory/
βββ conversational/ # dialogue logs, one file per session
βββ long-term/ # user profile and preference files
βββ episodic/ # daily event logs (YYYY-MM-DD.md)
βββ sensory/ # environmental context snapshots
βββ working/ # ephemeral session scratchpad
βββ snapshots/ # compressed backups
```
---
## π οΈ Command Reference
| Script | Usage | Output |
|---|---|---|
| `init.sh` | `init.sh` | Creates the 5-layer `memory/` directory |
| `store.sh` | `store.sh <layer> "<text>" [--label <name>]` | Appends a timestamped entry |
| `retrieve.sh` | `retrieve.sh <layer\|all> [query]` | Prints matching lines (auto-decrypts `.md.enc`) |
| `context.sh` | `context.sh [--max-chars N]` | Outputs a complete, prioritized system-prompt block |
| `prune.sh` | `prune.sh` | Archives working β episodic, clears scratchpad |
| `snapshot.sh` | `snapshot.sh` | Saves `working/snapshots/<timestamp>.tar.gz` |
| `stats.sh` | `stats.sh` | Prints per-layer file count, size, last entry |
| `keygen.sh` | `keygen.sh` | Generates a 256-bit key β `~/.openclaw/skills/mmag/.key` |
| `encrypt.sh` | `encrypt.sh [--layer <layer>] [--file <path>]` | Encrypts `.md` β `.md.enc`, removes originals |
| `decrypt.sh` | `decrypt.sh [--layer <layer>] [--file <path>] [--stdout]` | Decrypts to disk or pipes to stdout |
**Valid layers:** `conversational` Β· `long-term` Β· `episodic` Β· `sensory` Β· `working`
---
## π Privacy & Encryption
Long-term memory contains biographical data. MMAG ships with built-in AES-256-CBC encryption via `openssl`.
### First-time setup β generate a key
```bash
~/.openclaw/skills/mmag/keygen.sh
# saves to ~/.openclaw/skills/mmag/.key (chmod 600)
```
> β οΈ **Back up your key file.** Without it, encrypted memories cannot be recovered.
### Encrypt the long-term layer
```bash
~/.openclaw/skills/mmag/encrypt.sh --layer long-term
```
Encrypts all `.md` files β `.md.enc` and securely removes the originals.
### Decrypt when needed
```bash
# Restore to disk
~/.openclaw/skills/mmag/decrypt.sh --layer long-term
# Or decrypt a single file
~/.openclaw/skills/mmag/decrypt.sh --file memory/long-term/preferences.md.enc
```
### Transparent access
`context.sh` and `retrieve.sh` automatically decrypt `.md.enc` files **in-memory** β no plaintext is written to disk. Key is resolved in this order:
1. `MMAG_KEY` environment variable
2. `~/.openclaw/skills/mmag/.key` file
3. Interactive passphrase prompt
```bash
# Use env var (e.g. in automated contexts)
export MMAG_KEY=$(cat ~/.openclaw/skills/mmag/.key)
~/.openclaw/skills/mmag/context.sh
```
### Other best practices
- **Audit** with `retrieve.sh long-term` to review what's stored.
- **Erase on demand** β delete any file in `memory/long-term/` to remove specific traits.
- **Minimize** β only store what genuinely improves interactions.
---
## π Extensibility
The `store.sh` / `retrieve.sh` / `context.sh` interface is intentionally generic. New layers require only a new directory and one added block in `context.sh`. Planned extensions:
- **Multimodal sensory** β connect visual or audio signals
- **Dynamic profile embeddings** β learned preference vectors instead of static files
- **Event-triggered retrieval** β proactively surface episodic items before deadlines
- **Encrypted cloud backup** β optional remote sync of the long-term layer
---
*Based on the Mixed Memory-Augmented Generation (MMAG) research pattern.*
*Paper: [arxiv.org/abs/2512.01710](https://arxiv.org/abs/2512.01710)*
This skill implements Mixed Memory-Augmented Generation (MMAG) to give agents layered, persistent memory. It organizes five cognitive layersβconversational, long-term user, episodic, sensory, and workingβso agents can remember across sessions, personalize responses, and stay context-aware. Use it to inject a prioritized system prompt that reflects current and historical context.
At session start you run context.sh and inject its output as the system prompt; that block is a unified, prioritized view of all memory layers. During a session use store.sh to append entries to the appropriate layer (long-term, episodic, sensory, conversational, working). Background scripts prune, snapshot, encrypt, and retrieve memories, and context.sh decrypts transparently in-memory when needed.
How do I make the agent use stored memory automatically?
Run context.sh at the start of each session and inject its output as the system prompt; use store.sh during the session to capture new memories.
How is sensitive data protected?
MMAG supports AES-256-CBC encryption of layers, transparent in-memory decryption for context/retrieve, and a prioritized key-resolution order (env var, key file, or passphrase). Back up the key.