Version: 1.0.0
Type: Context Enhancement Skill for AI Agents
Language: Bash (Shell Scripts)
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)
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)
| 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 |
# Clone to your skills directory
git clone https://github.com/YOUR_USERNAME/session-memory-check.git
cd session-memory-check# 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" falseAdd 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 prefixsession-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
Purpose: Detect message type and decide trigger level
Usage:
./scripts/session-memory-trigger.sh <message> <is_first_message>Arguments:
message: The user message contentis_first_message:trueorfalse
Output:
- Message type (task/question/correction/amnesia/chat)
- Trigger level (L1/L2/L3/none)
- Memory context (if triggered)
Purpose: Load memory context based on trigger level
Usage:
./scripts/session-memory-loader.sh <level>Arguments:
level:L1,L2, orL3
Output:
- Formatted memory context for injection
| 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.
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
- ✅ 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
## 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
// 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;
}Edit scripts/session-memory-trigger.sh:
# Task assignment keywords
case "$msg" in
*your_keyword*|*another_keyword*)
echo "task"
;;
esacEdit 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"Solution:
chmod +x scripts/*.shSolution: Ensure your shell supports UTF-8:
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8Solution: Reduce line count in session-memory-loader.sh:
read_lines "$WORKSPACE/SOUL.md" 10 # Reduce from 20 to 10MIT License - See LICENSE file for details
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Created: 2026-04-03
Version: 1.0.0
Language: Bash (Shell)
Compatible: Linux, macOS, WSL