Skip to content

Yuancircle/session-memory-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Session Memory Check Skill

Version: 1.0.0
Type: Context Enhancement Skill for AI Agents
Language: Bash (Shell Scripts)


🎯 What It Does

Intelligently loads memory context based on message type, balancing "memory coverage" and "context token efficiency".

Key Features:

  • ✅ Session startup auto-load (prevents AI amnesia)
  • ✅ Task-related context injection
  • ✅ Amnesia signal detection
  • ✅ Normal chat skip (saves tokens)
  • ✅ Graded loading (L1/L2/L3)

📋 How It Works

Trigger Mechanism (3-Layer Filter)

Message Received
    ↓
Layer 1: Is it the first session message?
├─ Yes → Trigger L1 Light Load
└─ No → Layer 2

Layer 2: Message Type Detection
├─ Task Assignment → Trigger L2 Standard Load
├─ Question → Trigger L2 Standard Load
├─ Correction → Trigger L3 Full Load
└─ Normal Chat → Layer 3

Layer 3: Context Check
├─ AI Amnesia Signal → Trigger L3 Full Load
├─ User Correction → Trigger L3 Full Load
└─ Normal → No Trigger (Save Tokens)

📦 Load Levels

Level Trigger Content Token Usage
L1 Light Session 1st message Identity + User + Today's Tasks ~500 chars
L2 Standard Task/Question L1 + Current Projects + Rules ~1000 chars
L3 Full Correction/Amnesia L2 + Lessons + Requirements ~2000 chars
None Normal chat Nothing 0 chars

🚀 Quick Start

1. Install

# Clone to your skills directory
git clone https://github.com/YOUR_USERNAME/session-memory-check.git
cd session-memory-check

2. Test

# Test session startup
./scripts/session-memory-trigger.sh "Hello" true

# Test task assignment
./scripts/session-memory-trigger.sh "Do XXX task" false

# Test amnesia detection
./scripts/session-memory-trigger.sh "You forgot again" false

# Test normal chat (should not trigger)
./scripts/session-memory-trigger.sh "Nice weather" false

3. Integrate

Add to your agent's system prompt or config:

# On message received
./scripts/session-memory-trigger.sh "$MESSAGE" "$IS_FIRST_MESSAGE"

# Inject output to system prompt prefix

📁 File Structure

session-memory-check/
├── SKILL.md                      # Full documentation
├── README.md                     # This file (quick start)
├── scripts/
│   ├── session-memory-loader.sh   # Memory loader
│   ├── session-memory-trigger.sh  # Trigger detector
│   └── run-tests.sh               # Test runner
├── tests/
│   └── test-report.md            # Test results
└── examples/
    └── integration.md            # Integration examples

🔧 Scripts

session-memory-trigger.sh

Purpose: Detect message type and decide trigger level

Usage:

./scripts/session-memory-trigger.sh <message> <is_first_message>

Arguments:

  • message: The user message content
  • is_first_message: true or false

Output:

  • Message type (task/question/correction/amnesia/chat)
  • Trigger level (L1/L2/L3/none)
  • Memory context (if triggered)

session-memory-loader.sh

Purpose: Load memory context based on trigger level

Usage:

./scripts/session-memory-loader.sh <level>

Arguments:

  • level: L1, L2, or L3

Output:

  • Formatted memory context for injection

📊 Token Efficiency

Scenario Without Skill With Skill Savings
Session startup 0 chars ~500 chars -500 (necessary)
Task assignment 0 chars ~1000 chars -1000 (necessary)
Normal chat (10 msgs) 0 chars 0 chars ✅ 0
Average 0 chars ~900 chars ✅ Efficient

Note: The skill only loads context when necessary, saving tokens on normal chats.


✅ Test Results

All tests passed:

Test Case Input Expected Result
Session startup "Hello" (first) L1 trigger ✅ Pass
Task assignment "Do XXX task" L2 trigger ✅ Pass
Amnesia detection "You forgot" L3 trigger ✅ Pass
Normal chat "Nice weather" No trigger ✅ Pass

Test Report: tests/test-report.md


🎯 Success Metrics

  • ✅ Session startup 100% triggers L1
  • ✅ Task assignment 100% triggers L2
  • ✅ Amnesia signal 100% triggers L3
  • ✅ Normal chat 0% triggers
  • ✅ Average context < 1000 characters
  • ✅ 10 consecutive sessions without amnesia

🤝 Integration Examples

Example 1: OpenClaw Agent

## Session Startup Check

In AGENTS.md:
```bash
./skills/session-memory-check/scripts/session-memory-trigger.sh "$MESSAGE" true

### Example 2: Custom Agent

```python
# Python wrapper
import subprocess

def inject_memory_context(message, is_first):
    result = subprocess.run([
        './scripts/session-memory-trigger.sh',
        message,
        str(is_first).lower()
    ], capture_output=True, text=True)
    return result.stdout

Example 3: Node.js Agent

// Node.js wrapper
const { execSync } = require('child_process');

function injectMemoryContext(message, isFirst) {
    const output = execSync(
        `./scripts/session-memory-trigger.sh "${message}" ${isFirst}`
    ).toString();
    return output;
}

📝 Configuration

Customize Keywords

Edit scripts/session-memory-trigger.sh:

# Task assignment keywords
case "$msg" in
    *your_keyword*|*another_keyword*)
        echo "task"
        ;;
esac

Customize Load Levels

Edit scripts/session-memory-loader.sh:

# L1: Change line count
read_lines "$WORKSPACE/SOUL.md" 20  # Change 20 to your preference

# L2: Add more sections
read_memory_sections "Your Section"

🐛 Troubleshooting

Issue: Script not found

Solution:

chmod +x scripts/*.sh

Issue: Chinese characters not matching

Solution: Ensure your shell supports UTF-8:

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Issue: Context too long

Solution: Reduce line count in session-memory-loader.sh:

read_lines "$WORKSPACE/SOUL.md" 10  # Reduce from 20 to 10

📄 License

MIT License - See LICENSE file for details


🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

📬 Contact

  • Issues: GitHub Issues
  • Discussions: GitHub Discussions

Created: 2026-04-03
Version: 1.0.0
Language: Bash (Shell)
Compatible: Linux, macOS, WSL

About

Intelligent memory context loading for AI agents - Prevents AI amnesia with token-efficient graded loading

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages