Просмотр исходного кода

feat: 健康教练graph按coach_id路由人格prompt

iwt 2 месяцев назад
Родитель
Сommit
1dc564c24e
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      cfc-langgraph/app/graphs/health_coach_graph.py

+ 8 - 1
cfc-langgraph/app/graphs/health_coach_graph.py

@@ -86,7 +86,14 @@ def create_health_coach_graph():
 
     async def generate_answer(state: HealthCoachState) -> dict:
         """带健康知识检索的 LLM 生成"""
-        messages = [SystemMessage(content=await get_prompt("health_coach") or DEFAULT_COACH_PROMPT)]
+        # 人格路由:context.coach_id (xibao/fubao) -> 专属prompt,三级回退保证可用性
+        _ctx = state.get("context") or {}
+        _coach_id = _ctx.get("coach_id")
+        if _coach_id not in ("xibao", "fubao"):
+            _coach_id = None
+        _persona_prompt = await get_prompt(f"health_coach_{_coach_id}") if _coach_id else None
+        _base_prompt = await get_prompt("health_coach")
+        messages = [SystemMessage(content=_persona_prompt or _base_prompt or DEFAULT_COACH_PROMPT)]
 
         # 家庭上下文
         ctx = state.get("context") or {}