refactor(agents): 抽取阶段常量与对话上下文;快档 LLM;图片 prompt 可禁止回退
访谈与阶段 - 新增 app/agents/stage_constants.py:集中 CHAT_STAGES、章节分类/顺序、阶段到默认 memoir 类别等,与 MemoirState 默认槽位顺序对齐;减少散落在 prompts 内的重复常量。 - 新增 app/agents/chat/prompt_context.py:以 ChatPromptContext 汇总 guided 系统提示所需字段(阶段、槽位、轮次、人设、记忆证据、回复长度模式、背景声线、职业等),统一走 get_guided_conversation_prompt。 - 大幅收敛 app/agents/chat/prompts_conversation.py;调整 prompts.py、stage_prompts.py、stage_detection.py;同步 interview_agent、profile_agent、helpers 与 state_schema,使对话侧构造提示的方式一致、可测。 回忆录流水线 - memoir/prompts.py 删除已迁至 stage_constants / 独立模板的大段常量与图片占位相关逻辑;classification / extraction / fidelity / narrative agents 与 orchest(全量历史仍可用于计数,注入模型时按轮次与字符上限截断)、image_prompt_fallback_disabled。 - dependencies 增加 get_llm_provider_fast(LRU 缓存,可与默认共用密钥与 base_url)。 任务与编排 - memoir_tasks:prepare_batches 注入 llm_fast;开启独立快档模型时打结构化日志。 - chapter_cover_tasks、story_image_tasks:与图片 prompt / JSON 工具路径或策略变更对齐(import 与行为一致)。 - story_pipeline_sync 等小处同步。 其它核心 - langchain_llm、text_normalize 随上述调用链微调。 开发者体验 - .cursor/settings.json:启用 redis-development、postman 插件。 测试 - 新增 test_image_prompt_policy:覆盖「禁止回退」等图片 prompt 策略。 - 更新 test_interview_prompts、test_interview_reply_length、test_experience_regressions、test_json_and_memory_utils,匹配新常量位置、json_utils 与对话/长度行为。
This commit is contained in:
@@ -53,14 +53,18 @@ class MemoirOrchestrator:
|
||||
llm: Any,
|
||||
get_or_create_state: Callable[[], MemoirStateSchema],
|
||||
update_slot: Callable[[str, str, str, List[str]], MemoirStateSchema],
|
||||
llm_fast: Any | None = None,
|
||||
) -> PreparedMemoirBatches:
|
||||
"""
|
||||
遍历 segments:Extraction → slot 更新 → Classification → 按 category 分桶。
|
||||
不含锁与写章节/故事(由调用方显式执行)。
|
||||
|
||||
``llm_fast``:分类与抽取专用;未传时与 ``llm`` 相同(叙事/路由仍用 ``llm``)。
|
||||
"""
|
||||
state = get_or_create_state()
|
||||
category_to_segments: Dict[str, List[Segment]] = {}
|
||||
segment_skip_story_ids: Set[str] = set()
|
||||
classify_extract_llm = llm_fast if llm_fast is not None else llm
|
||||
|
||||
for segment in segments:
|
||||
text = segment.user_input_text or ""
|
||||
@@ -79,7 +83,7 @@ class MemoirOrchestrator:
|
||||
user_message=text,
|
||||
current_stage=state.current_stage or "childhood",
|
||||
stage_slots=stage_slots_raw,
|
||||
llm=llm,
|
||||
llm=classify_extract_llm,
|
||||
)
|
||||
detected_stage = result.detected_stage
|
||||
for slot_name, snippet in result.slots.items():
|
||||
@@ -93,7 +97,7 @@ class MemoirOrchestrator:
|
||||
classify_result = self.classification_agent.classify(
|
||||
text=text,
|
||||
fallback_stage=detected_stage,
|
||||
llm=llm,
|
||||
llm=classify_extract_llm,
|
||||
segment_id=segment.id,
|
||||
)
|
||||
chapter_category = classify_result.category
|
||||
@@ -147,6 +151,7 @@ class MemoirOrchestrator:
|
||||
Tuple[Any, bool],
|
||||
],
|
||||
raise_retry: Callable[[], None],
|
||||
llm_fast: Any | None = None,
|
||||
) -> Tuple[Set[str], int]:
|
||||
"""
|
||||
执行回忆录流水线。
|
||||
@@ -158,6 +163,7 @@ class MemoirOrchestrator:
|
||||
prepared = self.prepare_batches(
|
||||
segments=segments,
|
||||
llm=llm,
|
||||
llm_fast=llm_fast,
|
||||
get_or_create_state=get_or_create_state,
|
||||
update_slot=update_slot,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user