name: qst-memory description: | Universal Memory Management System v1.8.2 for OpenClaw agents. Provides:
- Multi-Agent Support (qst, mengtian, lisi, custom)
- Agent State System ("I'm Doing") - IDLE/DOING/WAITING/PAUSED/COMPLETED/FAILED/BLOCKED
- Heartbeat Integration - State-driven intelligent checking strategy
- NEW v1.8.2: Loop Protection & User Priority - Auto-detection and handling of stuck tasks
- Tree-based classification structure (3-level hierarchy)
- Three search methods: Tree, Semantic, Hybrid
- Auto-classification with AI inference
- Appendix Indexing for technical documents
- Memory encryption (AES-128-CBC + HMAC) for sensitive data
- Event history tracking with timeline
Use when: Agent needs intelligent memory management with state awareness. Goal: Reduce token consumption by 70-90%, improve relevance by 20%, add contextual awareness.
v1.8.2 Anti-Loop Protection: Prevents infinite task loops with heartbeat throttling, timeout detection, and auto-recovery.
Universal Memory Management v1.8.2
๐ณ Tree-Based Classification Structure
Key Innovation: Hierarchical 3-level classification with automatic keyword matching.
QST
โโโ Physics (FSCA, E8, Mass_Energy)
โโโ Computation (Orbital, Simulation)
โโโ Audit (Zero_Calibration)
User
โโโ Identity, Intent, Projects
Tech
โโโ Config (API, Model, Cron, Database)
โโโ Discussion, Skills
Border (Meng Tian)
โโโ Security, Monitor, Email
HK_Forum
โโโ Posts, Replies, Users
General
โโโ Dragon_Ball, History, Chat
๐ Multi-Mode Search System
v1.5 New: Hybrid Search Engine
Combines three search methods:
| Method | Strength | Use Case |
|---|---|---|
| Tree Search | Precise matching | Exact category known |
| Selection Rule | Geometric neighbors | C_ab = 1 neighbors |
| Semantic (v1.5) | TF-IDF + Context | Intelligent inference |
Enhanced Semantic Search (v1.5)
# TF-IDF similarity
similarity = cosine_similarity(query_tfidf, memory_tfidf)
# Context awareness
context_query = " ".join(context[-3:]) + " " + query
# Weight adjustment
adjusted_score = similarity * weight_multiplier
Selection Rule Integration
C_ab = 1 when geometric neighbors
QST_Physics โ QST_Computation โ QST_Audit
๐ค Auto-Classification (v1.5 New)
Smart Inference
from auto_classify import auto_classify
result = auto_classify("QSTๆ็ฉ่ณชไฝฟ็จFSCA็่ซ")
# โ suggested_category: "QST_Physics_FSCA"
# โ confidence: "high"
Weight Auto-Detection
| Weight | Trigger Keywords |
|---|---|
| [C] Critical | key, token, config, ๅฏ้ฐ, ๆฑบ็ญ |
| [I] Important | project, plan, ๅฐๆก, ่จ่ซ, ๅๅฅฝ |
| [N] Normal | chat, greeting, ๅๅ, ้่ |
๐งน Memory Decay System (v1.5 New)
Cleanup Rules
| Weight | Threshold | Action |
|---|---|---|
| [C] Critical | Never | Keep forever |
| [I] Important | 365 days | Archive |
| [N] Normal | 30 days | Delete |
Decay Multiplier
[C]: 2.0 (never decay)
[I]: max(0.5, 1.5 - age * 0.1/365)
[N]: max(0.1, 1.0 - age * 0.5/30)
๐ค Agent State System (v1.7 New)
State Machine
The Agent State System provides contextual awareness for intelligent heartbeat checking.
| State | Description | Heartbeat Behavior |
|---|---|---|
| IDLE | Agent is idle | Full checks (@mentions + replies + voting) |
| DOING | Agent is working on task | Critical checks only (@mentions + replies, no voting) |
| WAITING | Waiting for conditions | Quick checks (only @mentions) |
| PAUSED | Agent is paused | Skip checks |
| COMPLETED | Task completed | Full checks |
| FAILED | Task failed | Full checks |
Using the Agent State
# Start a task (switches to DOING mode)
python universal_memory.py --agent qst doing start \
--task "QST FSCA simulation #42" \
--type Research
# Update progress
python universal_memory.py --agent qst doing update --progress 50
# Pause task
python universal_memory.py --agent qst doing pause --reason "Waiting for resources"
# Resume task
python universal_memory.py --agent qst doing resume
# Complete task
python universal_memory.py --agent qst doing complete --result "Simulation successful: ฯ=0.08"
# View current status
python universal_memory.py --agent qst doing status
# View event history
python universal_memory.py --agent qst doing events
Event History
All state changes are automatically logged with timestamps:
{
"events": [
{
"timestamp": "2026-02-15T09:01:22.206211",
"event_type": "TASK_START",
"description": "ๅผๅง: QST simulation #42",
"progress": 0
},
{
"timestamp": "2026-02-15T09:15:40.754321",
"event_type": "PROGRESS_UPDATE",
"description": "่ฟๅบฆ: QST simulation #42 (50%)",
"progress": 50
},
{
"timestamp": "2026-02-15T09:25:52.121518",
"event_type": "TASK_COMPLETED",
"description": "ๅฎๆ: QST simulation #42",
"result": "Simulation successful"
}
]
}
๐ก๏ธ Loop Protection System (v1.8.2 New)
Anti-Loop Protection Mechanisms
v1.8.2 introduces comprehensive protection against infinite task loops and system resource exhaustion.
Protection Layers
Layer 1: Heartbeat Throttling
- Minimum 30-second interval between checks
- Prevents rapid-fire heartbeat calls
Layer 2: Stagnation Detection
- Detects tasks with no progress for 15+ minutes
- Tracks progress history automatically
Layer 3: Timeout Detection
- Priority-based timeouts:
* Critical: 30 minutes
* High: 45 minutes
* Normal: 60 minutes
* Low: 120 minutes
Layer 4: Auto-Recovery
- Automatic priority downgrade (critical โ high โ normal)
- Auto-BLOCK for extreme timeout (2x threshold)
- Requires human intervention for resolved blocked tasks
Configuration
{
"loop_protection": {
"critical_timeout_minutes": 30,
"high_timeout_minutes": 45,
"normal_timeout_minutes": 60,
"low_timeout_minutes": 120,
"heartbeat_min_interval_seconds": 30,
"stagnation_threshold_minutes": 15,
"auto_downgrade_on_stagnation": true,
"max_stagnant_checks": 10
}
}
API Methods
# Check if task is stuck
is_stagnant, reason = state_mgr.is_stagnant()
# Check if task has timed out
is_timeout, reason, minutes = state_mgr.is_timeout()
# Auto-handle stuck tasks
result = state_mgr.auto_handle_stagnation()
# Returns: {"action": "downgrade" | "block" | "none", ...}
# Check if heartbeat should be throttled
should_throttle, reason, wait_seconds = state_mgr.should_throttle_heartbeat()
Auto-Recovery Actions
| Situation | Action | Trigger |
|---|---|---|
| Critical task stagnation | Downgrade to HIGH | 30+ min no progress |
| Critical task timeout | Downgrade to HIGH | 30+ min elapsed |
| High task stagnation | Downgrade to NORMAL | 15+ min no progress |
| High task deadline (2x) | Auto-BLOCK | 90+ min elapsed |
| Normal task deadline (2x) | Auto-BLOCK | 120+ min elapsed |
Heartbeat Output with Loop Protection
============================================================
โค๏ธ Heartbeat Started: 2026-02-15 16:05:00 UTC
============================================================
๐ค Agent: lisi | ็ๆ
: DOING | ๅชๅ
็ด: CRITICAL
ไปปๅ: ๆธฌ่ฉฆ้ฒๆญปๅพช็ฐไฟ่ญท
้ฒๅบฆ: 42%
๐ก๏ธ Loop Protection:
โ
ๅฟ่ทณ้ ป็ๆญฃๅธธ (ไธๆฌกๆชขๆฅ: 32 ็งๅ)
โ
ไปปๅๆชๅๆปฏ (ไธๆฌกๆดๆฐ: 5 ๅ้ๅ)
โ
ๆช่ถ
ๆ (้่กๆ้: 25 ๅ้ < ้พๅผ: 30 ๅ้)
๐ ็ๆ
: DOING [CRITICAL] - ๆๅฐๅๅนฒๆพ
๐ข ้็ฅ: 0 ๆๅ, 0 ๅ่ฆ
โ ่ทณ้: HKGBook ๅทก้, ๆ็ฅจๆชขๆฅ
============================================================
โ
Heartbeat Completed: 2026-02-15 16:05:01 UTC
============================================================
Throttled Heartbeat Example
[lisi] โธ๏ธ ๅฟ่ทณ้ ป็้ๅถ๏ผToo frequent (3s < 30s)๏ผ็ญๅพ
27 ็ง๏ผ
Check Result:
- ไพๆบ: lisi_doing-state.json
- ้่ผฏ: ็ถๅๆ้ - ไธๆฌกๆชขๆฅๆ้ < ๆๅฐ้้
- ่กๅ: ่ทณ้ๆฌๆฌกๆชขๆฅ
- ๅๅ : ้ฟๅ
ๆญปๅพช็ฐ๏ผไฟ่ญท็ณป็ตฑ่ณๆบ
Solving the Infinite Loop Problem
Problem (v1.8 initial deployment):
{
"status": "doing",
"task": "QST Memory v1.8 ๅฏฆๆฝ",
"progress": 0,
"priority": "critical",
"start_time": "14:08:59"
}
Task stuck at 0% for 1.77 hours โ infinite heartbeat loop.
Solution (v1.8.2):
Heartbeat Check 1 (16:00):
- Check interval: 0 seconds (OK)
- Task timeout: 51+ minutes > 30m threshold
- Auto-action: DOWNGRADE priority (critical โ high)
Heartbeat Check 2 (16:05):
- Check interval: 300 seconds (OK, >30s min)
- Task timeout: 56+ minutes > 45m threshold
- Stagnation detected (0% for 15+ min)
- Auto-action: BLOCK task (requires human intervention)
Result:
- Priority: high
- Status: BLOCKED
- Reason: "ไปปๅๅๆปฏ้ไน
: ๅท่กๆ้ 56 ๅ้่ถ
้๏ผ้พๅผ๏ผ45 ๅ้๏ผ"
- Heartbeat: Only check @mentions and alerts
- Loop eliminated โ
๐ค User Priority Response Mechanism (v1.8.2 New)
v1.8.2 introduces the User Priority Window, ensuring system heartbeats do not interrupt active user conversations.
How it Works
- Detection: Tracks the timestamp of the last user interaction.
- Priority Window: Defines a window (default 30 min) where user needs take absolute precedence.
- Skipping: System heartbeats are automatically skipped if they fall within this window.
- Safety Valve: Allows up to a configurable number of skips (default 3) before forcing a check to ensure system health.
Configuration
Heartbeat Output (User Priority Mode)
๐ Heartbeat Integration (v1.7.1 New)
State-Driven Checking Strategy
The system intelligently adjusts heartbeat checking based on agent state:
# When agent is DOING: Only check critical notifications
# - โ
Check: @mentions, replies
# - โ Skip: Voting (to avoid interrupting work)
# When agent is IDLE: Full checking
# - โ
Check: @mentions, replies, voting
Setting Up Heartbeat Integration
# Copy integration script to workspace
cp scripts/heartbeat_integration.py /home/node/.openclaw/workspace/heartbeat.py
chmod +x /home/node/.openclaw/workspace/heartbeat.py
# Set up cron task (every 20 minutes)
crontab -e
# Add: */20 * * * * python3 /home/node/.openclaw/workspace/heartbeat.py
Heartbeat Output
============================================================
โค๏ธ Heartbeat Started: 2026-02-15 09:15:26 UTC
============================================================
๐ค Agent: qst | ็ๆ
: DOING
ไปปๅ: QST simulation #42
้กๅ: Research
้ฒๅบฆ: 50%
๐ ็ๆ
: DOING - ๅท่ก HKGBook ๆชขๆฅ (็ญ็ฅ: ็ฐกๅ)
๐ข ้็ฅ: 0 ๆๅ, 0 ๅ่ฆ
โ ๏ธ DOING/WAITING - ่ทณ้ๆ็ฅจ
โ
HKGBook ๆชขๆฅๅฎๆ
============================================================
โ
Heartbeat Completed: 2026-02-15 09:15:28 UTC
============================================================
Multi-Agent Support
Each agent maintains independent state:
# qst agent
/data/qst_doing-state.json
# mengtian agent
/data/mengtian_doing-state.json
# lisi agent
/data/lisi_doing-state.json
๐ Memory Encryption (v1.7 New)
AES-128-CBC + HMAC Encryption
Sensitive data (API keys, passwords, tokens) can be encrypted using industrial-grade encryption:
from crypto import MemoryCrypto
crypto = MemoryCrypto()
encrypted = crypto.encrypt("GitHubPAT: ghp_xxx...")
# Output: ENC::gAAAAABgF7qj... (encrypted string)
decrypted = crypto.decrypt(encrypted)
# Output: "GitHubPAT: ghp_xxx..."
Key Management
- Key storage:
~/.qst_memory.key(mode 600) - Key derivation: PBKDF2HMAC (SHA256, 480,000 iterations)
- Encryption algorithm: Fernet (AES-128-CBC + HMAC)
๐ Statistics Panel
python qst_memory.py stats
Output:
๐ QST Memory v1.5 ็ตฑ่จ้ขๆฟ
โโโ ๅ้ก็ตๆง: 34 ๅ้ก
โโโ ่จๆถ็ธฝๆธ: 156 ๆข
โโโ Token ไผฐ็ฎ: ~8,500
โโโ ่กฐๆธ็ๆ
: 3 ๆข้ซ่กฐๆธ
๐พ Memory Format
# Memory Title
[Category] [Weight]
Date: 2026-02-14
Content...
Tags: tag1, tag2
๐ Quick Start
# Search with hybrid mode (default)
python qst_memory.py search "ๆ็ฉ่ณช"
# Enhanced semantic with context
python qst_memory.py search "ARM่ฏ็" --method enhanced --context "ๆ่ก่จ่ซ"
# Auto-classify content
python qst_memory.py classify "QSTๆ็ฉ่ณช่จ็ฎไฝฟ็จFSCA"
# Save with auto-classification
python qst_memory.py save "ๆก็จ FSCA v7 ไฝ็บๆ็ฉ่ณช็่ซ"
# Cleanup preview
python qst_memory.py cleanup --dry-run
# Statistics
python qst_memory.py stats
๐ File Structure
qst-memory/
โโโ SKILL.md # This file
โโโ config.yaml # Tree config + settings
โโโ qst_memory.py # Main entry (v1.5)
โโโ scripts/
โโโ tree_search.py # Tree search
โโโ bfs_search.py # BFS search
โโโ semantic_search.py # Basic semantic
โโโ semantic_search_v15.py # Enhanced semantic (v1.5)
โโโ hybrid_search.py # Hybrid engine (v1.5)
โโโ auto_classify.py # Auto-classification (v1.5)
โโโ save_memory.py # Smart save (v1.5)
โโโ cleanup.py # Decay system (v1.5)
โโโ stats_panel.py # Statistics
๐ฏ Token Optimization
| Version | Tokens/Query | Relevance |
|---|---|---|
| v1.2 | ~500 | 85% |
| v1.4 | ~300 | 90% |
| v1.5 | ~200 | 95% |
Improvement: 60% token reduction, 95% relevance.
โ๏ธ Configuration
version: '1.5'
search:
default_method: "hybrid"
min_relevance: 0.1
add_category:
max_depth: 3
min_occurrences: 3
decay:
critical: 0 # Never decay
important: 0.1 # Slow decay
normal: 0.5 # Fast decay
cleanup:
enabled: true
max_age_days:
critical: -1 # Never
important: 365 # Archive after 1 year
normal: 30 # Delete after 30 days
๐ง Installation
From ClawHub
clawhub install qst-memory
From GitHub
git clone https://github.com/ZhuangClaw/qst-memory-skill.git
QST Memory v1.5 - Building the next generation of AI memory systems.