← 返回
未分类 中文

Context Persistence

Solve cross-session context storage and sync problems. Use when (1) isolated sessions (cron/subagent/heartbeat) lack context from main session, (2) long-runn...
解决跨会话上下文存储与同步问题。使用场景包括:(1)独立会话(cron/子代理/心跳)缺少主会话上下文;(2)长时间运行...
lgy2020
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 564
下载
💾 1
安装
1
版本
#beta#latest

概述

Context Persistence & Cross-Session Sync

Design and implement persistent context systems that survive session boundaries.

Core Problem

OpenClaw has multiple session types with different context access:

SessionMemory FilesHistoryCron Context
--------------------------------------------
Main DM✅ All injected✅ FullN/A
Group Chat❌ Not loaded✅ PartialN/A
Cron (isolated)❌ None❌ None✅ Payload only
Heartbeat❌ None✅ PartialN/A
Subagent❌ None❌ None✅ Task only

Result: State created in one session is invisible to others unless persisted to files.

Architecture: Three-Layer Memory System

Layer 1: Long-Term Memory (MEMORY.md)

  • What: Curated facts, decisions, lessons, key state
  • Who writes: Main session only
  • Who reads: Main session only (injected via AGENTS.md)
  • Update frequency: On significant events, periodic review during heartbeats
  • Size limit: < 200 lines (context budget)

Layer 2: Daily Logs (memory/YYYY-MM-DD.md)

  • What: Raw chronological notes, conversations, decisions
  • Who writes: Any session that has something to record
  • Who reads: Main session (at startup), heartbeats (for review)
  • Update frequency: Real-time as events happen
  • Size limit: Unbounded (not injected into context)

Layer 3: Task Progress Files (memory/-progress.md)

  • What: Structured progress for long-running work
  • Who writes: Any session doing the task
  • Who reads: Any session continuing the task
  • Update frequency: At task boundaries (session end, checkpoints)
  • Size limit: < 300 lines

The Key Insight

> Files are the only cross-session communication channel.

> In-memory state dies with the session. Files survive.

Pattern 1: Progress Tracking

For tasks spanning multiple sessions (source code reading, data analysis, etc.)

See references/progress-tracking.md for full template.

Essential elements:

# <Task> Progress
- Total: X items
- Completed: Y items  
- Progress: Z%
## Completed List (dedup)
## Current Position / Next Steps
## Key Findings

Pattern 2: Cron Job Context Injection

Isolated cron sessions have NO access to workspace memory. Solutions:

  1. Embed context in payload message (for <1KB state)
  2. Read from progress files (task loads its own context)
  3. Shared state file (coordination between sessions)

See references/cross-session-sync.md for patterns.

Pattern 3: Main Session Initialization

The AGENTS.md startup sequence ensures context loading:

1. Read SOUL.md (persona)
2. Read USER.md (who you help)
3. Read memory/YYYY-MM-DD.md (today + yesterday)
4. If main session: also read MEMORY.md

This is the ONLY automated context loading. Everything else must be explicit.

Quick Checklist

When designing context for a new task:

  • [ ] Can this span multiple sessions? → Create progress file
  • [ ] Does cron/subagent need this? → Embed in payload or file
  • [ ] Is this a fact to remember? → Update MEMORY.md
  • [ ] Is this a raw event? → Append to daily log
  • [ ] Should future sessions know this? → Write it DOWN, never rely on memory

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-30 06:48 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,222 📥 267,260
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 672 📥 324,893
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,370 📥 319,593