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

@@ -21,7 +21,7 @@ from agents.prompts.memory_prompts import (
get_creative_title_prompt,
get_narrative_prompt,
get_state_extraction_prompt,
CHAPTER_ORDER,
STAGE_TO_ORDER,
)
logger = logging.getLogger(__name__)
@@ -264,7 +264,7 @@ def process_memoir_segments(self, user_id: str, segment_ids: List[str]):
chapter.source_segments = list({*(chapter.source_segments or []), *source_ids})
else:
# 根据 stage 计算正确的排序索引
calculated_order_index = CHAPTER_ORDER.index(stage) if stage in CHAPTER_ORDER else 999
calculated_order_index = STAGE_TO_ORDER.get(stage, 999)
chapter = Chapter(
id=str(uuid.uuid4()),
user_id=user_id,
@@ -367,7 +367,7 @@ def generate_chapter_content(self, user_id: str, stage: str, new_content: str):
chapter.is_new = True
else:
# 根据 stage 计算正确的排序索引
calculated_order_index = CHAPTER_ORDER.index(stage) if stage in CHAPTER_ORDER else 999
calculated_order_index = STAGE_TO_ORDER.get(stage, 999)
chapter = Chapter(
id=str(uuid.uuid4()),
user_id=user_id,