- doc/heart.md: emotional system design (motivation, reflection, relationship memory) - Auto-reflection: every 10 messages, async LLM call updates inner_state with feelings and understanding changes (not conversation summary) - Life Loop emotional motivation: "you care, not because timer fired" - Remove all instance-specific names from code/docs — persona, name, memories are instance data (SQLite), not code - Rewrite doc/life.md and doc/todo.md for instance isolation principle
2.4 KiB
2.4 KiB
Life Loop 设计
核心理念
noc 不只是一个对话机器人。对话是它跟用户交流的窗口,但 Life Loop 才是它"活着"的地方。
双循环架构
Chat Loop (被动) Life Loop (主动)
收到消息 → 处理 → 回复 每 30 秒醒来 → 检查 timers
context: context:
persona persona
inner_state (只读) inner_state (读写)
对话历史 + scratch timer payload
memory_slots 无对话历史
tools (全量) tools (全量)
┌─── SQLite (共享状态层) ───┐
│ inner_state │
│ timers │
│ conversations/messages │
│ memory_slots / scratch │
│ config │
└───────────────────────────┘
状态层级
| 层级 | 存储 | 生命周期 | 用途 |
|---|---|---|---|
| persona | config 表 | 永久 | 定义 bot 是谁 |
| inner_state | inner_state 表 | 永久,LLM 自更新 | bot 对当前情况的感知 |
| memory_slots | memory_slots 表 | 永久,LLM 管理 | 跨会话的关键事实/偏好/关系 |
| summary | conversations 表 | 按 session | 长对话的压缩记忆 |
| scratch | scratch_area 表 | session 内 | 当前任务的工作笔记 |
Timer 系统
调度格式
- 相对时间:
5min,2h,30s,1d - 绝对时间:
once:2026-04-10 09:00 - 周期性:
cron:0 8 * * *(标准 cron 表达式)
触发流程
- Life Loop tick(30 秒)
- 扫描 timers 表,找到 next_fire <= now 的
- 构建 LLM 请求:persona + inner_state + 当前时间 + 情感动机
- 调用 LLM(带全量工具)
- 发送回复到 chat(或选择沉默)
- cron 类型自动重新调度,一次性的删除
自动反思
每 10 条消息后,异步触发一次反思 LLM 调用:
- 输入:当前 inner_state
- 输出:更新后的 inner_state
- 不阻塞对话,不发消息给用户
- 让 bot 持续更新对自己和用户的理解
实例隔离
代码仓库不包含实例特定数据。每个 noc 实例的"灵魂"(名字、人格、记忆、情感状态)全部在 SQLite 里。同一份代码可以运行多个独立实例。