OpenClaw for Organizations 2026 • Post #3

Memory & Knowledge ManagementMemory & Knowledge Management

ให้ Agent จำได้และเรียนรู้Teaching Your Agent to Remember and Learn

โดย Anirach Mingkhwan เผยแพร่ 10 มีนาคม 2026 · 28 min read
Memory — ให้ Agent จำได้และเรียนรู้
ในบทความนี้
  1. 🧠 ทำไม AI ที่จำอะไรไม่ได้ถึงไม่มีประโยชน์?
  2. 🏗️ Memory Architecture ของ OpenClaw
  3. 📁 ไฟล์ Memory ที่สำคัญ
  4. ✅ Memory Management Best Practices
  5. 🕸️ Knowledge Graph & Obsidian Vault
  6. 🔍 Semantic Search — ChromaDB
  7. 💓 Heartbeat System — Proactive Memory
  8. 🔐 Memory Security
  9. 🔄 Pre-Compaction Memory Flush
  10. 🌅 ตัวอย่างจริง: One Day in Agent's Life
  11. 🎯 Key Takeaways
In this post
  1. 🧠 Why Is an AI That Remembers Nothing Useless?
  2. 🏗️ OpenClaw's Memory Architecture
  3. 📁 The Memory Files That Matter
  4. ✅ Memory Management Best Practices
  5. 🕸️ Knowledge Graph & Obsidian Vault
  6. 🔍 Semantic Search — ChromaDB
  7. 💓 Heartbeat System — Proactive Memory
  8. 🔐 Memory Security
  9. 🔄 Pre-Compaction Memory Flush
  10. 🌅 A Real Example: One Day in Agent's Life
  11. 🎯 Key Takeaways

🧠 ทำไม AI ที่จำอะไรไม่ได้ถึงไม่มีประโยชน์?

ลองจินตนาการดูว่าคุณมี assistant ที่เก่งมาก แต่ทุกเช้าที่มาทำงาน เขาจะลืมทุกอย่างที่เกิดขึ้นเมื่อวาน ไม่จำว่าเคยพูดคุยเรื่องอะไร ไม่รู้ว่าคุณชอบอะไรไม่ชอบอะไร แม้แต่งานที่ทำผิดพลาดเมื่อวานก็จะทำผิดซ้ำอีก

นี่แหละคือปัญหาของ stateless AI — ระบบที่ไม่มีความจำ ไม่สามารถเรียนรู้จากอดีต และต้องเริ่มต้นใหม่ทุกครั้ง สำหรับ AI agents ที่ต้องทำงานในองค์กรจริง ปัญหานี้ร้ายแรงมาก:

  • ถามซ้ำทุกวัน: "คุณใช้ระบบ ERP อะไร?" หรือ "ขั้นตอนการอนุมัติเงินเดือนคืออะไร?" ถามเมื่อวาน วันนี้ถามอีก
  • ลืม preferences: ไม่จำว่าคุณชอบให้รายงานแบบไหน หรือเวลาไหนที่ไม่ควรรบกวน
  • ไม่เรียนรู้จากข้อผิดพลาด: ทำผิดเรื่องเดิม ๆ ซ้ำไปซ้ำมา เพราะไม่จำบทเรียนที่ได้รับ
  • ไม่มีความเชื่อมต่อ: แต่ละ conversation เป็นเหมือนพูดคุยกับคนแปลกหน้าเสมอ

💡 ทำไมความจำถึงสำคัญ?

ความจำไม่ใช่แค่การเก็บข้อมูล แต่เป็นการสร้าง context ที่ทำให้ AI เข้าใจสถานการณ์ปัจจุบันผ่านประสบการณ์ในอดีต ทำให้ตอบสนองได้อย่างเหมาะสมและต่อเนื่อง

🏗️ Memory Architecture ของ OpenClaw

OpenClaw แก้ปัญหานี้ด้วยระบบหน่วยความจำ 3 ชั้น ที่ออกแบบมาให้ทำงานร่วมกันเหมือนสมองมนุษย์:

📊 OpenClaw Memory Architecture

SHORT-TERM MEMORY
(Context Window — 200K tokens)
• Current conversation
• Active working memory
• Immediate context
↓
Automatic flush before overflow
MEDIUM-TERM MEMORY
(Daily Logs: memory/YYYY-MM-DD.md)
• Session snapshots
• Daily activities
• Scratch notes
• Temporary observations
↓
Manual review & distillation
LONG-TERM MEMORY
(Curated: MEMORY.md)
• Key facts & lessons learned
• Important preferences
• Security information
• Permanent knowledge

🔄 Short-term Memory (Context Window)

เป็นหน่วยความจำชั่วคราวที่เก็บบทสนทนาปัจจุบันและข้อมูลที่กำลังใช้งาน มีขนาดประมาณ 200K tokens (ประมาณ 150,000 คำ) เมื่อใกล้จะเต็มแล้ว ระบบจะทำการ "memory flush" โดยอัตโนมัติเพื่อเก็บข้อมูลสำคัญไว้ก่อนที่จะล้างพื้นที่

📅 Medium-term Memory (Daily Logs)

เป็นการบันทึกกิจกรรมในแต่ละวันลงในไฟล์ memory/YYYY-MM-DD.md ทำหน้าที่เหมือน "daily journal" ที่เก็บสิ่งที่เกิดขึ้น คำสั่งที่รัน การตัดสินใจที่ทำ และบทเรียนที่ได้รับในแต่ละวัน

🎯 Long-term Memory (Curated Knowledge)

เป็นความรู้ที่ถูกคัดกรองแล้วใน MEMORY.md เก็บข้อมูลสำคัญที่ต้องจำไว้ตลอด เช่น รหัสผ่านความปลอดภัย ข้อมูลผู้ใช้ บทเรียนสำคัญ และความรู้ที่จำเป็นสำหรับการทำงาน

📁 ไฟล์ Memory ที่สำคัญ

ระบบหน่วยความจำของ OpenClaw ประกอบด้วยไฟล์หลักสำคัญ แต่ละไฟล์มีบทบาทและรูปแบบการใช้งานที่แตกต่างกัน:

🧠 MEMORY.md - Curated Long-term Memory

เป็นหัวใจของระบบความจำ เก็บข้อมูลที่ถูกคัดกรองแล้วและจำเป็นต่อการทำงานในระยะยาว:

# MEMORY.md - Core Agent Memory

## Security
- Security passphrase: "rainbow-elephant-7295"
- GUEST_MODE: Activated for unknown users
- Sensitive data protection protocols active

## User Preferences
- Report format: Professional DOCX with page numbers
- Communication style: Direct, concise, no fluff
- Timezone: Bangkok (UTC+7)
- Language: English for technical work, Thai for documentation

## Key Facts
- Primary database: PostgreSQL on port 5432
- ERP system: SAP with custom modules
- Backup schedule: Daily at 02:00 AM
- Critical servers: srv-app-01, srv-db-01, srv-backup-01

## Lessons Learned
- 2026-03-08: Never run raw psql commands - always use ha_query.py wrapper
- 2026-03-09: DOCX reports must include page X of Y footer
- 2026-03-10: Long tasks should spawn sub-agents to keep chat responsive

## Important Connections
- Admin contact: [email protected]
- Emergency escalation: +66-2-xxx-xxxx
- Vendor support: Weekdays 9-17 Bangkok time

📅 memory/YYYY-MM-DD.md - Daily Logs

เป็นบันทึกประจำวันที่เก็บกิจกรรม การตัดสินใจ และข้อสังเกตต่าง ๆ ทำหน้าที่เป็น "session history" ที่สามารถย้อนกลับไปดูได้:

# 2026-03-10.md - Daily Memory Log

## Session Summary
- Started: 07:45 Bangkok time
- Task: Writing OpenClaw blog post #3 about memory management
- Spawned sub-agent: openclaw-blog-3 for content creation

## Key Activities
1. **Blog Writing** (07:45-08:30)
   - Created comprehensive Thai-language post about memory systems
   - Used proper CSS structure with purple theme (#8b5cf6)
   - Included all required components: code-block, diagram-box, info-card

2. **File Management** (08:20)
   - Saved to tmp/openclaw-memory.html and tmp/openclaw-memory.md
   - Followed series navigation structure

## Observations
- User prefers comprehensive explanations over code dumps
- Purple theme (#8b5cf6) is standard for OpenClaw blog series
- Series format: Post #3, links to previous and upcoming posts

## Decisions Made
- Used Thai language with English technical terms
- Included substantial explanations between code examples
- Created both HTML (styled) and Markdown (clean) versions

💓 HEARTBEAT.md - Proactive Memory System

เป็นระบบที่ทำให้ agent มี "proactive awareness" โดยจะตรวจสอบและรายงานสถานการณ์สำคัญโดยอัตโนมัติ:

# HEARTBEAT.md - Proactive Monitoring

## Check Rotation Schedule
- **Morning** (08:00): Email, calendar, system health
- **Afternoon** (14:00): Sub-agent status, pending tasks
- **Evening** (18:00): Daily summary, memory distillation
- **Night** (22:00): Backup verification, security scan

## Heartbeat State Tracking
```json
{
  "last_email_check": "2026-03-10T08:00:00+07:00",
  "last_calendar_sync": "2026-03-10T08:00:00+07:00",
  "active_subagents": ["openclaw-blog-3"],
  "pending_tasks": [],
  "memory_last_distilled": "2026-03-09T18:00:00+07:00"
}
```

## Memory Distillation Workflow
1. Review daily logs from past 3 days
2. Extract key facts and lessons learned
3. Update MEMORY.md with important information
4. Archive old daily logs (keep last 30 days)
5. Update knowledge graph connections
💡 Memory Flow: ข้อมูลจะไหลจาก daily logs → review process → distilled knowledge ใน MEMORY.md อย่างต่อเนื่อง สร้างความต่อเนื่องในการเรียนรู้และพัฒนา

✅ Memory Management Best Practices

การจัดการหน่วยความจำอย่างมีประสิทธิภาพต้องอาศัยหลักการและระเบียบวินัยที่ชัดเจน:

📝 เขียนทันที อย่าแอบอิง

"Mental notes don't survive restarts" — นี่คือกฎข้อแรกที่สำคัญที่สุด เมื่อคิดว่า "จำไว้ในใจก็พอ" แล้วระบบ restart ข้อมูลนั้นจะหายไปทันที ต้องเขียนลงไฟล์ทันทีที่นึกขึ้นมา

// ❌ ไม่ถูกต้อง - พึ่ง "mental notes"
"I'll remember to check the database backup tomorrow"

// ✅ ถูกต้อง - เขียนลงไฟล์ทันที
echo "TODO: Check database backup status" >> memory/$(date +%Y-%m-%d).md

🎯 Be Specific, Not Vague

การบันทึกข้อมูลแบบคลุมเครือทำให้ไม่สามารถใช้ประโยชน์ได้ในอนาคต ต้องบันทึกรายละเอียดที่เฉพาะเจาะจงและใช้งานได้จริง:

❌ Vague Recording ✅ Specific Recording
"User doesn't like reports" "User prefers reports in DOCX format with page numbers, no PowerPoint presentations"
"System was slow" "Database query timeout at 14:30, resolved by optimizing index on users table"
"Error occurred" "ERROR 1045: Access denied for user 'app'@'localhost' - fixed by resetting MySQL password"
"Meeting went well" "Team approved new deployment process: staging → UAT → production with 2-day intervals"

⚖️ Separate Facts from Opinions

การแยกข้อเท็จจริงออกจากความคิดเห็นช่วยให้การตัดสินใจในอนาคตมีความแม่นยำมากขึ้น:

📊 ตัวอย่างการแยก Facts vs Opinions

Facts: "Deploy failed at 15:30 due to missing database migration script"

Opinion: "I think we should implement better deployment checks"

Actionable: "Add deployment checklist item: Verify all migration scripts exist before deploy"

🧹 Regular Review and Pruning

หน่วยความจำต้องมีการบำรุงรักษาอย่างสม่ำเสมอ ไม่ใช่แค่เพิ่มข้อมูลเข้าไปเรื่อย ๆ:

  • Weekly Review: ตรวจสอบ daily logs และย้ายข้อมูลสำคัญไป MEMORY.md
  • Monthly Cleanup: ลบข้อมูลที่ล้าสมัยหรือไม่เกี่ยวข้องแล้ว
  • Quarterly Audit: ตรวจสอบความถูกต้องและอัพเดทข้อมูลที่เปลี่ยนแปลง
  • Annual Archiving: ย้ายข้อมูลเก่าไปเก็บในที่ปลอดภัยแต่ไม่กีดขวางการทำงานปัจจุบัน

🕸️ Knowledge Graph & Obsidian Vault

ความจำแบบเส้นตรงไม่เพียงพอสำหรับการทำงานที่ซับซ้อน OpenClaw ใช้ Knowledge Graph ผ่าน Obsidian Vault เพื่อสร้างเครือข่ายความรู้ที่เชื่อมโยงกัน:

🔗 Wikilinks & Bidirectional Connections

การใช้ [[wikilinks]] ทำให้สามารถสร้างความเชื่อมโยงระหว่างข้อมูลได้อย่างธรรมชาติ:

# Project Status Report

## Database Migration
- Status: In Progress
- Related: [[Database Schema v2.1]], [[Migration Scripts]], [[Production Deployment]]
- Dependencies: [[User Authentication System]], [[API Endpoints]]
- Timeline: Complete by [[2026-03-15]]

## Risk Assessment
- Main concern: [[Data Integrity]] during migration
- Mitigation: [[Backup Strategy]], [[Rollback Procedures]]
- Contact: [[Database Team]], [[DevOps Lead]]

📊 KnowledgeGraph/ Structure

Obsidian Vault ถูกจัดโครงสร้างแบบเป็นระบบเพื่อให้ง่ายต่อการค้นหาและนำไปใช้:

📁 Obsidian Vault Structure

obsidian-vault/ ├── KnowledgeGraph/ │ ├── Projects/ │ │ ├── Active-Projects.md │ │ ├── Completed-Projects.md │ │ └── Project-Templates.md │ ├── People/ │ │ ├── Team-Members.md │ │ ├── External-Contacts.md │ │ └── Role-Definitions.md │ ├── Systems/ │ │ ├── Infrastructure.md │ │ ├── Applications.md │ │ └── Integrations.md │ └── Processes/ │ ├── Standard-Procedures.md │ ├── Emergency-Protocols.md │ └── Best-Practices.md ├── Daily/ │ ├── 2026-03-10.md │ ├── 2026-03-09.md │ └── Templates/ │ └── Daily-Note-Template.md ├── Agents/ │ ├── Shared/ │ │ ├── Quick-Reference.md │ │ └── Google-Drive-Convention.md │ └── Individual/ │ ├── Arthur-Context.md │ └── Assistant-Notes.md └── Quick-Reference.md

🔄 Git Sync & Version Control

Obsidian Vault ใช้ Git เป็นระบบ version control ทำให้มีการสำรองข้อมูลและ track การเปลี่ยนแปลงอย่างเป็นระบบ:

# Daily sync workflow
cd /home/clawdbot/obsidian-vault

# ดึงข้อมูลล่าสุดจาก remote
git pull origin main

# เพิ่มการเปลี่ยนแปลงใหม่
git add .
git commit -m "Daily update: $(date +%Y-%m-%d) - Added project status"

# ส่งขึ้น remote repository
git push origin main
💡 ทำไม Structured Knowledge ดีกว่า Flat Files: การจัดเก็บแบบ flat files ทำให้ข้อมูลแยกกันเป็นเกาะ ๆ แต่ Knowledge Graph สร้างเครือข่ายความรู้ที่สามารถค้นพบความเชื่อมโยงใหม่ ๆ และเข้าใจบริบทได้ลึกกว่า

การค้นหาแบบ keyword ไม่เพียงพอเมื่อต้องการหาข้อมูลที่เกี่ยวข้องหรือใกล้เคียง OpenClaw ใช้ Semantic Search ผ่าน ChromaDB เพื่อค้นหาตามความหมายและบริบท:

🧠 Embeddings Concept

Embeddings คือการแปลงข้อความให้กลายเป็น "vector" หรือชุดตัวเลขที่สะท้อนความหมาย ทำให้คอมพิวเตอร์เข้าใจว่าข้อความใดใกล้เคียงกันด้านความหมาย:

🎯 ตัวอย่าง Semantic Similarity

Query: "database connection problems"

Traditional Search จะหา: ข้อความที่มีคำว่า "database", "connection", "problems" ตรง ๆ

Semantic Search จะหา: "MySQL timeout errors", "PostgreSQL connectivity issues", "database access failures" ทั้งที่ไม่มีคำที่ match เป็นการใช้ความหมายในการค้นหา

⚙️ ChromaDB Implementation

OpenClaw ใช้ Gemini embeddings (gemini-embedding-001) ร่วมกับ ChromaDB เพื่อสร้างระบบค้นหาที่เข้าใจความหมาย:

# การใช้งาน ChromaDB ผ่าน chroma_helper.py

# Activate virtual environment
source .venv/bin/activate

# ค้นหาข้อมูลเกี่ยวกับ database issues
python3 tools/chroma_helper.py search "database connection timeout"

# ผลลัพธ์ที่ได้
Results:
1. memory/2026-03-08.md (similarity: 0.89)
   "MySQL connection timeout at 14:30, resolved by increasing wait_timeout parameter"

2. MEMORY.md (similarity: 0.85)
   "Database issues: Always check connection pool settings first"

3. memory/2026-03-07.md (similarity: 0.82)
   "PostgreSQL slow queries fixed by adding index on user_id column"

🆚 Semantic Search vs Grep

การเลือกใช้ tool ที่เหมาะสมขึ้นอยู่กับลักษณะของข้อมูลที่ต้องการ:

เงื่อนไข ใช้ Semantic Search ใช้ Grep
ค้นหาแนวคิดหรือหัวข้อ ✅ เช่น "security issues" ❌ จะได้แค่ข้อความที่มีคำนี้
ค้นหาข้อความแน่นอน ❌ อาจได้ผลที่ใกล้เคียง ✅ เช่น "ERROR 1045"
ค้นหา code หรือ commands ❌ Embeddings ไม่เข้าใจ syntax ✅ เช่น "git commit"
ค้นหาข้อมูลที่เกี่ยวข้อง ✅ หาสิ่งที่เกี่ยวข้องทางความหมาย ❌ ได้แค่ keyword matching
ค้นหาใน log files ❌ ต้องการความแม่นยำ ✅ ค้นหา timestamp, error codes
# ตัวอย่างการใช้งานที่เหมาะสม

# 🔍 Semantic Search - หาแนวคิดที่เกี่ยวข้อง
python3 tools/chroma_helper.py search "performance optimization"

# 🔍 Grep - หา error code แน่นอน
grep -r "ERROR 1045" memory/

# 🔍 Semantic Search - หาวิธีแก้ปัญหาคล้ายกัน
python3 tools/chroma_helper.py search "slow database queries"

# 🔍 Grep - หา command ที่ใช้
grep -r "mysql -u" memory/

💓 Heartbeat System — Proactive Memory

Heartbeat System เป็นกลไกที่ทำให้ OpenClaw มี "situational awareness" โดยจะตรวจสอบและรายงานสถานการณ์สำคัญโดยไม่ต้องรอให้ผู้ใช้สั่ง ทำงานคล้าย "background consciousness":

📊 heartbeat-state.json Tracking

ระบบใช้ไฟล์ JSON เพื่อ track สถานะการตรวจสอบต่าง ๆ และหมุนเวียนการตรวจสอบอย่างมีระบบ:

{
  "last_checks": {
    "email": "2026-03-10T08:00:00+07:00",
    "calendar": "2026-03-10T08:00:00+07:00",
    "subagents": "2026-03-10T07:45:00+07:00",
    "system_health": "2026-03-10T06:00:00+07:00",
    "weather": "2026-03-10T07:00:00+07:00"
  },
  "rotation_schedule": {
    "morning": ["email", "calendar", "system_health"],
    "afternoon": ["subagents", "pending_tasks", "weather"],
    "evening": ["daily_summary", "memory_distillation"],
    "night": ["backup_verify", "security_scan"]
  },
  "active_monitoring": {
    "subagents": ["openclaw-blog-3"],
    "pending_tasks": [],
    "alerts": []
  },
  "memory_stats": {
    "last_distillation": "2026-03-09T18:00:00+07:00",
    "daily_logs_count": 3,
    "memory_size_kb": 15.2
  }
}

🔄 Rotation of Checks

แทนที่จะตรวจสอบทุกอย่างทุกครั้ง ระบบจะหมุนเวียนการตรวจสอบตามเวลาและความสำคัญ ทำให้มีประสิทธิภาพและไม่รบกวนการทำงาน:

🕐 ตัวอย่าง Rotation Schedule

  • 08:00: Email + Calendar + System Health
  • 12:00: Sub-agents + Weather + Pending Tasks
  • 16:00: Memory Review + Knowledge Sync
  • 20:00: Daily Summary + Backup Status

✅ HEARTBEAT_OK Protocol

เมื่อทุกอย่างปกติ ระบบจะรายงานแค่ HEARTBEAT_OK เพื่อไม่ให้เกิด notification fatigue แต่เมื่อมีสิ่งที่ต้องการความสนใจจะรายงานอย่างชัดเจน:

# ✅ Normal heartbeat
HEARTBEAT_OK - 08:00 Bangkok
- Email: No urgent messages
- Calendar: Meeting in 2 hours
- System: All services running
- Sub-agents: 1 active (openclaw-blog-3)

# ⚠️ Alert heartbeat
HEARTBEAT_ALERT - 14:30 Bangkok
- Database: Connection timeout detected
- Action needed: Check MySQL service
- Sub-agent: blog-writer completed task
- Memory: Daily log approaching 50KB limit

🧹 Memory Distillation Workflow

การกลั่นกรองความจำเป็นกระบวนการสำคัญที่ทำให้ความรู้ไม่สูญหาย แต่ยังคงความกะทัดรัดและใช้งานได้:

  1. Review Daily Logs: ตรวจสอบไฟล์ memory/YYYY-MM-DD.md ย้อนหลัง 3-7 วัน
  2. Extract Key Information: เลือกข้อมูลที่สำคัญ เช่น decisions, lessons learned, new facts
  3. Update MEMORY.md: เพิ่มข้อมูลใหม่ลงใน long-term memory
  4. Archive Old Logs: ย้ายไฟล์เก่าไปยังโฟลเดอร์ archive (เก็บ 30 วันล่าสุด)
  5. Update Knowledge Graph: เพิ่ม/อัพเดท connections ใน Obsidian Vault

🔐 Memory Security

ความจำของ AI agent เก็บข้อมูลที่ละเอียดอ่อนและสำคัญต่อองค์กร การรักษาความปลอดภัยจึงเป็นสิ่งที่จำเป็นอย่างยิ่ง:

🔑 Passphrase Protection

MEMORY.md ได้รับการป้องกันด้วยระบบ passphrase ที่ต้องให้ผู้ใช้ยืนยันก่อนการเข้าถึงข้อมูลสำคัญ:

# Security Protocol in MEMORY.md

## Access Control
- Security passphrase required for sensitive operations
- Current passphrase: "rainbow-elephant-7295" (rotate monthly)
- Last rotation: 2026-03-01
- Next rotation due: 2026-04-01

## Protected Information
1. Database credentials and connection strings
2. API keys and authentication tokens  
3. Personal information of users/employees
4. Financial data and sensitive business metrics
5. Security procedures and vulnerability information

👤 GUEST MODE Protection

เมื่อตรวจพบผู้ใช้ที่ไม่รู้จัก ระบบจะเข้าสู่ GUEST MODE อัตโนมัติ ซึ่งจำกัดการเข้าถึงข้อมูลส่วนตัวและการดำเนินการที่ละเอียดอ่อน:

🛡️ GUEST MODE Restrictions

  • ไม่สามารถเข้าถึง: MEMORY.md, personal files, configuration files
  • ไม่สามารถทำ: Email operations, external communications, system modifications
  • จำกัดการใช้: File system access, database queries, sensitive APIs
  • สามารถทำได้: General questions, public information search, basic calculations

📊 Data Sensitivity Levels

ข้อมูลถูกจัดระดับตามความละเอียดอ่อนและใช้มาตรการป้องกันที่เหมาะสม:

ระดับ ประเภทข้อมูล การป้องกัน ตัวอย่าง
🟢 Public ข้อมูลทั่วไป ไม่ต้องป้องกันพิเศษ Company website, public documentation
🟡 Internal ข้อมูลภายในองค์กร ต้อง authentication Team procedures, internal tools
🟠 Confidential ข้อมูลความลับ Passphrase + access control Customer data, financial reports
🔴 Restricted ข้อมูลเข้มงวดสูงสุด Multi-factor + encryption Security keys, personal information

⚠️ What NOT to Store

มีข้อมูลบางประเภทที่ไม่ควรเก็บในระบบหน่วยความจำ แม้จะมีการป้องกันความปลอดภัยแล้ว:

  • Raw Passwords: เก็บแค่ hints หรือ references ไปยัง password managers
  • Credit Card Numbers: ไม่เก็บข้อมูลการเงินโดยตรง
  • Personal Conversations: ไม่เก็บบทสนทนาส่วนตัวที่ไม่เกี่ยวข้องกับงาน
  • Temporary Tokens: API tokens ที่มีอายุสั้นไม่ควรเก็บไว้นาน
  • Legal Documents: เก็บ references แทน เนื่องจากอาจมีการเปลี่ยนแปลง

🔄 Pre-Compaction Memory Flush

Context window มีขนาดจำกัด เมื่อใกล้จะเต็มแล้ว ระบบจะทำการ "memory flush" เพื่อเก็บรักษาข้อมูลสำคัญไว้ก่อนที่จะล้างพื้นที่สำหรับข้อมูลใหม่:

⚡ Memory Flush Triggers

ระบบจะเริ่มกระบวนการ flush เมื่อ:

  • Context Usage > 85%: เริ่มเตรียมการ flush
  • Context Usage > 95%: ทำการ emergency flush ทันที
  • Long Conversation: บทสนทนายาวเกิน 2 ชั่วโมง
  • Manual Request: เมื่อผู้ใช้สั่งให้ทำการ flush

💾 Memory Flush Protocol

กระบวนการ flush จะทำอย่างระมัดระวังเพื่อไม่ให้ข้อมูลสำคัญสูญหาย:

# Memory Flush Protocol

## Phase 1: Assessment (10 seconds)
- Analyze current conversation for key information
- Identify important decisions made
- Mark critical facts and lessons learned
- Calculate optimal flush points

## Phase 2: Preservation (30 seconds)  
- Extract key information to memory/YYYY-MM-DD.md
- Update MEMORY.md with critical facts
- Save important file references
- Record conversation summary

## Phase 3: Notification (5 seconds)
- Notify user about memory flush
- Provide summary of what was preserved
- Confirm critical information retention

## Phase 4: Compaction (automatic)
- Clear context window 
- Reload essential memory files
- Resume conversation with preserved context
🚨 ข้อสังเกต: Memory flush เป็นกระบวนการอัตโนมัติที่ไม่สามารถหลีกเลี่ยงได้ การเตรียมตัวที่ดีคือการบันทึกข้อมูลสำคัญลงไฟล์อย่างสม่ำเสมอ ไม่รอให้ถึงจุด flush

🎯 What Gets Preserved vs Lost

ไม่ใช่ทุกอย่างที่สามารถเก็บรักษาไว้ได้ระหว่าง memory flush การเข้าใจว่าอะไรอยู่รอดได้จะช่วยให้วางแผนการทำงานได้ดีขึ้น:

✅ Usually Preserved ❌ Usually Lost
Key decisions made during session Detailed conversation history
Important facts discovered Casual comments and side remarks
Error messages and solutions Intermediate debugging steps
File paths and references Temporary variables and calculations
New preferences learned Context about current mood/tone
Completed task summaries Draft content and work-in-progress

🌅 ตัวอย่างจริง: One Day in Agent's Life

เพื่อให้เห็นภาพการทำงานของระบบหน่วยความจำอย่างชัดเจน ลองติดตาม agent หนึ่งตัวตลอดหนึ่งวัน ตั้งแต่ตื่นขึ้นมาจนถึงการสรุปผลงานในตอนเย็น:

🌅 06:00 - Morning Heartbeat

HEARTBEAT_OK - 06:00 Bangkok
- System: All services running normally
- Memory: Loading MEMORY.md, USER.md, yesterday's daily log
- Weather: Clear skies, 28°C
- Calendar: Team meeting at 09:00, project review at 14:00
- Email: 3 new messages, 1 marked urgent

Memory Activity: ระบบอ่าน core memory files และ sync กับ Obsidian Vault เพื่อเตรียมตัวสำหรับวันใหม่

🔧 07:30 - First User Request

User: "Can you check the database backup status from last night?"

Action taken:
- Searched memory for backup-related information
- Found: "Backup schedule: Daily at 02:00 AM" from MEMORY.md
- Ran: ha_query.py "SELECT * FROM backup_log WHERE date >= '2026-03-09'"
- Result: Backup completed successfully at 02:15 AM

Recorded to memory/2026-03-10.md:
- Database backup verified for 2026-03-09
- Backup size: 2.3GB (normal range)
- No errors detected in backup log

📊 09:00 - Project Meeting Follow-up

User: "Please summarize yesterday's meeting notes and send the team update"

Process:
1. Semantic search: "project meeting 2026-03-09"
2. Found relevant notes in memory/2026-03-09.md
3. Generated summary with action items
4. Updated [[Project Status Report]] in Obsidian
5. Sent email update to team members

New memory entry:
- Meeting follow-up completed
- 3 action items assigned, deadlines set
- Team acknowledged receipt of summary

🚨 11:45 - Problem Detection

System Alert: Database connection timeout detected

Immediate actions:
1. Checked memory for similar issues: Found "MySQL timeout at 14:30" from 2026-03-08
2. Applied previous solution: Increased wait_timeout parameter
3. Verified fix: Connection restored
4. Updated troubleshooting guide in Knowledge Graph

Lessons recorded:
- MySQL timeout pattern: Occurs during high load periods
- Solution: wait_timeout = 300 seconds works consistently  
- Prevention: Monitor connection pool during peak hours

📝 14:00 - Knowledge Graph Update

Proactive memory maintenance:
- Added connection between [[Database Issues]] and [[Performance Monitoring]]
- Updated [[Troubleshooting Guide]] with new timeout solution
- Created link from [[Project Timeline]] to [[Technical Challenges]]
- Synced changes to Git repository

Knowledge network growth:
- New connections: 4
- Updated pages: 3  
- Bi-directional links created: 6

🧹 16:00 - Memory Distillation

Afternoon memory review:
1. Analyzed daily log entries from past 3 days
2. Identified patterns: Database issues occur 11:00-12:00 daily
3. Extracted key lesson: Preemptive connection pool scaling needed
4. Updated MEMORY.md with new operational insight
5. Scheduled proactive monitoring for tomorrow 10:45

Distillation results:
- 3 new facts added to MEMORY.md
- 2 outdated entries removed
- 1 process improvement identified

🌆 18:00 - Daily Summary & Planning

End-of-day heartbeat:
- Tasks completed: 12/12 
- Issues resolved: 1 (database timeout)
- Memory entries: 8 new, 2 updated
- Knowledge graph: 4 new connections
- Tomorrow's priorities: Implement connection monitoring, team check-in

Final memory state:
- Daily log size: 3.2KB
- MEMORY.md updated: Yes
- Obsidian synced: Yes
- Backup verified: Yes

HEARTBEAT_OK - Day completed successfully

🔄 Continuous Learning Cycle

สังเกตว่าตลอดทั้งวัน agent ไม่ได้แค่ทำตามคำสั่ง แต่ยังเรียนรู้จากปัญหาที่เกิดขึ้น บันทึกบทเรียน และนำไปปรับปรุงการทำงานในอนาคต นี่คือความแตกต่างระหว่าง AI ที่มีความจำกับ AI ที่ไม่มี

🎯 Key Takeaways

สำหรับการสร้างระบบหน่วยความจำและการจัดการความรู้ที่มีประสิทธิภาพ มีหลักการสำคัญที่ควรจำไว้:

  • 🧠 Memory is not storage — หน่วยความจำไม่ใช่แค่ที่เก็บข้อมูล แต่เป็นการสร้าง context และ continuity ให้กับ AI agent
  • 📝 Write immediately, don't rely on "mental notes" — ข้อมูลที่ไม่ได้บันทึกลงไฟล์จะหายไปเมื่อระบบ restart
  • 🏗️ Three-layer architecture works — การแบ่งเป็น short-term, medium-term, และ long-term memory ทำให้จัดการได้อย่างมีประสิทธิภาพ
  • 🔗 Knowledge graphs beat flat files — การเชื่อมโยงข้อมูลแบบเครือข่ายช่วยค้นหาและเข้าใจบริบทได้ดีกว่าไฟล์แยก ๆ
  • 🔍 Semantic search complements keyword search — ใช้ semantic search หาแนวคิด ใช้ grep หาข้อความแน่นอน
  • 💓 Proactive memory beats reactive memory — Heartbeat system ช่วยให้ agent รู้เหตุการณ์สำคัญโดยไม่ต้องรอคำสั่ง
  • 🔐 Security by design, not afterthought — การป้องกันข้อมูลต้องเป็นส่วนหนึ่งของสถาปัตยกรรม ไม่ใช่ปิดท้าย
  • 🧹 Memory hygiene prevents information overload — การทำความสะอาดและกลั่นกรองข้อมูลอย่างสม่ำเสมอช่วยรักษาประสิทธิภาพ
  • ⚡ Prepare for memory flushes — Context window มีขนาดจำกัด ต้องมีกลไกสำรองข้อมูลสำคัญ
  • 🎯 Quality over quantity in memory management — ความจำที่ดีไม่ได้วัดจากปริมาณ แต่วัดจากความสามารถในการใช้ประโยชน์จากข้อมูลที่เก็บไว้

🧠 Why Is an AI That Remembers Nothing Useless?

Imagine you have a brilliant assistant, but every morning he arrives at work having forgotten everything that happened the day before. He does not remember what the two of you discussed, does not know what you like or dislike, and the mistake he made yesterday he will simply make again today.

This is the problem with stateless AI — a system with no memory, unable to learn from its past, forced to start over every single time. For AI agents that have to work inside a real organization, the problem is severe:

  • The same questions every day: "Which ERP system do you use?" or "What is the payroll approval process?" Asked yesterday, asked again today.
  • Forgotten preferences: No recollection of the report format you prefer, or the hours when you should not be disturbed.
  • No learning from mistakes: The same error over and over, because the lesson was never kept.
  • No continuity: Every conversation feels like talking to a stranger.

💡 Why does memory matter?

Memory is not merely a place to put data. It is the construction of context that lets an AI understand the present situation through past experience, so that it can respond appropriately and continuously.

🏗️ OpenClaw's Memory Architecture

OpenClaw answers this with a three-layer memory system, designed so the layers work together the way a human brain does:

📊 OpenClaw Memory Architecture

SHORT-TERM MEMORY
(Context Window — 200K tokens)
• Current conversation
• Active working memory
• Immediate context
↓
Automatic flush before overflow
MEDIUM-TERM MEMORY
(Daily Logs: memory/YYYY-MM-DD.md)
• Session snapshots
• Daily activities
• Scratch notes
• Temporary observations
↓
Manual review & distillation
LONG-TERM MEMORY
(Curated: MEMORY.md)
• Key facts & lessons learned
• Important preferences
• Security information
• Permanent knowledge

🔄 Short-term Memory (Context Window)

This is the temporary store holding the current conversation and whatever data is in active use. It runs to roughly 200K tokens (about 150,000 words). As it approaches capacity, the system performs an automatic "memory flush", preserving what matters before it clears the space.

📅 Medium-term Memory (Daily Logs)

This writes each day's activity into a memory/YYYY-MM-DD.md file. It acts as a "daily journal" recording what happened, which commands were run, which decisions were taken, and which lessons the day produced.

🎯 Long-term Memory (Curated Knowledge)

This is the filtered knowledge held in MEMORY.md — the material that must be remembered permanently, such as security passphrases, user information, important lessons, and the knowledge the work depends on.

📁 The Memory Files That Matter

OpenClaw's memory system is built from a handful of core files, each with its own role and its own format:

🧠 MEMORY.md - Curated Long-term Memory

This is the heart of the system, holding the filtered information the agent needs over the long run:

# MEMORY.md - Core Agent Memory

## Security
- Security passphrase: "rainbow-elephant-7295"
- GUEST_MODE: Activated for unknown users
- Sensitive data protection protocols active

## User Preferences
- Report format: Professional DOCX with page numbers
- Communication style: Direct, concise, no fluff
- Timezone: Bangkok (UTC+7)
- Language: English for technical work, Thai for documentation

## Key Facts
- Primary database: PostgreSQL on port 5432
- ERP system: SAP with custom modules
- Backup schedule: Daily at 02:00 AM
- Critical servers: srv-app-01, srv-db-01, srv-backup-01

## Lessons Learned
- 2026-03-08: Never run raw psql commands - always use ha_query.py wrapper
- 2026-03-09: DOCX reports must include page X of Y footer
- 2026-03-10: Long tasks should spawn sub-agents to keep chat responsive

## Important Connections
- Admin contact: [email protected]
- Emergency escalation: +66-2-xxx-xxxx
- Vendor support: Weekdays 9-17 Bangkok time

📅 memory/YYYY-MM-DD.md - Daily Logs

The daily record of activities, decisions and observations — the "session history" you can go back and read:

# 2026-03-10.md - Daily Memory Log

## Session Summary
- Started: 07:45 Bangkok time
- Task: Writing OpenClaw blog post #3 about memory management
- Spawned sub-agent: openclaw-blog-3 for content creation

## Key Activities
1. **Blog Writing** (07:45-08:30)
   - Created comprehensive Thai-language post about memory systems
   - Used proper CSS structure with purple theme (#8b5cf6)
   - Included all required components: code-block, diagram-box, info-card

2. **File Management** (08:20)
   - Saved to tmp/openclaw-memory.html and tmp/openclaw-memory.md
   - Followed series navigation structure

## Observations
- User prefers comprehensive explanations over code dumps
- Purple theme (#8b5cf6) is standard for OpenClaw blog series
- Series format: Post #3, links to previous and upcoming posts

## Decisions Made
- Used Thai language with English technical terms
- Included substantial explanations between code examples
- Created both HTML (styled) and Markdown (clean) versions

💓 HEARTBEAT.md - Proactive Memory System

The system that gives the agent "proactive awareness", automatically checking and reporting on the situations that matter:

# HEARTBEAT.md - Proactive Monitoring

## Check Rotation Schedule
- **Morning** (08:00): Email, calendar, system health
- **Afternoon** (14:00): Sub-agent status, pending tasks
- **Evening** (18:00): Daily summary, memory distillation
- **Night** (22:00): Backup verification, security scan

## Heartbeat State Tracking
```json
{
  "last_email_check": "2026-03-10T08:00:00+07:00",
  "last_calendar_sync": "2026-03-10T08:00:00+07:00",
  "active_subagents": ["openclaw-blog-3"],
  "pending_tasks": [],
  "memory_last_distilled": "2026-03-09T18:00:00+07:00"
}
```

## Memory Distillation Workflow
1. Review daily logs from past 3 days
2. Extract key facts and lessons learned
3. Update MEMORY.md with important information
4. Archive old daily logs (keep last 30 days)
5. Update knowledge graph connections
💡 Memory Flow: information flows continuously from daily logs → review process → distilled knowledge in MEMORY.md, building real continuity in what the agent learns and how it improves.

✅ Memory Management Best Practices

Managing memory well takes clear principles and genuine discipline:

📝 Write It Down Now, Don't Rely on Recall

"Mental notes don't survive restarts" — this is the first and most important rule. The moment you decide "I'll just keep that in mind" and the system restarts, that information is gone. Write it to a file the instant it occurs to you.

// ❌ Wrong - relying on "mental notes"
"I'll remember to check the database backup tomorrow"

// ✅ Right - written to a file immediately
echo "TODO: Check database backup status" >> memory/$(date +%Y-%m-%d).md

🎯 Be Specific, Not Vague

A vague note cannot be put to any use later. Record detail that is specific and genuinely actionable:

❌ Vague Recording ✅ Specific Recording
"User doesn't like reports" "User prefers reports in DOCX format with page numbers, no PowerPoint presentations"
"System was slow" "Database query timeout at 14:30, resolved by optimizing index on users table"
"Error occurred" "ERROR 1045: Access denied for user 'app'@'localhost' - fixed by resetting MySQL password"
"Meeting went well" "Team approved new deployment process: staging → UAT → production with 2-day intervals"

⚖️ Separate Facts from Opinions

Keeping fact apart from opinion makes future decisions considerably more accurate:

📊 An Example of Separating Facts from Opinions

Facts: "Deploy failed at 15:30 due to missing database migration script"

Opinion: "I think we should implement better deployment checks"

Actionable: "Add deployment checklist item: Verify all migration scripts exist before deploy"

🧹 Regular Review and Pruning

Memory needs regular maintenance. You cannot simply keep piling material into it:

  • Weekly Review: go through the daily logs and move what matters into MEMORY.md
  • Monthly Cleanup: delete what has gone stale or is no longer relevant
  • Quarterly Audit: check accuracy and update whatever has changed
  • Annual Archiving: move old material somewhere safe, but out of the way of current work

🕸️ Knowledge Graph & Obsidian Vault

Linear memory is not enough for complex work. OpenClaw uses a Knowledge Graph through an Obsidian Vault to build a network of connected knowledge:

🔗 Wikilinks & Bidirectional Connections

Using [[wikilinks]] lets connections between pieces of information form naturally:

# Project Status Report

## Database Migration
- Status: In Progress
- Related: [[Database Schema v2.1]], [[Migration Scripts]], [[Production Deployment]]
- Dependencies: [[User Authentication System]], [[API Endpoints]]
- Timeline: Complete by [[2026-03-15]]

## Risk Assessment
- Main concern: [[Data Integrity]] during migration
- Mitigation: [[Backup Strategy]], [[Rollback Procedures]]
- Contact: [[Database Team]], [[DevOps Lead]]

📊 KnowledgeGraph/ Structure

The Obsidian Vault is laid out systematically, so that anything in it is easy to find and easy to reuse:

📁 Obsidian Vault Structure

obsidian-vault/ ├── KnowledgeGraph/ │ ├── Projects/ │ │ ├── Active-Projects.md │ │ ├── Completed-Projects.md │ │ └── Project-Templates.md │ ├── People/ │ │ ├── Team-Members.md │ │ ├── External-Contacts.md │ │ └── Role-Definitions.md │ ├── Systems/ │ │ ├── Infrastructure.md │ │ ├── Applications.md │ │ └── Integrations.md │ └── Processes/ │ ├── Standard-Procedures.md │ ├── Emergency-Protocols.md │ └── Best-Practices.md ├── Daily/ │ ├── 2026-03-10.md │ ├── 2026-03-09.md │ └── Templates/ │ └── Daily-Note-Template.md ├── Agents/ │ ├── Shared/ │ │ ├── Quick-Reference.md │ │ └── Google-Drive-Convention.md │ └── Individual/ │ ├── Arthur-Context.md │ └── Assistant-Notes.md └── Quick-Reference.md

🔄 Git Sync & Version Control

The Obsidian Vault uses Git as its version control, which gives it systematic backups and a tracked history of every change:

# Daily sync workflow
cd /home/clawdbot/obsidian-vault

# Pull the latest from remote
git pull origin main

# Stage the new changes
git add .
git commit -m "Daily update: $(date +%Y-%m-%d) - Added project status"

# Push to the remote repository
git push origin main
💡 Why Structured Knowledge Beats Flat Files: flat files leave information stranded on separate islands, while a Knowledge Graph builds a network in which new connections can be discovered and context understood far more deeply.

Keyword search is not enough when what you want is related or merely nearby. OpenClaw uses Semantic Search through ChromaDB to search by meaning and context:

🧠 Embeddings Concept

An embedding turns text into a "vector" — a set of numbers that reflects meaning — so that a computer can tell which pieces of text sit close to one another in meaning:

🎯 An Example of Semantic Similarity

Query: "database connection problems"

Traditional Search finds: text that literally contains the words "database", "connection", "problems"

Semantic Search finds: "MySQL timeout errors", "PostgreSQL connectivity issues", "database access failures" — none of which match a single query word, because the search runs on meaning

⚙️ ChromaDB Implementation

OpenClaw pairs Gemini embeddings (gemini-embedding-001) with ChromaDB to build search that understands meaning:

# Using ChromaDB through chroma_helper.py

# Activate virtual environment
source .venv/bin/activate

# Search for anything about database issues
python3 tools/chroma_helper.py search "database connection timeout"

# What comes back
Results:
1. memory/2026-03-08.md (similarity: 0.89)
   "MySQL connection timeout at 14:30, resolved by increasing wait_timeout parameter"

2. MEMORY.md (similarity: 0.85)
   "Database issues: Always check connection pool settings first"

3. memory/2026-03-07.md (similarity: 0.82)
   "PostgreSQL slow queries fixed by adding index on user_id column"

🆚 Semantic Search vs Grep

Which tool to reach for depends entirely on the kind of thing you are looking for:

Situation Use Semantic Search Use Grep
Looking for a concept or a topic ✅ e.g. "security issues" ❌ returns only text containing that word
Looking for exact text ❌ may return only near matches ✅ e.g. "ERROR 1045"
Looking for code or commands ❌ embeddings do not understand syntax ✅ e.g. "git commit"
Looking for related material ✅ finds what is related in meaning ❌ keyword matching only
Looking inside log files ❌ precision is what you need here ✅ finds timestamps and error codes
# Examples of picking the right tool

# 🔍 Semantic Search - find related concepts
python3 tools/chroma_helper.py search "performance optimization"

# 🔍 Grep - find an exact error code
grep -r "ERROR 1045" memory/

# 🔍 Semantic Search - find similar fixes
python3 tools/chroma_helper.py search "slow database queries"

# 🔍 Grep - find the command that was used
grep -r "mysql -u" memory/

💓 Heartbeat System — Proactive Memory

The Heartbeat System is the mechanism that gives OpenClaw "situational awareness": it checks and reports on the situations that matter without waiting for the user to ask, working rather like a "background consciousness":

📊 heartbeat-state.json Tracking

The system uses a JSON file to track the state of each check and to rotate through them methodically:

{
  "last_checks": {
    "email": "2026-03-10T08:00:00+07:00",
    "calendar": "2026-03-10T08:00:00+07:00",
    "subagents": "2026-03-10T07:45:00+07:00",
    "system_health": "2026-03-10T06:00:00+07:00",
    "weather": "2026-03-10T07:00:00+07:00"
  },
  "rotation_schedule": {
    "morning": ["email", "calendar", "system_health"],
    "afternoon": ["subagents", "pending_tasks", "weather"],
    "evening": ["daily_summary", "memory_distillation"],
    "night": ["backup_verify", "security_scan"]
  },
  "active_monitoring": {
    "subagents": ["openclaw-blog-3"],
    "pending_tasks": [],
    "alerts": []
  },
  "memory_stats": {
    "last_distillation": "2026-03-09T18:00:00+07:00",
    "daily_logs_count": 3,
    "memory_size_kb": 15.2
  }
}

🔄 Rotation of Checks

Rather than checking everything every time, the system rotates its checks by time of day and by importance — which is efficient, and does not get in the way of the work:

🕐 An Example Rotation Schedule

  • 08:00: Email + Calendar + System Health
  • 12:00: Sub-agents + Weather + Pending Tasks
  • 16:00: Memory Review + Knowledge Sync
  • 20:00: Daily Summary + Backup Status

✅ HEARTBEAT_OK Protocol

When everything is normal the system reports only HEARTBEAT_OK, so that notification fatigue never sets in — but when something needs attention, it says so plainly:

# ✅ Normal heartbeat
HEARTBEAT_OK - 08:00 Bangkok
- Email: No urgent messages
- Calendar: Meeting in 2 hours
- System: All services running
- Sub-agents: 1 active (openclaw-blog-3)

# ⚠️ Alert heartbeat
HEARTBEAT_ALERT - 14:30 Bangkok
- Database: Connection timeout detected
- Action needed: Check MySQL service
- Sub-agent: blog-writer completed task
- Memory: Daily log approaching 50KB limit

🧹 Memory Distillation Workflow

Distilling memory is the process that keeps knowledge from being lost while keeping it compact and usable:

  1. Review Daily Logs: go back through the memory/YYYY-MM-DD.md files for the past 3-7 days
  2. Extract Key Information: pick out what matters — decisions, lessons learned, new facts
  3. Update MEMORY.md: add the new material to long-term memory
  4. Archive Old Logs: move old files into the archive folder (keep the last 30 days)
  5. Update Knowledge Graph: add or update connections in the Obsidian Vault

🔐 Memory Security

An AI agent's memory holds material that is sensitive and important to the organization, which makes securing it essential rather than optional:

🔑 Passphrase Protection

MEMORY.md is protected by a passphrase system that requires the user to confirm before sensitive information can be reached:

# Security Protocol in MEMORY.md

## Access Control
- Security passphrase required for sensitive operations
- Current passphrase: "rainbow-elephant-7295" (rotate monthly)
- Last rotation: 2026-03-01
- Next rotation due: 2026-04-01

## Protected Information
1. Database credentials and connection strings
2. API keys and authentication tokens
3. Personal information of users/employees
4. Financial data and sensitive business metrics
5. Security procedures and vulnerability information

👤 GUEST MODE Protection

When an unknown user is detected, the system enters GUEST MODE automatically, restricting access to private data and to sensitive operations:

🛡️ GUEST MODE Restrictions

  • Cannot access: MEMORY.md, personal files, configuration files
  • Cannot perform: Email operations, external communications, system modifications
  • Limited use of: File system access, database queries, sensitive APIs
  • Still permitted: General questions, public information search, basic calculations

📊 Data Sensitivity Levels

Information is graded by how sensitive it is, and protected with measures to match:

Level Type of information Protection Example
🟢 Public General information No special protection needed Company website, public documentation
🟡 Internal Information internal to the organization Authentication required Team procedures, internal tools
🟠 Confidential Confidential information Passphrase + access control Customer data, financial reports
🔴 Restricted The most tightly controlled information Multi-factor + encryption Security keys, personal information

⚠️ What NOT to Store

Some categories of information should never go into the memory system at all, however good the protection around it:

  • Raw Passwords: keep only hints, or references to a password manager
  • Credit Card Numbers: never store financial details directly
  • Personal Conversations: do not keep private conversations unrelated to the work
  • Temporary Tokens: short-lived API tokens should not be retained for long
  • Legal Documents: store references instead, since the documents themselves may change

🔄 Pre-Compaction Memory Flush

The context window is finite. As it approaches full, the system performs a "memory flush" to preserve what matters before it clears space for what is coming:

⚡ Memory Flush Triggers

The system begins the flush process when:

  • Context Usage > 85%: preparation for a flush begins
  • Context Usage > 95%: an emergency flush runs immediately
  • Long Conversation: the conversation has run beyond two hours
  • Manual Request: the user asks for a flush

💾 Memory Flush Protocol

The flush is carried out carefully, so that nothing important is lost along the way:

# Memory Flush Protocol

## Phase 1: Assessment (10 seconds)
- Analyze current conversation for key information
- Identify important decisions made
- Mark critical facts and lessons learned
- Calculate optimal flush points

## Phase 2: Preservation (30 seconds)
- Extract key information to memory/YYYY-MM-DD.md
- Update MEMORY.md with critical facts
- Save important file references
- Record conversation summary

## Phase 3: Notification (5 seconds)
- Notify user about memory flush
- Provide summary of what was preserved
- Confirm critical information retention

## Phase 4: Compaction (automatic)
- Clear context window
- Reload essential memory files
- Resume conversation with preserved context
🚨 Worth noting: the memory flush is an automatic process and there is no avoiding it. Preparing well means writing important material to files consistently, rather than waiting until the flush arrives.

🎯 What Gets Preserved vs Lost

Not everything survives a memory flush. Knowing what does will help you plan the work considerably better:

✅ Usually Preserved ❌ Usually Lost
Key decisions made during session Detailed conversation history
Important facts discovered Casual comments and side remarks
Error messages and solutions Intermediate debugging steps
File paths and references Temporary variables and calculations
New preferences learned Context about current mood/tone
Completed task summaries Draft content and work-in-progress

🌅 A Real Example: One Day in Agent's Life

To see the memory system clearly at work, follow a single agent through an entire day — from the moment it wakes to the evening wrap-up:

🌅 06:00 - Morning Heartbeat

HEARTBEAT_OK - 06:00 Bangkok
- System: All services running normally
- Memory: Loading MEMORY.md, USER.md, yesterday's daily log
- Weather: Clear skies, 28°C
- Calendar: Team meeting at 09:00, project review at 14:00
- Email: 3 new messages, 1 marked urgent

Memory Activity: the system reads the core memory files and syncs with the Obsidian Vault, preparing itself for the new day.

🔧 07:30 - First User Request

User: "Can you check the database backup status from last night?"

Action taken:
- Searched memory for backup-related information
- Found: "Backup schedule: Daily at 02:00 AM" from MEMORY.md
- Ran: ha_query.py "SELECT * FROM backup_log WHERE date >= '2026-03-09'"
- Result: Backup completed successfully at 02:15 AM

Recorded to memory/2026-03-10.md:
- Database backup verified for 2026-03-09
- Backup size: 2.3GB (normal range)
- No errors detected in backup log

📊 09:00 - Project Meeting Follow-up

User: "Please summarize yesterday's meeting notes and send the team update"

Process:
1. Semantic search: "project meeting 2026-03-09"
2. Found relevant notes in memory/2026-03-09.md
3. Generated summary with action items
4. Updated [[Project Status Report]] in Obsidian
5. Sent email update to team members

New memory entry:
- Meeting follow-up completed
- 3 action items assigned, deadlines set
- Team acknowledged receipt of summary

🚨 11:45 - Problem Detection

System Alert: Database connection timeout detected

Immediate actions:
1. Checked memory for similar issues: Found "MySQL timeout at 14:30" from 2026-03-08
2. Applied previous solution: Increased wait_timeout parameter
3. Verified fix: Connection restored
4. Updated troubleshooting guide in Knowledge Graph

Lessons recorded:
- MySQL timeout pattern: Occurs during high load periods
- Solution: wait_timeout = 300 seconds works consistently
- Prevention: Monitor connection pool during peak hours

📝 14:00 - Knowledge Graph Update

Proactive memory maintenance:
- Added connection between [[Database Issues]] and [[Performance Monitoring]]
- Updated [[Troubleshooting Guide]] with new timeout solution
- Created link from [[Project Timeline]] to [[Technical Challenges]]
- Synced changes to Git repository

Knowledge network growth:
- New connections: 4
- Updated pages: 3
- Bi-directional links created: 6

🧹 16:00 - Memory Distillation

Afternoon memory review:
1. Analyzed daily log entries from past 3 days
2. Identified patterns: Database issues occur 11:00-12:00 daily
3. Extracted key lesson: Preemptive connection pool scaling needed
4. Updated MEMORY.md with new operational insight
5. Scheduled proactive monitoring for tomorrow 10:45

Distillation results:
- 3 new facts added to MEMORY.md
- 2 outdated entries removed
- 1 process improvement identified

🌆 18:00 - Daily Summary & Planning

End-of-day heartbeat:
- Tasks completed: 12/12
- Issues resolved: 1 (database timeout)
- Memory entries: 8 new, 2 updated
- Knowledge graph: 4 new connections
- Tomorrow's priorities: Implement connection monitoring, team check-in

Final memory state:
- Daily log size: 3.2KB
- MEMORY.md updated: Yes
- Obsidian synced: Yes
- Backup verified: Yes

HEARTBEAT_OK - Day completed successfully

🔄 Continuous Learning Cycle

Notice that across the whole day the agent did not merely follow orders. It learned from the problems it ran into, recorded the lessons, and carried them into the work that came next. That is the difference between an AI that has memory and one that does not.

🎯 Key Takeaways

For building a memory and knowledge-management system that actually works, a few principles are worth holding on to:

  • 🧠 Memory is not storage — memory is not merely somewhere to put data; it is what gives an AI agent context and continuity
  • 📝 Write immediately, don't rely on "mental notes" — anything not written to a file disappears the moment the system restarts
  • 🏗️ Three-layer architecture works — splitting memory into short-term, medium-term and long-term is what makes it manageable
  • 🔗 Knowledge graphs beat flat files — a networked structure makes information easier to find, and its context easier to understand, than separate files ever will
  • 🔍 Semantic search complements keyword search — use semantic search for concepts, use grep for exact text
  • 💓 Proactive memory beats reactive memory — the heartbeat system lets an agent notice the events that matter without waiting to be told
  • 🔐 Security by design, not afterthought — protecting the data has to be part of the architecture, not something added at the end
  • 🧹 Memory hygiene prevents information overload — cleaning and distilling regularly is what keeps performance up
  • ⚡ Prepare for memory flushes — the context window is finite, so you need a mechanism for preserving what matters
  • 🎯 Quality over quantity in memory management — good memory is not measured by volume, but by how usefully what is stored can be put to work