feat(chat): server-side interview turn plan (mode, anchor slot, snippet)

- Add plan_interview_turn: emotion_first / memoir_push / follow_user_only
- Inject hard directive block at top of guided system prompt
- Pass stage_switched_this_turn from ChatOrchestrator after stage detection
- Log interview_turn_plan for observability; add unit tests
This commit is contained in:
Kevin
2026-04-10 13:56:44 +08:00
parent df6eafeae2
commit 5ff495729e
6 changed files with 301 additions and 2 deletions

View File

@@ -0,0 +1,65 @@
"""interview_turn_plan轮次模式与主槽选择服务端硬编排"""
from app.agents.chat.interview_turn_plan import (
extract_anchor_snippet,
plan_interview_turn,
primary_empty_slot,
)
def test_primary_empty_slot_order():
assert primary_empty_slot("childhood", ["emotion", "place"]) == "place"
assert primary_empty_slot("childhood", ["emotion"]) == "emotion"
def test_extract_anchor_snippet_prefers_memory():
mem = "摘录的一段记忆\n\n[场景氛围提示"
assert "摘录的一段记忆" in extract_anchor_snippet(
memory_evidence_text=mem, user_message="用户说很长一句" * 3
)
def test_plan_memoir_push():
p = plan_interview_turn(
current_stage="childhood",
empty_slots=["place", "people"],
normalized_user_message="我小时候住在河边,夏天常去玩水。",
memory_evidence_text="",
stage_switched_this_turn=False,
)
assert p.mode == "memoir_push"
assert p.anchor_slot_key == "place"
assert p.anchor_snippet
def test_plan_emotion_first():
p = plan_interview_turn(
current_stage="childhood",
empty_slots=["place"],
normalized_user_message="想起来还是很难受,忍不住想哭。",
memory_evidence_text="",
stage_switched_this_turn=False,
)
assert p.mode == "emotion_first"
def test_plan_follow_on_stage_switch():
p = plan_interview_turn(
current_stage="education",
empty_slots=["school", "city"],
normalized_user_message="后来我去省城读中学了。",
memory_evidence_text="",
stage_switched_this_turn=True,
)
assert p.mode == "follow_user_only"
def test_plan_follow_when_no_empty_slots():
p = plan_interview_turn(
current_stage="childhood",
empty_slots=[],
normalized_user_message="嗯。",
memory_evidence_text="",
stage_switched_this_turn=False,
)
assert p.mode == "follow_user_only"