Skip to content

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

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages