qst-memory

star 8

Universal Memory Management System v1.8.2 for OpenClaw agents. Provides: 1. Multi-Agent Support (qst, mengtian, lisi, custom) 2. Agent State System ("I'm Doing") - IDLE/DOING/WAITING/PAUSED/COMPLETED/FAILED/BLOCKED 3. Heartbeat Integration - State-driven intelligent checking strategy 4. **NEW v1.8.2**: Loop Protection & User Priority - Auto-detection and handling of stuck tasks 5. Tree-based classification structure (3-level hierarchy) 6. Three search methods: Tree, Semantic, Hybrid 7. Auto-classification with AI inference 8. Appendix Indexing for technical documents 9. Memory encryption (AES-128-CBC + HMAC) for sensitive data 10. 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.

modbender By modbender schedule Updated 3/6/2026

name: qst-memory description: | Universal Memory Management System v1.8.2 for OpenClaw agents. Provides:

  1. Multi-Agent Support (qst, mengtian, lisi, custom)
  2. Agent State System ("I'm Doing") - IDLE/DOING/WAITING/PAUSED/COMPLETED/FAILED/BLOCKED
  3. Heartbeat Integration - State-driven intelligent checking strategy
  4. NEW v1.8.2: Loop Protection & User Priority - Auto-detection and handling of stuck tasks
  5. Tree-based classification structure (3-level hierarchy)
  6. Three search methods: Tree, Semantic, Hybrid
  7. Auto-classification with AI inference
  8. Appendix Indexing for technical documents
  9. Memory encryption (AES-128-CBC + HMAC) for sensitive data
  10. 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

  1. Detection: Tracks the timestamp of the last user interaction.
  2. Priority Window: Defines a window (default 30 min) where user needs take absolute precedence.
  3. Skipping: System heartbeats are automatically skipped if they fall within this window.
  4. 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.

Install via CLI
npx skills add https://github.com/modbender/skill-library-mcp --skill qst-memory
Repository Details
star Stars 8
call_split Forks 2
navigation Branch main
article Path SKILL.md
More from Creator