소스 검색

fix(langgraph): S-cfc-33 修复 AI 问卷生成 100% 降级 (B-34) - GenerateRequest 补 prompt_template 字段 + build_prompt getattr 防御

Agnes Agent 6 일 전
부모
커밋
1b15b67d2
2개의 변경된 파일과 3개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      cfc-langgraph/src/graphs/questionnaire.py
  2. 1 0
      cfc-langgraph/src/schemas/questionnaire.py

+ 2 - 1
cfc-langgraph/src/graphs/questionnaire.py

@@ -36,7 +36,8 @@ def _build_context(req: GenerateRequest) -> str:
 def build_prompt(state: GraphState) -> GraphState:
     req = state["request"]
     # 优先使用 Java 后端传入的 prompt 模板(可配置),缺省回退内置模板
-    template = req.prompt_template or (
+    # getattr 防御:旧版 schema 无 prompt_template 字段时(AttributeError 崩溃),回退内置模板
+    template = getattr(req, "prompt_template", None) or (
         PARENT_TEMPLATE if req.relationship_type == "parent" else CHILD_TEMPLATE
     )
 

+ 1 - 0
cfc-langgraph/src/schemas/questionnaire.py

@@ -44,6 +44,7 @@ class GenerateRequest(BaseModel):
     member_profile: Optional[dict] = None  # 被评成员:年龄、性别、出生时辰、星座、能量画像等
     respondent_profile: Optional[dict] = None  # 答卷人:年龄、性别、出生时辰、星座、能量画像等
     family_context: Optional[dict] = None  # 家庭背景:家庭成员数、其他成员关系、居住情况等
+    prompt_template: Optional[str] = Field(default=None, description="外部传入的 prompt 模板(Java 后端配置),为 null 时 fallback 内置模板")
 
 
 class GenerateResponse(BaseModel):