refactor(chat): AI-native prompts, remove interview heuristics
- Drop interview_reply_length and utterance_substance; always run stage LLM and memory retrieval when enabled; trim Settings fields and .env.example. - Replace guided/opening prompts with compact fact blocks plus unified behavior guidance; slim background_voice and persona to tone hints. - InterviewAgent uses fixed chat_interview max_tokens/chars/segments. Also includes stacked work: profile followup/extract path, evaluation rubric and judge schema updates, transcript SPLIT handling in execution service, user export markdown split tests, and golden case fixture.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""访谈提示词:追问触发与性格(Persona)拼接回归。"""
|
||||
"""访谈提示词:精简结构与人格/语气融合回归。"""
|
||||
|
||||
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
||||
|
||||
@@ -10,37 +10,51 @@ from app.agents.chat.prompts_conversation import (
|
||||
)
|
||||
|
||||
|
||||
def test_guided_prompt_contains_mandatory_followup_when_heuristic_matches():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place", "people"],
|
||||
filled_slots={},
|
||||
user_message="厉害吧 那个女生叫娟娟",
|
||||
conversation_turn_total=1,
|
||||
same_topic_turns=1,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
)
|
||||
assert "本轮追问判定" in p
|
||||
assert "本轮判定" in p
|
||||
|
||||
|
||||
def test_guided_prompt_does_not_embed_raw_user_message_in_system_text():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="__USER_SECRET_PHRASE_XYZ__",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
)
|
||||
assert "__USER_SECRET_PHRASE_XYZ__" not in p
|
||||
# Signature no longer takes user_message; secret would only leak via profile
|
||||
p2 = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="__USER_SECRET_PROFILE__",
|
||||
persona="default",
|
||||
)
|
||||
assert "__USER_SECRET_PROFILE__" in p2
|
||||
|
||||
|
||||
def test_guided_prompt_mentions_empathy_and_self_judgment():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
)
|
||||
assert "接住对方" in p
|
||||
assert "你自己判断" in p or "该追问" in p
|
||||
|
||||
|
||||
def test_guided_prompt_persona_tone_warm_listener():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="education",
|
||||
empty_slots=["school"],
|
||||
filled_slots={},
|
||||
detected_user_stage="education",
|
||||
user_profile_context="",
|
||||
persona="warm_listener",
|
||||
)
|
||||
assert "倾听" in p or "柔和" in p
|
||||
|
||||
|
||||
def test_guided_prompt_persona_curious_guide():
|
||||
@@ -48,15 +62,11 @@ def test_guided_prompt_persona_curious_guide():
|
||||
current_stage="education",
|
||||
empty_slots=["school"],
|
||||
filled_slots={},
|
||||
user_message="还行吧",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="education",
|
||||
user_profile_context="",
|
||||
persona="curious_guide",
|
||||
)
|
||||
assert "好奇引导" in p
|
||||
assert "细节" in p
|
||||
|
||||
|
||||
def test_normalize_interview_persona_unknown_falls_back():
|
||||
@@ -64,32 +74,11 @@ def test_normalize_interview_persona_unknown_falls_back():
|
||||
assert normalize_interview_persona("") == "default"
|
||||
|
||||
|
||||
def test_guided_prompt_contains_memoir_orientation():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="后来我就去上班了",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
)
|
||||
assert "对话方向" in p
|
||||
assert "人生故事" in p
|
||||
|
||||
|
||||
def test_guided_prompt_contains_memory_section_when_evidence():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="后来我就去上班了",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
@@ -100,75 +89,17 @@ def test_guided_prompt_contains_memory_section_when_evidence():
|
||||
assert "1990年生于上海" in p
|
||||
|
||||
|
||||
def test_guided_prompt_chit_chat_hint():
|
||||
def test_guided_prompt_military_tone_in_system():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="今天天气真好哈哈",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
)
|
||||
assert "偏闲聊" in p
|
||||
|
||||
|
||||
def test_guided_prompt_reply_length_section_explicit_expanded():
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="还行吧",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
reply_length_mode="expanded",
|
||||
)
|
||||
assert "本轮回复长度" in p
|
||||
assert "当前档位:expanded" in p
|
||||
assert "expanded" in p
|
||||
|
||||
|
||||
def test_guided_prompt_reply_length_explicit_brief():
|
||||
"""档位由 Agent 的 ReplyPlan 传入,prompt 不再自行推导。"""
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="嗯",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
reply_length_mode="brief",
|
||||
)
|
||||
assert "当前档位:brief" in p
|
||||
|
||||
|
||||
def test_guided_prompt_background_voice_military() -> None:
|
||||
p = get_guided_conversation_prompt(
|
||||
current_stage="childhood",
|
||||
empty_slots=["place"],
|
||||
filled_slots={},
|
||||
user_message="后来我就去上班了",
|
||||
conversation_turn_total=0,
|
||||
same_topic_turns=0,
|
||||
all_stages_coverage=None,
|
||||
detected_user_stage="childhood",
|
||||
user_profile_context="",
|
||||
persona="default",
|
||||
background_voice="military",
|
||||
)
|
||||
assert "背景语气:军队语境" in p
|
||||
assert "先接住对方" in p
|
||||
assert "简洁" in p or "利落" in p or "得体" in p
|
||||
|
||||
|
||||
def test_opening_prompt_military_has_examples_note() -> None:
|
||||
@@ -180,11 +111,9 @@ def test_opening_prompt_military_has_examples_note() -> None:
|
||||
background_voice="military",
|
||||
)
|
||||
assert "军队语境" in p
|
||||
assert "(军队语境:简洁" in p or "军队语境" in p
|
||||
|
||||
|
||||
def test_format_history_string_includes_system_for_debug_logs() -> None:
|
||||
"""log_agent_payload 依赖本函数时需包含 System,避免生产上丢失主 system prompt。"""
|
||||
s = format_history_string(
|
||||
[
|
||||
SystemMessage(content="SYS_INSTRUCTIONS"),
|
||||
|
||||
Reference in New Issue
Block a user