agent init
This commit is contained in:
@@ -6,17 +6,24 @@
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 1. 文字对话
|
||||
### 1. 智能对话引导
|
||||
- 用户通过WebSocket发送 `TEXT` 类型的消息
|
||||
- AI Agent 生成文字回应
|
||||
- AI Agent 基于人生阶段(童年、教育、事业、家庭、信念)智能引导
|
||||
- Agent 可能返回 1-3 条连续消息,像微信聊天一样自然
|
||||
- 所有对话记录保存到数据库
|
||||
|
||||
### 2. 章节自动整理
|
||||
- 对话结束后,系统自动调用 Memory Agent
|
||||
- 将对话段落整理成结构化的章节
|
||||
- 章节按类别分类(童年、教育、职业、家庭、信念、总结等)
|
||||
### 2. 回忆录增量生成
|
||||
- **实时处理**:每条用户消息都会触发后台异步分析
|
||||
- **智能分类**:自动识别内容所属的人生阶段
|
||||
- **增量写入**:新内容追加到对应章节,不覆盖已有内容
|
||||
- **创意标题**:自动生成富有文学性的章节标题
|
||||
|
||||
### 3. 用户认证
|
||||
### 3. 共享状态管理
|
||||
- 对话 Agent 和回忆录 Agent 共享状态
|
||||
- 状态包含:当前阶段、已完成阶段、各阶段已收集的信息片段
|
||||
- 对话 Agent 根据状态智能选择下一个问题方向
|
||||
|
||||
### 4. 用户认证
|
||||
- 所有操作需要用户登录
|
||||
- 使用JWT访问令牌进行认证
|
||||
- WebSocket连接需要传递token参数
|
||||
@@ -65,12 +72,26 @@
|
||||
"type": "agent_response",
|
||||
"conversation_id": "conversation-id",
|
||||
"data": {
|
||||
"text": "听起来很有趣!能告诉我更多关于你在北京的生活吗?"
|
||||
"text": "听起来很有趣!能告诉我更多关于你在北京的生活吗?",
|
||||
"index": 0,
|
||||
"total": 1
|
||||
},
|
||||
"timestamp": "2024-01-15T10:30:05.000Z"
|
||||
}
|
||||
```
|
||||
|
||||
**多消息支持**:Agent 可能返回多条消息(最多3条),通过 `index` 和 `total` 字段标识:
|
||||
- `index`: 当前消息序号(从0开始)
|
||||
- `total`: 本次回复的总消息数
|
||||
|
||||
示例(Agent 返回2条消息):
|
||||
```json
|
||||
// 第1条
|
||||
{"type": "agent_response", "data": {"text": "那个小院子听起来很温馨。", "index": 0, "total": 2}}
|
||||
// 第2条(约0.5秒后)
|
||||
{"type": "agent_response", "data": {"text": "奶奶给你讲的故事里,有没有哪个让你印象特别深刻?", "index": 1, "total": 2}}
|
||||
```
|
||||
|
||||
#### 对话结束确认
|
||||
```json
|
||||
{
|
||||
@@ -120,6 +141,49 @@ ws://localhost:8000/ws/conversation/{conversation_id}?token={access_token}
|
||||
```bash
|
||||
GET /api/chapters
|
||||
Authorization: Bearer {access_token}
|
||||
|
||||
# 仅查看未读章节
|
||||
GET /api/chapters?is_new=true
|
||||
Authorization: Bearer {access_token}
|
||||
```
|
||||
|
||||
### 7. 查看回忆录状态
|
||||
```bash
|
||||
GET /api/memoir-state
|
||||
Authorization: Bearer {access_token}
|
||||
|
||||
# 返回示例
|
||||
{
|
||||
"stage_order": ["childhood", "education", "career", "family", "belief"],
|
||||
"current_stage": "childhood",
|
||||
"covered_stages": [],
|
||||
"slots": {
|
||||
"childhood": {
|
||||
"place": {"snippet": "在南方一个小镇长大"},
|
||||
"people": {"snippet": "跟奶奶关系很好"},
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 8. 获取下一个问题方向
|
||||
```bash
|
||||
GET /api/memoir-state/next-question
|
||||
Authorization: Bearer {access_token}
|
||||
|
||||
# 返回当前阶段和尚未覆盖的话题
|
||||
{
|
||||
"current_stage": "childhood",
|
||||
"empty_slots": ["daily_life", "turning_event"],
|
||||
"covered_stages": []
|
||||
}
|
||||
```
|
||||
|
||||
### 9. 标记回忆录已读
|
||||
```bash
|
||||
POST /api/memoir-state/mark-read
|
||||
Authorization: Bearer {access_token}
|
||||
```
|
||||
|
||||
## 已移除的功能
|
||||
@@ -133,9 +197,10 @@ Authorization: Bearer {access_token}
|
||||
## 保留的功能
|
||||
|
||||
- ✅ 文字消息处理(`TEXT`)
|
||||
- ✅ Agent 文字回应(`AGENT_RESPONSE`)
|
||||
- ✅ 对话阶段检测
|
||||
- ✅ 章节自动整理
|
||||
- ✅ Agent 多消息回应(`AGENT_RESPONSE`,支持连续 1-3 条)
|
||||
- ✅ 智能对话阶段引导
|
||||
- ✅ 回忆录增量生成(实时后台处理)
|
||||
- ✅ 共享状态管理(回忆录状态 API)
|
||||
- ✅ 用户认证
|
||||
- ✅ 对话管理
|
||||
|
||||
@@ -143,5 +208,6 @@ Authorization: Bearer {access_token}
|
||||
|
||||
1. **WebSocket 连接必须提供 token**:`ws://.../ws/conversation/{id}?token={access_token}`
|
||||
2. **所有对话记录都会保存**:用于后续章节整理
|
||||
3. **章节整理在对话结束时触发**:发送 `END_CONVERSATION` 消息
|
||||
3. **章节增量生成**:每条消息都会触发后台异步分析,不必等对话结束
|
||||
4. **章节按类别自动分类**:系统会根据内容自动判断章节类别
|
||||
5. **多消息处理**:Agent 可能返回多条消息,客户端应根据 `index` 和 `total` 字段正确处理
|
||||
|
||||
Reference in New Issue
Block a user