feat: 增强对话代理以检测用户阶段并更新章节排序

- 在 api/agents/conversation_agent.py 中添加 _detect_user_stage 方法,以通过关键词检测用户谈论的人生阶段。
- 在 api/agents/memory_agent.py 中更新章节排序逻辑,使用 STAGE_TO_ORDER 替代 CHAPTER_ORDER。
- 在 api/agents/state_schema.py 中添加方法以获取各阶段的填充情况。
- 在 api/agents/prompts/conversation_prompts.py 中更新对话提示,包含用户阶段检测和整体进度信息。
- 在 api/migrations/fix_chapter_order_index.sql 中添加 SQL 脚本以修复章节 order_index 的问题。
- 更新相关文档和提示以反映新功能。
This commit is contained in:
penghanyuan
2026-02-13 21:45:56 +01:00
parent 0ebeb05420
commit 7fe0b70d5c
9 changed files with 207 additions and 48 deletions

View File

@@ -0,0 +1,15 @@
-- 修复章节 order_index 为 999 的问题
-- 原因STAGE_KEYWORDS 使用简化阶段名career, belief
-- 但 CHAPTER_ORDER 使用详细分类名career_early, beliefs导致查找失败回退到 999
-- 根据 category 字段修复 order_index
UPDATE chapters SET order_index = 0 WHERE order_index = 999 AND category = 'childhood';
UPDATE chapters SET order_index = 1 WHERE order_index = 999 AND category = 'education';
UPDATE chapters SET order_index = 2 WHERE order_index = 999 AND category = 'career';
UPDATE chapters SET order_index = 2 WHERE order_index = 999 AND category = 'career_early';
UPDATE chapters SET order_index = 3 WHERE order_index = 999 AND category = 'career_achievement';
UPDATE chapters SET order_index = 4 WHERE order_index = 999 AND category = 'career_challenge';
UPDATE chapters SET order_index = 5 WHERE order_index = 999 AND category = 'family';
UPDATE chapters SET order_index = 6 WHERE order_index = 999 AND category = 'belief';
UPDATE chapters SET order_index = 6 WHERE order_index = 999 AND category = 'beliefs';
UPDATE chapters SET order_index = 7 WHERE order_index = 999 AND category = 'summary';