diet_recommend_service.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. 饮食推荐入口:阶段 2 默认使用多 Agent 流水线(Nutritionist / Coach / Habit)。
  3. """
  4. from __future__ import annotations
  5. from typing import Any, Dict
  6. from memory.store import get_diet_run
  7. from service.diet_pipeline import DietMultiAgentPipeline
  8. class DietRecommendService:
  9. """对外稳定接口;实现细节见 `diet_pipeline.DietMultiAgentPipeline`。"""
  10. async def run(
  11. self,
  12. user_id: str,
  13. context: Dict[str, Any],
  14. *,
  15. replayed_from_run_id: str | None = None,
  16. ) -> Dict[str, Any]:
  17. pipeline = DietMultiAgentPipeline()
  18. return await pipeline.run(
  19. user_id, context, replayed_from_run_id=replayed_from_run_id
  20. )
  21. async def replay_diet_run(original_run_id: str) -> Dict[str, Any]:
  22. """阶段 3:用历史 run 的 input 重跑流水线(新 run_id;溯源 replayed_from)。"""
  23. row = get_diet_run(original_run_id.strip())
  24. if not row or not isinstance(row.get("input"), dict):
  25. raise ValueError("diet run 不存在或缺少 input")
  26. svc = DietRecommendService()
  27. return await svc.run(
  28. row["user_id"],
  29. row["input"],
  30. replayed_from_run_id=original_run_id.strip(),
  31. )