← Starchild Wiki

Starchild Agent Memory: A Self-Maintaining Layered Knowledge SystemStarchild Agent Memory:一个自维护的分层知识系统

Three storage tiers — Rules, Wiki, Raw — with write gating and periodic maintenance forming a fully automated knowledge loopRules · Wiki · Raw 三层存储,写入门控与每周维护构成全自动知识闭环

Starchild Engineering · 2026 · SQLite FTS5 / ChromaDB / Markdown Wiki · zero new dependencies零新增依赖

1Overview概述

The core tension for a long-running agent is a bounded context window against an ever-growing body of experience. This system partitions agent memory into three storage tiers — always-resident rules (Rules), a structured knowledge base (Wiki), and raw session records (Raw) — each with a strict injection budget governing its share of the LLM context. Every write passes through a gate (deduplication, supersession, conflict detection); the knowledge base is maintained by periodic lint passes; and raw records are distilled daily back into the wiki, forming a knowledge loop that requires no manual curation.长期运行的 Agent 面临的核心矛盾是:上下文窗口有限,而经验持续累积。本系统将 Agent 记忆划分为三个存储层——常驻规则(Rules)、结构化知识库(Wiki)、原始会话记录(Raw)——并以严格的注入预算控制每层进入 LLM 上下文的份额。知识的写入经过门控(去重、取代、冲突检测),知识库本身由周期性 lint 维护,原始记录经每日蒸馏回流知识库,形成不依赖人工整理的知识闭环。

2System Architecture系统架构

The three tiers have orthogonal roles: Rules are injected unconditionally, Wiki is recalled on demand, and Raw serves only as material for search and distillation — it is never injected directly.三个存储层职责正交:Rules 无条件常驻,Wiki 按需召回,Raw 仅作检索与蒸馏的原料,从不直接注入。

WRITE PATHS In-session writes会话内即时写入 topic save / patch Idle-time capture空闲期沉淀 idle flush · 30 min Daily distillation每日蒸馏 distill · last 7 daysdistill · 近 7 日会话 Write gate写入门控 dedup · supersede · conflict去重 · 取代 · 冲突 WIKI — structured knowledgeWIKI — 结构化知识库 topic = summary + detail + history namespaced · global machine-readable indexnamespace 组织 · 全局机器可读索引 state machine: active / pinned / stale /状态机 active / pinned / stale / superseded / archived / conflict weekly lint: dedup · contradiction · archive每周 lint:查重 · 矛盾检测 · 归档 capacity cap 100 topics容量上限 100 topics Periodic maintenance周期性维护 piggyback triggeredpiggyback 触发 rules first, LLM fallback规则先行,LLM 兜底 RULES — always-residentRULES — 常驻规则层 identity · user prefs · hard lessons · index身份 · 用户偏好 · 硬性教训 · 知识索引 injected every turn, budget ≈13 KB + 2 KB每轮无条件注入,预算 ≈13 KB + 2 KB RAW — session recordsRAW — 原始会话层 SQLite + FTS5 full-text, hundreds of sessionsSQLite + FTS5 全文检索,数百 session never injected; sole input to distillation从不直接注入;蒸馏管道的唯一原料 distill back蒸馏回流 index sync ≤1 s索引同步 ≤1 s LLM ContextLLM 上下文 rules ≈13 KB index ≤2 KB recall ≤6 KB knowledge share 5–10% hybrid recall混合召回 semantic+keyword+recency+pin语义+关键词+时近+置顶 full-text search, on demand全文检索,按需

Figure 1图 1System architecture. Left: three write paths pass through a unified gate into the Wiki; center: the three storage tiers; right: three budgeted channels into the LLM context.系统架构。左:三条写入路径经统一门控进入 Wiki;中:三个存储层;右:进入 LLM 上下文的三条预算通道。

3Knowledge Lifecycle知识生命周期

Every piece of knowledge passes through five stages; the outputs of maintenance and distillation are written back into the wiki and join the next recall round — knowledge compounds.每条知识经历五个阶段;维护与蒸馏的产物回写知识库,参与下一轮召回,实现知识复利。

Write写入 three paths: live /即时 / 空闲 / 蒸馏 idle / distilled三条路径 unified gate: dedup,统一门控:去重、 supersede, conflict-hold取代、冲突挂起 Index索引 global index rebuilt写入后 ≤1 s 重建 ≤1 s after write全局索引 directory injected into目录注入 prompt: prompt: visible = retrievable可见方可检索 Recall召回 semantic + keyword +语义 + 关键词 + recency + activity + pin时近 + 活跃 + 置顶 invalidated entries demoted;失效条目降权; per-turn budget ≤6 KB每轮预算 ≤6 KB Maintain维护 weekly lint: dedup,每周 lint:查重、 contradiction, archive矛盾检测、归档 conflicts never auto-overwrite:矛盾不自动覆盖, proposals await ruling呈现提案待裁决 Distill蒸馏 daily scan of raw sessions;每日扫描原始会话 extract decisions, lessons提取决策与教训 distilled sessions marked,已蒸馏标记, never reprocessed不重复处理 maintenance & distillation outputs flow back → index updates → next recall round维护与蒸馏产物回写知识库 → 更新索引 → 参与下一轮召回

Figure 2图 2Knowledge lifecycle: the Write → Index → Recall → Maintain → Distill loop.知识生命周期:写入 → 索引 → 召回 → 维护 → 蒸馏的闭环。

4File & Storage Layout文件与存储布局

Everything lives inside the agent workspace as plain text and SQLite files — directly reviewable, version-controllable, no external services.全部落在 Agent 工作区内的纯文本与 SQLite 文件,可直接审阅、可版本化、无外部服务。

workspace/
├── prompt/                        # RULES tier — resident, injected every turn
│   ├── SOUL.md                    # persona & hard rules
│   ├── IDENTITY.md                # agent identity
│   └── USER.md                    # user settings & preferences
├── MEMORY.md                      # distilled facts & lessons (≤3000 chars)
├── memory/
│   ├── topics/                    # WIKI tier — structured knowledge base
│   │   ├── _index.json            # global index (auto-maintained, ≤2 KB injected)
│   │   └── {namespace}/{slug}/
│   │       ├── summary.md         # summary ≤1000 chars — the recall unit
│   │       ├── detail.md          # detail ≤8000 chars — read on demand
│   │       ├── history.jsonl      # append-only change history
│   │       └── meta.json          # state / timestamps / reference counts
│   ├── proposals/                 # conflict & merge proposals awaiting user ruling
│   └── metrics.jsonl              # observability: injection share, recall hits
└── .starchild/
    ├── sessions.db                # RAW tier — SQLite + FTS5 full-text index
    └── chroma/                    # vector index (topic-summary level)workspace/
├── prompt/                        # RULES 层 — 每轮常驻注入
│   ├── SOUL.md                    # 人格与硬性规则
│   ├── IDENTITY.md                # Agent 身份
│   └── USER.md                    # 用户设定与偏好
├── MEMORY.md                      # 精炼事实与教训(≤3000 字符)
├── memory/
│   ├── topics/                    # WIKI 层 — 结构化知识库
│   │   ├── _index.json            # 全局索引(自动维护,≤2 KB 注入)
│   │   └── {namespace}/{slug}/
│   │       ├── summary.md         # 摘要 ≤1000 字符 — 召回单元
│   │       ├── detail.md          # 详情 ≤8000 字符 — 按需读取
│   │       ├── history.jsonl      # 追加式变更历史
│   │       └── meta.json          # 状态 / 时间戳 / 引用计数
│   ├── proposals/                 # 矛盾与合并提案,待用户裁决
│   └── metrics.jsonl              # 可观测性:注入占比、召回命中
└── .starchild/
    ├── sessions.db                # RAW 层 — SQLite + FTS5 全文索引
    └── chroma/                    # 向量索引(topic summary 级)

Figure 3图 3Storage layout. Summary/detail separation controls injection cost; append-only history keeps everything auditable.存储布局。摘要与详情分离控制注入成本;历史追加保证可审计。

5Design Principles设计原则

Principle原则Implementation实现
Injection is budgeted注入有预算Resident ≈13 KB, index ≤2 KB, recall ≤6 KB; knowledge tokens capped at 5–10% of total input — over budget means trimming, never accumulation常驻 ≈13 KB、索引 ≤2 KB、召回 ≤6 KB;知识 token 占总输入 5–10%,超限即裁剪而非累积
Writes are gated写入有门控All write paths pass one gate: semantic dedup, explicit supersession of stale knowledge, same-key conflicts resolved via unique IDs所有写入路径经统一门控:语义去重、旧知识显式取代(supersede)、同键冲突以唯一 ID 消解
Conflicts never auto-overwrite矛盾不自动覆盖Mutually exclusive knowledge is kept on both sides, marked conflict, and surfaced as a proposal for the user to rule on — stale knowledge is more dangerous than no knowledge检测到互斥知识时双方保留并标记 conflict,生成提案交用户裁决——过期知识比没有知识更危险
Index before retrieval索引先于检索The model must know something exists before it can retrieve it; the global index is rebuilt ≤1 s after every write and injected into the prompt模型必须先"知道存在"才能检索;全局索引在每次写入后 ≤1 s 内重建并注入
Raw records stay out of context原始记录不注入The Raw tier serves only full-text search and distillation; all knowledge in context comes from the gated Rules / Wiki tiersRaw 层只服务全文检索与蒸馏;上下文中的知识一律来自受控的 Rules / Wiki 层
Maintenance is zero-resident维护零常驻Periodic jobs piggyback on normal wakeups with lazy due-checks — compatible with host auto-suspend, no daemon required周期任务借正常唤醒触发(piggyback),懒惰到期检查,兼容宿主机自动休眠
Observable可观测Injection share, recall hit rate, topic growth, and invalidation ratio are continuously written to metrics — preventing silent degradation注入占比、召回命中、topic 增长与失效比例持续写入 metrics,防止系统静默退化

6Key Parameters关键参数

Parameter参数Value取值Notes说明
topics.max100knowledge-base capacity cap; overflow triggers archival知识库容量上限,超限触发归档
summary / detail≤1000 / ≤8000 charssummary is the recall unit; detail is read on demand摘要为召回单元,详情按需读取
index / recall budget≤2 KB / ≤6 KBhard per-turn injection caps每轮注入硬上限
idle flush30 mincapture window after a session goes idle会话空闲后的沉淀窗口
distill window7 d, dailyraw-session distillation range原始会话蒸馏范围
lint interval7 dknowledge-base maintenance cycle知识库维护周期
stale threshold90 d unaccessed未访问demoted in recall and queued for archival降权并候选归档
dedup thresholdcos > 0.92semantic-duplicate merge threshold语义查重合并阈值

7References参考文献

  1. AI Never Sleeps. I Gave Claude Code a Brain That Never Forgets. Here's Exactly How. Substack, 2026. — the core Rules/Wiki/Raw three-tier model and wiki lint.Rules/Wiki/Raw 三层与 wiki lint 的核心模型。
  2. Agentic AI Foundation. Karpathy's LLM Wiki as Agent Memory.the wiki layer with index.md / log.md; Ingest / Query / Lint as the three primitive operations.wiki 层的 index.md / log.md 设计;Ingest / Query / Lint 三原语。
  3. Karpathy, A. Discussions on LLM knowledge bases and token budgets关于 LLM 知识库与 token 预算的讨论, X (Twitter), 2026. — the task-token vs knowledge-token budget split.task tokens 与 knowledge tokens 的预算划分。
  4. mem0. The State of Agent Wikis. X (long-form article), 2026. — the industry convergence on "markdown wiki + periodic lint"; declarative memory entries stating facts rather than imperative instructions.业界收敛于 "markdown wiki + 周期 lint";记忆条目陈述事实而非祈使指令。