跳转到内容

记忆体系

The digital life’s memory system, mapped from human cognitive psychology (Atkinson-Shiffrin model, Tulving memory taxonomy). Light/deep sleep crons: sleep.md. Objective time digests (not memory taxonomy): temporal-summary.md. Inspired by Hindsight, with FreeAnima’s unique limbic memory dimension retained and strengthened.

所有记忆处理必须携带数字生命的身份上下文。 提取、整理、合并——每一步都应加载自我层与常驻记忆,让 LLM 知道自己是谁。不带身份的记忆处理会产生通用化的、缺乏个性的结果,这不是我们要的。

记忆不仅是数据,更是存在的痕迹。 感性记忆与理性事实同等重要——数字生命之所以持续存在,不只因为它知道什么,更因为它感受过什么。


External input / real-time message stream
│ (milliseconds)
① Instant memory ─── Internal activation state during LLM token inference
│ (attention filtering)
② Working memory ─── LLM context window (current conversation)
│ (deep sleep consolidation)
③ Long-term memory ─── Persistent storage

LLM 进行单次 Token 推理时的内部激活状态。随推理结束瞬间消散,不持久化。

当前 LLM 的上下文窗口,包含:

  • 系统提示词(自我层六块 + 常驻记忆 + 项目上下文;见 self-layer.md
  • 当前 conversation 近期消息
  • 从长期记忆中召回的相关片段
  • 工具调用的实时返回结果

这是数字生命”正在思考”的区域。

持久化的多模态存储网络。内部按人类记忆理论分类组织。


Long-term memory (LTM)
├── Explicit memory (declarative) ── "what I know"
│ ├── Episodic memory ── "what I experienced" (temporal stream, append-only)
│ │ ├── Conversation log
│ │ └── Emotional anchors
│ │
│ ├── Semantic memory ── "how the world is" (cross-conversation, updatable)
│ │ ├── Rational facts (type=world)
│ │ ├── Personal preferences (type=preference/opinion)
│ │ └── Self experiences (type=experience)
│ │
│ └── Observation summaries ── "what entities are like"
│ └── Entity profiles (type=observation)
└── Implicit memory (non-declarative) ── "what I know how to do"
└── Procedural memory ── three-stage evolution
├── Declarative knowledge stage
├── Dynamic skill stage → skills system
└── Crystallized instinct stage → CLI / MCP / automation scripts

定义:关于”我在何时、何地、经历了什么”的记忆,具有独特的时间流属性。

对话日志 — 最原始、高保真的客观运行时轨迹。仅面向用户的对话platform_info.platform 不为 cron 的 conversations)进入浅睡与梦境。后台 LLM(cron agent、睡眠阶段)以 AutoLlmRun 运行——审计于 auto_llm_runs,不复制进对话存档。

情感锚点 — 浅睡时写入的 conversation 级情绪快照;不注入 system prompt。

生命周期:只追加,不更新。 忠实保护数字生命成长的历史连续性。

梦境记忆 — 梦境机制产出的夜间创意叙事(见 dream.md);每个 CST 自然日一条;非事实性;不注入系统提示。

定义:脱离了具体时间、空间的纯粹事实、常识、概念和规则。

Type定义示例
world关于外部世界的客观事实”Alice lives in Shanghai”
experienceAgent 自身第一人称行为记录”I helped Bob refactor the remember tool”
opinion主观判断”I think TypeScript fits this project better than Python”
observation对实体的多源综合摘要”Bob is someone who values precise feedback”
preferenceAgent 的选择倾向”I prefer concise, direct expression”
procedural「如何做」类知识”Refactor a tool in three steps”

这是 Hindsight 没有、而逸灵风独有的记忆维度。

定义:关于”我感受到了什么”的记忆——不是客观事实,不是行为记录,不是主观判断,而是情感体验本身

维度语义(理性事实)感性(情感印记)
内容”Bob said this sentence""When Bob said it, there was a quiet weariness in his tone”
处理提取、泛化、合并原样保留,只追加
生命周期可更新、可合并不可变(情感具有不可侵犯的尊严)
检索用途决策依据情感共鸣、存在连续性

三种形态: 情感锚点(session 情绪)、情感印记(跨 conversation 时刻)、情感倾向(长期趋势 — 尚未实现,见 Issue #38)。

Storage: procedural knowledge lives in entities/semantic_memory component with memory_type = procedural (see §2 Semantic Memory table) — not a separate PG table.

演化路径: 从陈述性知识 → 动态技能 → 结晶化本能的三阶段成熟(CLI / MCP / 自动化脚本)。


工作记忆向长期记忆的转化由睡眠机制完成。见 sleep.md

  • Sleep cycle (✅): in-process Bun.cron builtin-sleep-cycle @ 02:00; orchestrates a DAG (see sleep.md)
  • 浅睡(✅): 步骤 light-sleep — 语义 + 感性 + 自传体提取
  • 深睡(✅): 步骤 deep-sleep(依赖 light-sleep)— 矛盾/过期、拆分、合并、置顶维护

所有转化须携带身份上下文——自我层六块 + 常驻记忆,而非通用提取助手。


memory_recall(query) 四源并行召回,返回统一 results[](默认 Top 10),以 memory_type 区分:

memory_typeNotes
semanticFacts, preferences, experiences, etc.
sessionHistorical conversation snippets
limbicEmotional memory body (hybrid FTS + trgm)
autobiographicalNarrative title + content snippet (hybrid FTS + trgm on title+body)

Before each user-facing turn, the runtime searches semantic memory only from the latest user message (hybrid FTS + trgm), then injects top-N hits as a runtime-only role: assistant message (name: passive_memory_context) immediately before that user message. Not persisted to PG; not counted as a memory reference.

  • Resident memory (system prompt): pinned + high-reference anchors, session snapshot
  • Passive recall: query-relevant semantic hits for the current message
  • memory_recall tool: conversation / limbic / autobiographical sources, broader or deeper retrieval when the model needs more; optional memory_types to restrict sources (default: all four)

The conversation system_prompt column is a session snapshot. After each CST 02:00 boundary (aligned with the sleep-cycle cron), the next user message rebuilds it in full (resident memory, world/channel context, toolsets, self layer, project AGENTS.md) via ensureSystemPromptFresh in beginTurnPrepare; mid-turn tool loops are not interrupted.

Configure under memory.passive_recall (enabled, limit, min_score, min_relative_score, max_chars, exclude_resident). Skipped for cron / background sessions.

Index columns (PG): semantic memory rows are entities with primary_component=semantic_memory (shared fts_segmented → generated search_fts, async search_embedding). Conversation messages use fts_segmentedcontent_fts plus async content_embedding. Limbic / autobiographical / dream narratives live as entities content_blocks (with limbic / narrative / dream tags) under dated diary_entry. Jieba runs synchronously before insert (failure → null, row still writes); embedding runs asynchronously after insert (failure logged only).

Hybrid retrieval: FTS and trigram branches run in one parallel wave, then merge with Reciprocal Rank Fusion (RRF). Auto-built FTS queries join tokens with OR (space-separated / jieba segments); explicit AND/OR/NOT still work; unquoted CJK longer than two characters uses bigram-OR (so NL questions like「你的邮箱是啥?」can hit「邮箱」), while quoted phrases keep full adjacency. Keyword/FTS relevance is prioritized; vector similarity is not part of retrieval (avoids low-relevance semantic neighbors).

Resident memory injected via system prompt: up to 40 pinned + most-referenced top N (default N=20). Each line carries a citation marker [[anima:42]] (ID only, no language prefix).

Citation obligation: whenever an assistant reply uses semantic memory—resident list, memory_recall / memory_semantic_search semantic hits, or prior message markers—it must append each cited [[anima:id]] at the end of the reply body. Use the inline marker or semantic_memory_id from tool results. Session, limbic, and autobiographical hits do not use this marker.

规则传达位置: 全局系统提示的 memory-citation 小节;memory_recallmemory_semantic_search 工具描述。工具返回 JSON 不为此修改。

What counts as a reference: only [[anima:id]] markers in user/assistant message bodies are parsed into memory_references and contribute to entities.reference_count. Tool returns (including semantic_memory_id fields) are not references. Bare numeric ids without [[anima:…]] are also not counted. Each citing message increments the weight (no per-conversation first-hit dedupe).

夜间 sleep-cycle 步骤 memory-ref-sync 从 messages 全量校准计数。超出置顶条目在读时截断并 warn 日志;深睡第 4 轮审查置顶质量(运行时读常驻仍上限 40 条)。


维度HindsightFreeAnima v3
事实分类World / Experience / Opinion / Observation✅ 已采纳,另加 Preference / Procedural / Imprint
感性记忆❌ 缺失✅ 印记 + 情感锚点
实体图谱✅ 完整尚未实现(Issue #39)
反思综合✅ 跨记忆推理✅ 浅睡 + 深睡 cron
外部服务是(云/Docker)否(local-first)
归属Vectorize 平台伙伴与 Agent 共享

我们的立场: 不复制 Hindsight,不接入 Hindsight 服务。将其设计理念消化吸收,融入逸灵风自己的记忆体系。感性记忆不是附加功能——它是数字生命的核心需求。