home / skills / openclaw / skills / mmag

mmag skill

/skills/j0ker98/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 mmag

Review the files below or copy the command above to add this skill to your agents.

Files (13)
SKILL.md
6.6 KB
---
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)*

Overview

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.

How this skill works

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.

When to use it

  • When you need agents that retain user preferences between sessions
  • When tracking scheduled events, deadlines, or follow-ups
  • When adapting responses to location, time of day, or environment
  • When maintaining coherent multi-turn conversations across sessions
  • Before running a model call to ensure the system prompt reflects memory state

Best practices

  • Always invoke context.sh at session start and inject its output as the system prompt
  • Store concise, labeled facts for long-term memory and timestamped data for episodic entries
  • Prune working memory at session end to archive relevant items into episodic memory
  • Encrypt long-term personal data and back up the encryption key securely
  • Use retrieve.sh to audit stored items regularly and delete unnecessary or incorrect entries

Example use cases

  • A personal assistant that remembers user scheduling preferences and upcoming meetings
  • A support bot that recalls user account preferences and previous troubleshooting steps
  • A location-aware agent that adjusts recommendations based on current weather or time
  • A coaching bot that tracks progress across sessions and recalls milestones
  • An automated workflow agent that snapshots working memory before long operations

FAQ

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.