feat(api): 回忆录管线简化、路由延迟池与相关加固
- Phase1/2:移除 MemoirOrchestrator.run 与 process_memoir_segments 别名;文档改为 process_memoir_phase1。 - 槽位校验集中到 stage_constants(filter_stage_slots),批处理与顺序路径及 state_service 写库一致。 - StoryRoute:no_llm/parse_error/invalid_target 保守 new_story;短篇护栏不覆盖这些 fallback。 - Phase2 低置信单路径可选延迟(StoryPipelineResult.deferred):不写 Chapter/Story,Segment 记录 defer 元数据,冷却内不重复消费;上限后停自动重试,Phase1 同类目新段唤醒池内段。 - Alembic 0017:segments 表 narrative_defer_* 列。 - ProfileAgent:经 LlmGateway/注入 Provider 统一聊天与 JSON,新增测试。 - ImagePromptOrchestrator:LLM 初始化失败可依配置降级或硬失败;补充策略测试。 - 配套单测与 README/本地开发文档表述更新。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -106,7 +106,10 @@ def test_orchestrator_fallback_to_sequential(monkeypatch: pytest.MonkeyPatch) ->
|
||||
|
||||
orch._prepare_batches_via_batch_llm = fail_batch
|
||||
orch.extraction_agent.extract = MagicMock(
|
||||
return_value=ExtractionResult(detected_stage="childhood", slots={"toy": "ball"})
|
||||
return_value=ExtractionResult(
|
||||
detected_stage="childhood",
|
||||
slots={"place": "潍坊"},
|
||||
)
|
||||
)
|
||||
orch.classification_agent.classify = MagicMock(
|
||||
return_value=ChapterClassifyResult(category="childhood", llm_said_none=False)
|
||||
@@ -134,6 +137,52 @@ def test_orchestrator_fallback_to_sequential(monkeypatch: pytest.MonkeyPatch) ->
|
||||
assert "s1" in result.segment_chapter_category
|
||||
|
||||
|
||||
def test_orchestrator_sequential_filters_invalid_slots(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Sequential fallback should match batch path slot validation."""
|
||||
monkeypatch.setattr(
|
||||
"app.agents.memoir.orchestrator.settings.memoir_phase1_batch_llm_enabled",
|
||||
False,
|
||||
)
|
||||
|
||||
orch = MemoirOrchestrator()
|
||||
orch.extraction_agent.extract = MagicMock(
|
||||
return_value=ExtractionResult(
|
||||
detected_stage="childhood",
|
||||
slots={"place": "潍坊", "hallucinated": "bad"},
|
||||
)
|
||||
)
|
||||
orch.classification_agent.classify = MagicMock(
|
||||
return_value=ChapterClassifyResult(category="childhood", llm_said_none=False)
|
||||
)
|
||||
|
||||
st = MemoirStateSchema(
|
||||
stage_order=["childhood"],
|
||||
current_stage="childhood",
|
||||
covered_stages=[],
|
||||
slots={},
|
||||
)
|
||||
calls: list[tuple] = []
|
||||
|
||||
class _Seg:
|
||||
id = "s1"
|
||||
user_input_text = "我小时候在潍坊。"
|
||||
|
||||
def update_slot(*args):
|
||||
calls.append(args)
|
||||
return st
|
||||
|
||||
orch.prepare_batches(
|
||||
segments=[_Seg()],
|
||||
llm=MagicMock(),
|
||||
get_or_create_state=lambda: st,
|
||||
update_slot=update_slot,
|
||||
)
|
||||
|
||||
assert calls == [("childhood", "place", "潍坊", ["s1"])]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Memory enrichment decoupled from ingest
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -216,6 +265,33 @@ def test_resolve_append_target_forced_new_on_overflow() -> None:
|
||||
assert dsrc == "forced_new_due_to_append_limit"
|
||||
|
||||
|
||||
def test_resolve_append_target_does_not_guardrail_route_fallback() -> None:
|
||||
"""No-LLM / parse fallback new_story decisions must not append by recency."""
|
||||
from app.features.memoir.story_pipeline_sync import _resolve_append_target
|
||||
|
||||
session = MagicMock()
|
||||
candidate = MagicMock()
|
||||
candidate.id = "story-1"
|
||||
|
||||
tid, existing, dsrc = _resolve_append_target(
|
||||
session,
|
||||
route_decision="new_story",
|
||||
route_target_story_id=None,
|
||||
user_id="u1",
|
||||
chapter_category="childhood",
|
||||
oral_norm="short text",
|
||||
candidate_stories=[candidate],
|
||||
story_meta={"story-1": {"char_count": 10, "version_count": 1}},
|
||||
decision_source="no_llm",
|
||||
memoir_correlation_id=None,
|
||||
)
|
||||
|
||||
assert tid is None
|
||||
assert existing == ""
|
||||
assert dsrc == "no_llm"
|
||||
session.get.assert_not_called()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _run_post_pipeline_commit helper
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user