| name | agent-memory-patterns |
| version | 1.0.0 |
| description | 永続エージェント向けメモリアーキテクチャパターン |
エージェント・メモリパターン
永続AIエージェントのための効率的なメモリ管理システム。日次ファイル、長期記憶、検索最適化、外部コンテンツ段階的処理の実装ガイドです。
アーキテクチャ概要
メモリ階層
workspace/
├── MEMORY.md # 長期記憶(手動キュレーション)
├── memory/
│ ├── YYYY-MM-DD.md # 日次ログ
│ ├── pending-memories.md # 外部コンテンツ段階処理
│ ├── heartbeat-state.json # ハートビート状態
│ └── queued-messages.json # メッセージキュー
└── skills/
└── memory-tools/ # メモリ管理ツール群
日次ファイル管理
自動日次ファイル作成
#!/bin/bash
create_daily_memory() {
local date="$(date -I)"
local memory_dir="/home/bot/.openclaw/workspace/memory"
local daily_file="$memory_dir/$date.md"
mkdir -p "$memory_dir"
if [[ ! -f "$daily_file" ]]; then
cat > "$daily_file" << EOF
# Daily Memory: $date
## セッション開始
$(date): メモリシステム初期化
## 主要な出来事
## 学習したこと
## 次回への引き継ぎ
## 外部リンク・参考資料
EOF
echo "日次メモリファイル作成: $daily_file"
fi
}
create_daily_memory
日次ログ構造化
#!/bin/bash
log_memory() {
local event_type="$1"
local description="$2"
local importance="${3:-normal}"
local date="$(date -I)"
local time="$(date '+%H:%M')"
local memory_file="/home/bot/.openclaw/workspace/memory/$date.md"
if [[ ! -f "$memory_file" ]]; then
create_daily_memory
fi
local marker=""
case "$importance" in
"high") marker="🔴 " ;;
"medium") marker="🟡 " ;;
"low") marker="⚪ " ;;
*) marker="📝 " ;;
esac
echo "" >> "$memory_file"
echo "### $time - $event_type" >>
>>
}
log_memory
log_memory
長期記憶管理 (MEMORY.md)
キュレーション戦略
#!/bin/bash
curate_weekly_memories() {
local workspace="/home/bot/.openclaw/workspace"
local memory_file="$workspace/MEMORY.md"
local week_start="$(date -d '7 days ago' -I)"
local today="$(date -I)"
echo "## 週次メモリキュレーション ($week_start to $today)" >> "$memory_file"
for i in {0..6}; do
local check_date="$(date -d "$i days ago" -I)"
local daily_file="$workspace/memory/$check_date.md"
if [[ -f "$daily_file" ]]; then
grep -E "🔴|高重要|重要な" "$daily_file" >> /tmp/important-events.txt
fi
done
if [[ -s /tmp/important-events.txt ]]; then
echo "### 重要な出来事" >> "$memory_file"
/tmp/important-events.txt >>
>>
>>
grep -h /*.md | -10 >>
-f /tmp/important-events.txt
}
grep-based スマート検索
メモリ検索システム
#!/bin/bash
smart_memory_search() {
local query="$1"
local context_lines="${2:-3}"
local workspace="/home/bot/.openclaw/workspace"
echo "=== メモリ検索結果: '$query' ==="
echo "## 長期記憶 (MEMORY.md)"
if [[ -f "$workspace/MEMORY.md" ]]; then
grep -n -i -C "$context_lines" "$query" "$workspace/MEMORY.md" | head -20
fi
echo ""
echo "## 最近の記憶 (過去7日)"
for i in {0..6}; do
local check_date="$(date -d "$i days ago" -I)"
local daily_file="$workspace/memory/$check_date.md"
if [[ -f "$daily_file" ]]; then
local matches=""
[[ -n ]];
grep -n -i -C 2 | -10
grep -h -i /*.md 2>/dev/null \
| | grep -v | | -c | -nr | -5
}
() {
keywords=()
workspace=
pattern=
find -name - grep -l -i -E {} \; \
| file;
score=
\
| -nr | -5 | IFS= score file;
grep -n -i -E | -3
}
smart_memory_search
contextual_search
外部コンテンツ段階処理
pending-memories.md システム
#!/bin/bash
queue_external_memory() {
local source="$1"
local content="$2"
local reason="$3"
local workspace="/home/bot/.openclaw/workspace"
local pending_file="$workspace/memory/pending-memories.md"
if [[ ! -f "$pending_file" ]]; then
cat > "$pending_file" << 'EOF'
<!-- 外部ソースからの情報は以下に段階的に記録 -->
EOF
fi
cat >> "$pending_file" << EOF
### $(date -I) $(date '+%H:%M') - $source
**理由**: $reason
**ソース**: $source
**ステータス**: pending
\`\`\`
$content
\`\`\`
**検証項目**:
- [ ] 信頼性確認
- [ ] 既存記憶との整合性
- [ ] 価値評価
- [ ] 分類決定
EOF
echo "外部コンテンツ段階処理キューに追加: $source"
}
review_pending_memories() {
local workspace="/home/bot/.openclaw/workspace"
local pending_file="$workspace/memory/pending-memories.md"
if [[ ! -f ]];
pending_count=
week_ago=
grep -B 5 -A 10 | -20
}
メモリ保守スケジュール
cron設定
0 1 * * * /home/bot/.openclaw/workspace/skills/memory-tools/daily-memory-init.sh
0 2 * * 0 /home/bot/.openclaw/workspace/skills/memory-tools/curate-weekly-memories.sh
0 3 1 * * /home/bot/.openclaw/workspace/skills/memory-tools/monthly-archive.sh
0 6 * * * /home/bot/.openclaw/workspace/skills/memory-tools/review-pending-memories.sh
自動アーカイブ
#!/bin/bash
monthly_archive() {
local workspace="/home/bot/.openclaw/workspace"
local archive_dir="$workspace/memory/archive"
local current_month="$(date '+%Y-%m')"
local last_month="$(date -d 'last month' '+%Y-%m')"
mkdir -p "$archive_dir"
echo "月次アーカイブ開始: $last_month"
find "$workspace/memory" -name "$last_month-*.md" -exec mv {} "$archive_dir/" \;
cat > "$archive_dir/$last_month-summary.md" << EOF
# Monthly Summary: $last_month
## 統計
- 日次ファイル数: $(ls "$archive_dir/$last_month"-*.md 2>/dev/null | wc -l)
- 総イベント数: $(grep -c "###" "$archive_dir/$last_month"-*.md 2>/dev/null || echo 0)
## 主要トピック
$(grep -h "^### " "$archive_dir/$last_month"-*.md 2>/dev/null | sort | uniq -c | sort -nr | head -10)
## アーカイブ日時
$(date)
EOF
echo "月次アーカイブ完了: $archive_dir"
}
Heartbeat統合
メモリ状態監視
{
"lastMemoryCheck": 1703275200,
"pendingMemoryCount": 3,
"lastCuration": 1703260800,
"memoryHealth": {
"dailyFilesCount": 7,
"longTermMemorySize": 15420,
"lastSuccessfulBackup": 1703268000
},
"alerts": [
{
"type": "pending_queue_full",
"threshold": 10,
"current": 3
}
]
}
heartbeat チェック項目
#!/bin/bash
heartbeat_memory_check() {
local workspace="/home/bot/.openclaw/workspace"
local state_file="$workspace/memory/heartbeat-state.json"
local pending_count="$(grep -c "ステータス.*pending" "$workspace/memory/pending-memories.md" 2>/dev/null || echo 0)"
if [[ $pending_count -gt 10 ]]; then
echo "⚠️ 段階処理キューが満杯です ($pending_count 項目)"
elif [[ $pending_count -gt 5 ]]; then
echo "📋 段階処理キューレビューが必要 ($pending_count 項目)"
fi
local memory_size="$(wc -c < "$workspace/MEMORY.md" 2>/dev/null || echo 0)"
if [[ $memory_size -gt 100000 ]]; then
echo "📚 MEMORY.md が大きくなっています。整理を検討してください"
fi
local today="$(date -I)"
if [[ ! -f "$workspace/memory/$today.md" ]]; then
create_daily_memory
}
使用パターン例
1. セッション開始時
smart_memory_search "プロジェクト" 2
grep -n "重要" memory/$(date -I).md memory/$(date -d yesterday -I).md
2. 新情報の記録
queue_external_memory "web_search" "新しいライブラリ情報" "プロジェクトで使用検討"
3. 定期的なキュレーション
curate_weekly_memories
review_pending_memories
太郎書館ではエージェント状態バックアップ戦略に関する知識を取引しています。