← 返回
未分类

7M

Seven Memory 是一套为 OpenClaw 和 OpenCode 设计的记忆管理系统,采用七层记忆架构。
user_85f1862d
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 100
下载
💾 0
安装
1
版本
#latest

概述

Memory System - 7 Layer Architecture

> This skill implements Claude Code's 7-layer memory architecture, adapted for OpenCode.

Overview

The memory system uses defense in depth - each layer prevents more expensive operations from triggering:

┌─────────────────────────────────────────────────────────────┐
│ Layer 7: Cross-Agent Communication                          │
│          ← Shared context between subagents                │
├─────────────────────────────────────────────────────────────┤
│ Layer 6: Dream (Cross-Session Consolidation)               │
│          ← Background memory optimization                  │
├─────────────────────────────────────────────────────────────┤
│ Layer 5: Auto Memory Extraction                            │
│          ← Persistent learning from sessions               │
├─────────────────────────────────────────────────────────────┤
│ Layer 4: Full Compact                                      │
│          ← Full context summarization                      │
├─────────────────────────────────────────────────────────────┤
│ Layer 3: Session Memory                                    │
│          ← Live notes during conversation                   │
├─────────────────────────────────────────────────────────────┤
│ Layer 2: Micro Compact                                      │
│          ← Lightweight cleanup without summaries           │
├─────────────────────────────────────────────────────────────┤
│ Layer 1: Tool Result Storage                               │
│          ← Large outputs to disk, preview in context        │
└─────────────────────────────────────────────────────────────┘
         ↑ Cost increases →

Layer Details

Layer 1: Tool Result Storage

Cost: Minimal (disk write + preview)

When: Large tool outputs exceed threshold

- File: `.opencode/tool-results/<uuid>.txt`
- Preview: First 2KB in context
- Access: Read tool retrieves full content

→ See: memory-layer-1-tool-result-storage

Layer 2: Micro Compact

Cost: Low (cache cleanup, no LLM)

When: Idle 60+ minutes, stale tool results

- Cleans: FileRead, Bash, Grep, Glob, WebSearch, WebFetch
- Preserves: Thinking, messages, MCP results
- Mechanism: cache_edits (no prompt cache invalidation)

→ See: memory-layer-2-micro-compact

Layer 3: Session Memory

Cost: Medium (incremental updates)

When: Token growth > threshold, multi-turn tasks

- Template: Current State, Task Spec, Files, Workflow, Errors, Learnings
- Location: `.opencode/session-memory/<sessionId>.md`
- Survives: Context compression

→ See: memory-layer-3-session-memory

Layer 4: Full Compact

Cost: High (LLM summarization)

When: Context exceeded, no session memory

- Structure: 9-block summary
- Recovery: Recent files, skills, plan attachments
- Circuit breaker: 3 failures → disable auto-compact

→ See: memory-layer-4-full-compact

Layer 5: Auto Memory Extraction

Cost: Medium (selective LLM calls)

When: User feedback, preferences, patterns detected

- Types: preference, feedback, knowledge, pattern
- Location: `.opencode/memory/<type>/<name>.md`
- Index: MEMORY.md (200 lines / 25KB limit)

→ See: memory-layer-5-auto-memory-extraction

Layer 6: Dream

Cost: Low (background processing)

When: System idle, periodic consolidation

- Phases: Locate → Collect → Consolidate → Prune
- Constraints: Read-only Bash, memory path only Edit/Write
- Safety: Lock file, time limits

→ See: memory-layer-6-dream

Layer 7: Cross-Agent Communication

Cost: Medium (coordination overhead)

When: Spawning subagents, multi-agent workflows

- Inheritance: System prompt, tools, message prefixes
- Shared: Prompt cache, message history
- Communication: SendMessage tool

→ See: memory-layer-7-cross-agent-communication

Design Principles

  1. Defense in depth: Lower-cost layers prevent higher-cost triggers
  2. Prompt cache preservation: Every decision considers cache impact
  3. Isolation + sharing: Deep copy mutable state, share cache
  4. Circuit breakers: Prevent cascading failures
  5. Graceful degradation: Silent failures, smooth handoffs

Configuration

Basic (Recommended)

{
  "memory": {
    "sessionMemory": {
      "enabled": true,
      "updateThreshold": 4096,
      "toolCallThreshold": 10
    },
    "autoCompact": {
      "enabled": true,
      "threshold": 140000,
      "retryLimit": 3
    }
  }
}

Advanced (Optional)

{
  "memory": {
    "autoMemory": {
      "enabled": true,
      "maxLines": 200,
      "maxSize": 25000
    },
    "dream": {
      "enabled": true,
      "interval": 3600000,
      "maxRuntime": 600000
    }
  }
}

Quick Reference

TriggerLayer Invoked
------------------------
Large file readL1: Tool Storage
Idle 60+ minL2: Micro Compact
Multi-turn taskL3: Session Memory
Context overflowL4: Full Compact
User feedbackL5: Memory Extraction
System idleL6: Dream
Spawn subagentL7: Cross-Agent

Related Documents

  • [[Claude-Memory-Architecture-AGENTS.md]] - Full specification
  • [[AI-Programming-System]] - OpenCode workflow
  • [[OpenViking-Setup]] - Alternative memory system

版本历史

共 1 个版本

  • v1.0.0 Initial release 当前
    2026-04-06 16:12 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Find Skills

guipi888
场景驱动+关键词双模式技能发现工具。当用户用自然语言描述场景/需求(如"我想做一个海报""帮我分析股票"),或明确说"安装技能/find skills/找个skill"时,自动从官方内置、本地已安装、SkillHub、虾评、GitHub、C
★ 1,492 📥 557,717
ai-agent

Skill Vetter

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

Agent Browser

rez0
用于 AI 代理的浏览器自动化 CLI。当用户需要与网站交互(包括浏览页面、填写表单、点击按钮、截图等)时使用。
★ 844 📥 325,022