- update_inner_state: LLM can update its own persistent inner state - inner_state injected into chat loop system prompt (read-only) - Life Loop now uses run_openai_with_tools (full tool access) - Life Loop LLM calls wrapped in 120s tokio::time::timeout - All reqwest clients: 120s timeout (whisper: 60s) - doc/life.md: life loop architecture design doc - todo.md: removed completed items
70 lines
2.4 KiB
Markdown
70 lines
2.4 KiB
Markdown
# Life Loop 设计
|
||
|
||
## 核心理念
|
||
|
||
小乖不只是一个对话机器人。对话是她跟用户交流的窗口,但 Life Loop 才是她"活着"的地方。
|
||
|
||
## 双循环架构
|
||
|
||
```
|
||
Chat Loop (被动) Life Loop (主动)
|
||
收到消息 → 处理 → 回复 每 30 秒醒来 → 检查 timers
|
||
context: context:
|
||
persona persona
|
||
inner_state (只读) inner_state (读写)
|
||
对话历史 + scratch timer payload
|
||
memory_slots 无对话历史
|
||
tools (全量)
|
||
决策:
|
||
- 发消息给某个 chat
|
||
- 更新 inner_state
|
||
- 什么都不做
|
||
|
||
┌─── SQLite (共享状态层) ───┐
|
||
│ inner_state │
|
||
│ timers │
|
||
│ conversations/messages │
|
||
│ memory_slots / scratch │
|
||
│ config │
|
||
└───────────────────────────┘
|
||
```
|
||
|
||
## 状态层级
|
||
|
||
| 层级 | 名称 | 生命周期 | 用途 |
|
||
|------|------|---------|------|
|
||
| persona | 人格 | 永久 | 定义小乖是谁 |
|
||
| inner_state | 内在状态 | 永久,LLM 自更新 | 小乖对当前情况的感知 |
|
||
| memory_slots | 记忆槽 | 永久,LLM 管理 | 跨会话的关键事实/偏好 |
|
||
| summary | 对话摘要 | 按 session | 长对话的压缩记忆 |
|
||
| scratch | 草稿 | session 内 | 当前任务的工作笔记 |
|
||
|
||
## Timer 系统
|
||
|
||
### 调度格式
|
||
|
||
- 相对时间:`5min`, `2h`, `30s`, `1d`
|
||
- 绝对时间:`once:2026-04-10 09:00`
|
||
- 周期性:`cron:0 8 * * *`(标准 cron 表达式)
|
||
|
||
### 触发流程
|
||
|
||
```
|
||
Life Loop tick
|
||
→ 扫描 timers 表,找到 next_fire <= now 的
|
||
→ 构建 LLM 请求:
|
||
system: persona + inner_state + 当前时间
|
||
user: [timer] {label}
|
||
→ 调用 LLM(无工具,轻量)
|
||
→ 发送回复到 chat
|
||
→ cron 类型: 计算下次触发时间,更新 next_fire
|
||
→ 一次性: 删除
|
||
```
|
||
|
||
### 演进方向
|
||
|
||
- 给 Life Loop 的 LLM 调用也加工具(查待办、执行命令)
|
||
- inner_state 自动更新(对话结束后 LLM 反思)
|
||
- 预设 cron(晨间/晚间报告)
|
||
- 事件驱动(不只是时间驱动)
|