memory-pipeline
Complete agent memory + performance system. Extracts structured facts, builds knowledge graphs, generates briefings, and enforces execution discipline via pre-game routines, tool policies, result compression, and after-action reviews. Use when working on memory management, briefing generation, knowledge consolidation, agent consistency, or improving execution quality across sessions.
What this skill does
# Memory Pipeline + Performance Routine
A complete memory and performance system for AI agents. Two subsystems, one package:
- **Memory Pipeline** (Python scripts) — Extracts facts, builds knowledge graphs, generates daily briefings
- **Performance Routine** (TypeScript hooks) — Pre-game briefing injection, tool discipline, output compression, after-action review
## What This Does
### Memory Pipeline (Between Sessions)
A three-stage system that helps AI agents maintain long-term memory:
1. **Extract** — Pulls structured facts (decisions, preferences, learnings, commitments) from daily notes and session transcripts using LLM extraction
2. **Link** — Builds a knowledge graph with embeddings and bidirectional links between related facts, identifies contradictions
3. **Briefing** — Generates a compact BRIEFING.md file loaded at session start with personality reminders, active projects, recent decisions, and key context
### Performance Routine (Within Sessions)
Four lifecycle hooks that enforce consistency during agent runs:
1. **Pre-Game Routine** (`before_agent_start`) — Assembles a bounded briefing packet from memory files + checklist, injects into system prompt
2. **Tool Discipline** (`before_tool_call`) — Enforces deny lists, normalizes params, prevents unsafe tool calls
3. **Output Compression** (`tool_result_persist`) — Head+tail compression of large tool results to prevent context bloat
4. **After-Action Review** (`agent_end`) — Writes durable notes about what happened, tools used, and outcomes
## Quick Start
### Installation
The skill includes three Python scripts in `scripts/`:
- `memory-extract.py` — Fact extraction
- `memory-link.py` — Knowledge graph building
- `memory-briefing.py` — Daily briefing generation
All scripts auto-detect your workspace from:
1. `CLAWDBOT_WORKSPACE` environment variable
2. Current working directory (if contains SOUL.md or AGENTS.md)
3. `~/.clawdbot/workspace` (default fallback)
### Requirements
**At least one LLM API key** is required:
- OpenAI API key (for GPT-4o-mini + embeddings)
- Anthropic API key (for Claude Haiku)
- Gemini API key (for Gemini Flash)
Set via environment variable or config file:
```bash
# Environment variable
export OPENAI_API_KEY="sk-..."
# OR config file
echo "sk-..." > ~/.config/openai/api_key
```
The scripts will auto-detect and use whichever API key is available.
### Basic Usage
Run the full pipeline:
```bash
python3 scripts/memory-extract.py
python3 scripts/memory-link.py
python3 scripts/memory-briefing.py
```
Or run individual steps as needed.
## Pipeline Stages
### Stage 1: Extract Facts
**Script:** `memory-extract.py`
Reads from (in priority order):
1. Daily memory files (`{workspace}/memory/YYYY-MM-DD.md`) — today or yesterday
2. Session transcripts (`~/.clawdbot/agents/main/sessions/*.jsonl`)
Extracts structured facts:
- **Type**: decision, preference, learning, commitment, fact
- **Content**: The actual information
- **Subject**: What it's about (auto-detected from context)
- **Confidence**: 0.0-1.0 reliability score
**Output:** `{workspace}/memory/extracted.jsonl` — One JSON fact per line, deduplicated
### Stage 2: Build Knowledge Graph
**Script:** `memory-link.py`
Takes extracted facts and:
- Generates embeddings (if OpenAI key available, else uses keyword similarity)
- Creates bidirectional links between related facts
- Detects contradictions and marks superseded facts
- Auto-generates domain tags from content
**Output:**
- `{workspace}/memory/knowledge-graph.json` — Full graph with nodes and links
- `{workspace}/memory/knowledge-summary.md` — Human-readable summary
### Stage 3: Generate Briefing
**Script:** `memory-briefing.py`
Creates a compact daily briefing loaded at session start.
Combines:
- Personality traits (from SOUL.md if exists)
- User context (from USER.md if exists)
- Active projects (top subjects from recent facts)
- Recent decisions and preferences
- Active todos (from any todos*.md files)
**Output:** `{workspace}/BRIEFING.md` — Under 2000 chars, LLM-generated or template-based
## Wiring Into HEARTBEAT.md
To run automatically, add to your workspace's `HEARTBEAT.md`:
```markdown
# Heartbeat Tasks
## Daily (once per day, morning)
- Run memory extraction: `cd {workspace} && python3 skills/memory-pipeline/scripts/memory-extract.py`
- Build knowledge graph: `cd {workspace} && python3 skills/memory-pipeline/scripts/memory-link.py`
- Generate briefing: `cd {workspace} && python3 skills/memory-pipeline/scripts/memory-briefing.py`
## Weekly (Sunday evening)
- Review `memory/knowledge-summary.md` for insights
- Clean up old daily notes (optional)
```
## Loading BRIEFING.md
**Important:** BRIEFING.md needs to be loaded as workspace context at session start. This requires the OpenClaw context loading feature (currently in development).
Once available, configure your agent to load BRIEFING.md along with SOUL.md, USER.md, and AGENTS.md at the start of each session.
## Output Files
All files are created in `{workspace}/memory/`:
- **extracted.jsonl** — All extracted facts (append-only)
- **knowledge-graph.json** — Full knowledge graph with embeddings and links
- **knowledge-summary.md** — Human-readable summary of the graph
- **BRIEFING.md** (in workspace root) — Daily context cheat sheet
## Customization
### Changing Models
Edit the model names in each script:
- `memory-extract.py`: Lines with `"model": "gpt-4o-mini"` (or claude/gemini equivalents)
- `memory-link.py`: Line with `"model": "text-embedding-3-small"`
- `memory-briefing.py`: Lines with `"model": "gpt-4o-mini"`
### Adjusting Extraction
In `memory-extract.py`, modify the extraction prompt (lines ~75-85) to focus on different types of information or change the output format.
### Link Threshold
In `memory-link.py`, change the similarity threshold for creating links (currently 0.3 at line ~195).
## Troubleshooting
**No facts extracted:**
- Check that daily notes or transcripts exist
- Verify API key is set correctly
- Check script output for LLM errors
**Low-quality links:**
- Add OpenAI API key for embedding-based similarity (more accurate than keyword matching)
- Adjust similarity threshold in `memory-link.py`
**Briefing too long:**
- Reduce number of facts included in template (edit `generate_fallback_briefing`)
- LLM-generated briefings are automatically constrained to 2000 chars
## Performance Routine (Hook System)
The performance routine is implemented as OpenClaw lifecycle hooks in `src/`. It applies a core principle from performance psychology: **separate thinking from doing**. Athletes don't redesign their technique mid-game — they prepare (purposeful thinking), then execute trained sequences (reactive execution). The only exception is genuine error handling.
For agents, this means: front-load all context, constraints, and memory retrieval into a briefing packet *before* inference starts. Keep execution clean. Write the after-action review *after*. Never inject corrections mid-run.
### Architecture
```
User Message → Gateway → Agent Loop
├── before_agent_start → Briefing Packet (checklist + memory + constraints)
├── LLM Inference (clean context, no mid-run corrections)
├── before_tool_call → Policy enforcement (deny list)
├── Tool Execution → Result
├── tool_result_persist → Compression (head+tail, bounded)
└── agent_end → After-Action Review → durable memory for next run
```
### The Core Idea: No Mid-Swing Coaching
Constant correction during execution degrades output. Mid-run prompt patches create instruction collision — two competing directives the agent must reconcile instead of executing. The alternative:
1. **Capture corrections** — don't inject them into the current run
2. **Condense into deltas** — merge all corrections into a clean update
3. **Inject next run** — the next briefing packet includes the corrected instructions
The after-action review (`agent_end`) feeds back into the next briefing (`before_agent_start`). The lRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.