This repository was archived by the owner on Apr 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·208 lines (166 loc) · 6.7 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·208 lines (166 loc) · 6.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
# Memory Management Skill - Setup Script
# Initializes the hierarchical memory system in the OpenClaw workspace
set -e
WORKSPACE_DIR="${1:-$HOME/.openclaw/workspace}"
echo "Setting up memory management system in: $WORKSPACE_DIR"
# Create directory structure
echo "Creating directory structure..."
mkdir -p "$WORKSPACE_DIR/memory"
mkdir -p "$WORKSPACE_DIR/knowledge"/{concepts,technology,workflows,preferences,tools}
# Create MEMORY.md if it doesn't exist
if [ ! -f "$WORKSPACE_DIR/MEMORY.md" ]; then
echo "Creating MEMORY.md index file..."
cat > "$WORKSPACE_DIR/MEMORY.md" << 'EOF'
# MEMORY.md - Long-term Memory Index
## System Architecture
This is a hierarchical memory system designed to optimize token usage while preserving knowledge.
## Knowledge Categories
- concepts/ - Abstract concepts and theoretical frameworks
- technology/ - Technical knowledge, APIs, protocols
- workflows/ - Operational procedures and best practices
- preferences/ - User preferences and habits
- tools/ - Tool usage and configurations
## Quick Start Guide
### Learning New Content
1. Identify the knowledge category (concept, technology, workflow, etc.)
2. Create or update a knowledge file in the appropriate directory
3. Generate a summary for this index file
4. Add relevant tags for future retrieval
### Retrieving Knowledge
- Use `memory_search(query="keywords")` for semantic search
- Use `memory_get(path="file.md", from=10, lines=20)` for precise reading
- Check this index file for important cross-references
## Update Log
- System initialized: $(date)
EOF
else
echo "MEMORY.md already exists, skipping creation."
fi
# Create knowledge base README if it doesn't exist
if [ ! -f "$WORKSPACE_DIR/knowledge/README.md" ]; then
echo "Creating knowledge base README..."
cat > "$WORKSPACE_DIR/knowledge/README.md" << 'EOF'
# Knowledge Base
Systematic storage for all learned content. Follows structured formats for easy retrieval.
## Directory Structure
### concepts/
Abstract concepts, theoretical frameworks, mental models.
### technology/
Technical knowledge, API documentation, protocol specifications, code examples.
### workflows/
Operational procedures, best practices, step-by-step guides, decision trees.
### preferences/
User preferences, habits, expectations, communication styles.
### tools/
Tool usage, configurations, integration guides, troubleshooting.
## File Standards
Each knowledge file should include:
1. Metadata section (learning time, source, importance)
2. Core summary (50-100 words)
3. Detailed content (hierarchical structure)
4. Key takeaways (bulleted list)
5. Application scenarios (practical use cases)
6. Related links (reference sources)
7. Tags (for retrieval)
## Retrieval Methods
1. **Semantic search**: `memory_search(query="keywords")`
2. **Precise reading**: `memory_get(path="file.md", from=10, lines=20)`
3. **Directory browsing**: Direct file access by category
## Maintenance
- Update files when learning new related content
- Review and consolidate knowledge periodically
- Archive or delete outdated information
- Ensure consistency across related concepts
EOF
else
echo "knowledge/README.md already exists, skipping creation."
fi
# Create example knowledge files
echo "Creating example knowledge files..."
# Example 1: Token optimization strategy
if [ ! -f "$WORKSPACE_DIR/knowledge/workflows/token-optimization.md" ]; then
cat > "$WORKSPACE_DIR/knowledge/workflows/token-optimization.md" << 'EOF'
# Token Optimization Strategy
## Metadata
- **Learned**: $(date +%Y-%m-%d)
- **Source**: Memory Management Skill setup
- **Importance**: ⭐⭐⭐⭐⭐
- **Related**: #memory-management #efficiency #ai-context
- **Last Updated**: $(date +%Y-%m-%d)
## Core Summary
File-based hierarchical memory system that reduces AI conversation token consumption by storing long-term memories externally and retrieving only relevant snippets when needed.
## Key Principles
1. **Three-layer memory**: Short-term (context), mid-term (daily logs), long-term (knowledge base)
2. **Intelligent summarization**: Generate concise summaries at conversation milestones
3. **Efficient retrieval**: Semantic search + precise file access
4. **Structured organization**: Five knowledge categories for systematic storage
## Expected Benefits
- **89% token savings** compared to traditional cumulative context
- **Preserved knowledge continuity** across long conversations
- **Improved reasoning depth** through accumulated knowledge
- **Personalized service** through long-term preference tracking
## Implementation Steps
1. Initialize directory structure (already done by setup.sh)
2. Learn new content → create/update knowledge files
3. Generate summaries for MEMORY.md index
4. Retrieve knowledge as needed using memory tools
## Tags
- #token-optimization
- #memory-management
- #file-based-storage
- #efficiency
EOF
fi
# Example 2: Skill documentation
if [ ! -f "$WORKSPACE_DIR/knowledge/tools/memory-management-skill.md" ]; then
cat > "$WORKSPACE_DIR/knowledge/tools/memory-management-skill.md" << 'EOF'
# Memory Management Skill
## Metadata
- **Learned**: $(date +%Y-%m-%d)
- **Source**: Skill installation
- **Importance**: ⭐⭐⭐⭐
- **Related**: #openclaw #skills #ai-tools
- **Last Updated**: $(date +%Y-%m-%d)
## Overview
OpenClaw skill that implements a file-based hierarchical memory system for AI agents.
## Key Features
1. **Three-layer memory architecture** for optimal token usage
2. **Structured knowledge base** with five categories
3. **Intelligent summarization** at conversation milestones
4. **Efficient retrieval** through semantic search
5. **Extensible design** for customization and integration
## Installation
```bash
# Run setup script
./setup.sh [workspace_directory]
```
## Usage
1. After setup, the system is automatically integrated into OpenClaw
2. Use standard memory tools: `memory_search()` and `memory_get()`
3. Follow file standards when creating knowledge entries
4. Regular maintenance ensures optimal performance
## Integration
- Works with existing OpenClaw tools and skills
- Can be extended with vector databases or knowledge graphs
- Compatible with other memory systems through standardized formats
## Tags
- #openclaw-skill
- #memory-system
- #ai-infrastructure
EOF
fi
echo "Setup complete!"
echo ""
echo "Memory management system initialized with:"
echo " - Directory structure in $WORKSPACE_DIR"
echo " - MEMORY.md index file"
echo " - Knowledge base README"
echo " - Two example knowledge files"
echo ""
echo "To use the system:"
echo " 1. Learn new content → create files in knowledge/ directories"
echo " 2. Search for knowledge → use memory_search() and memory_get()"
echo " 3. Maintain the system → periodic review and consolidation"
echo ""
echo "For detailed usage, see the SKILL.md documentation."