协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
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 …
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
A complete memory and performance system for AI agents. Two subsystems, one package:
A three-stage system that helps AI agents maintain long-term memory:
Four lifecycle hooks that enforce consistency during agent runs:
before_agent_start) — Assembles a bounded briefing packet from memory files + checklist, injects into system promptbefore_tool_call) — Enforces deny lists, normalizes params, prevents unsafe tool callstool_result_persist) — Head+tail compression of large tool results to prevent context bloatagent_end) — Writes durable notes about what happened, tools used, and outcomesThe skill includes three Python scripts in scripts/:
memory-extract.py — Fact extractionmemory-link.py — Knowledge graph buildingmemory-briefing.py — Daily briefing generationAll scripts auto-detect your workspace from:
CLAWDBOT_WORKSPACE environment variable~/.clawdbot/workspace (default fallback)At least one LLM API key is required:
Set via environment variable or config file:
# 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.
Run the full pipeline:
python3 scripts/memory-extract.py
python3 scripts/memory-link.py
python3 scripts/memory-briefing.py
Or run individual steps as needed.
Script: memory-extract.py
Reads from (in priority order):
{workspace}/memory/YYYY-MM-DD.md) — today or yesterday~/.clawdbot/agents/main/sessions/*.jsonl)Extracts structured facts:
Output: {workspace}/memory/extracted.jsonl — One JSON fact per line, deduplicated
Script: memory-link.py
Takes extracted facts and:
Output:
{workspace}/memory/knowledge-graph.json — Full graph with nodes and links{workspace}/memory/knowledge-summary.md — Human-readable summaryScript: memory-briefing.py
Creates a compact daily briefing loaded at session start.
Combines:
Output: {workspace}/BRIEFING.md — Under 2000 chars, LLM-generated or template-based
To run automatically, add to your workspace's HEARTBEAT.md:
# 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)
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.
All files are created in {workspace}/memory/:
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"In memory-extract.py, modify the extraction prompt (lines ~75-85) to focus on different types of information or change the output format.
In memory-link.py, change the similarity threshold for creating links (currently 0.3 at line ~195).
No facts extracted:
Low-quality links:
memory-link.pyBriefing too long:
generate_fallback_briefing)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.
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
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:
The after-action review (agent_end) feeds back into the next briefing (before_agent_start). The loop is closed — just not during execution.
Configure via openclaw.plugin.json or your agent config:
{
"enabled": true,
"briefing": {
"maxChars": 6000,
"checklist": [
"Restate the task in one sentence.",
"List constraints and success criteria.",
"Retrieve only the minimum relevant memory.",
"Prefer tools over guessing when facts matter."
],
"memoryFiles": ["memory/IDENTITY.md", "memory/PROJECTS.md"]
},
"tools": {
"deny": ["dangerous_tool"],
"maxToolResultChars": 12000
},
"afterAction": {
"writeMemoryFile": "memory/AFTER_ACTION.md",
"maxBullets": 8
}
}
before_agent_start — Briefing Packet
maxChars limit)before_tool_call — Tool Discipline
deny listtool_result_persist — Output Compression
maxToolResultChars (default 12K)after_action_review — Durable Notes
src/index.ts — Hook registration and wiringsrc/briefing.ts — Briefing packet buildersrc/compress.ts — Tool result compressorsrc/memory.ts — Memory file loader + after-action writer