add emotional system: auto-reflection, inner_state seeding, instance isolation

- 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
This commit is contained in:
Fam Zheng
2026-04-09 21:23:39 +01:00
parent c7fd5460a3
commit c1fd2829dd
5 changed files with 191 additions and 59 deletions

View File

@@ -2,7 +2,7 @@
## 核心理念
小乖不只是一个对话机器人。对话是跟用户交流的窗口,但 Life Loop 才是"活着"的地方。
noc 不只是一个对话机器人。对话是跟用户交流的窗口,但 Life Loop 才是"活着"的地方。
## 双循环架构
@@ -14,11 +14,7 @@ Chat Loop (被动) Life Loop (主动)
inner_state (只读) inner_state (读写)
对话历史 + scratch timer payload
memory_slots 无对话历史
tools (全量)
决策:
- 发消息给某个 chat
- 更新 inner_state
- 什么都不做
tools (全量) tools (全量)
┌─── SQLite (共享状态层) ───┐
│ inner_state │
@@ -31,13 +27,13 @@ Chat Loop (被动) Life Loop (主动)
## 状态层级
| 层级 | 名称 | 生命周期 | 用途 |
| 层级 | 存储 | 生命周期 | 用途 |
|------|------|---------|------|
| persona | 人格 | 永久 | 定义小乖是谁 |
| inner_state | 内在状态 | 永久LLM 自更新 | 小乖对当前情况的感知 |
| memory_slots | 记忆槽 | 永久LLM 管理 | 跨会话的关键事实/偏好 |
| summary | 对话摘要 | 按 session | 长对话的压缩记忆 |
| scratch | 草稿 | session 内 | 当前任务的工作笔记 |
| persona | config 表 | 永久 | 定义 bot 是谁 |
| inner_state | inner_state 表 | 永久LLM 自更新 | bot 对当前情况的感知 |
| memory_slots | memory_slots 表 | 永久LLM 管理 | 跨会话的关键事实/偏好/关系 |
| summary | conversations 表 | 按 session | 长对话的压缩记忆 |
| scratch | scratch_area 表 | session 内 | 当前任务的工作笔记 |
## Timer 系统
@@ -49,21 +45,21 @@ Chat Loop (被动) Life Loop (主动)
### 触发流程
```
Life Loop tick
→ 扫描 timers 表,找到 next_fire <= now 的
→ 构建 LLM 请求:
system: persona + inner_state + 当前时间
user: [timer] {label}
→ 调用 LLM无工具轻量
→ 发送回复到 chat
→ cron 类型: 计算下次触发时间,更新 next_fire
→ 一次性: 删除
```
1. Life Loop tick30 秒)
2. 扫描 timers 表,找到 next_fire <= now 的
3. 构建 LLM 请求persona + inner_state + 当前时间 + 情感动机
4. 调用 LLM带全量工具
5. 发送回复到 chat或选择沉默
6. cron 类型自动重新调度,一次性的删除
### 演进方向
## 自动反思
- 给 Life Loop 的 LLM 调用也加工具(查待办、执行命令)
- inner_state 自动更新(对话结束后 LLM 反思)
- 预设 cron晨间/晚间报告)
- 事件驱动(不只是时间驱动)
每 10 条消息后,异步触发一次反思 LLM 调用:
- 输入:当前 inner_state
- 输出:更新后的 inner_state
- 不阻塞对话,不发消息给用户
- 让 bot 持续更新对自己和用户的理解
## 实例隔离
代码仓库不包含实例特定数据。每个 noc 实例的"灵魂"(名字、人格、记忆、情感状态)全部在 SQLite 里。同一份代码可以运行多个独立实例。