1) 客服 Agent 四份交付文档 + 构建脚手架:品牌由包装占位 XX科技 / 旧名 南方财富 统一为南方基金(热线 400-889-8899 / 官网 nffund.com),系统名改为「智能服务系统」; 同步追加 §0.4 修订记录行,工程记录行保留原占位字面以支撑硬编码扫描验收。 2) 开发文档:清理 28 份已作废/残留文档(14 份移出归档 + 14 份仓库副本), 新增《文档规整方案与开发前待决事项-2026-09-17》。 3) 客服agent 四份交付文档首次纳入本分支。
53 lines
2.5 KiB
Python
53 lines
2.5 KiB
Python
from app.service.memory_service import MemoryService
|
|
|
|
|
|
def test_memory_extraction_policy() -> None:
|
|
assert MemoryService.should_extract_memory(
|
|
conversation_content="我的风险偏好是稳健", role="user"
|
|
)
|
|
assert not MemoryService.should_extract_memory(conversation_content="", role="user")
|
|
assert MemoryService.should_extract_memory(
|
|
conversation_content="completed", role="system", event_type="trade.completed"
|
|
)
|
|
|
|
|
|
def test_explicit_short_statement_triggers_without_length_threshold() -> None:
|
|
"""长度不再是门槛:两三个字的明确陈述(如"只买货币基金")必须触发。"""
|
|
assert MemoryService.should_extract_memory(conversation_content="只买货币基金", role="user")
|
|
assert MemoryService.should_extract_memory(conversation_content="随时赎回", role="user")
|
|
|
|
|
|
def test_plain_question_never_triggers_even_when_long() -> None:
|
|
"""普通问答即使很长也不触发:没有持久事实就没有记忆。"""
|
|
question = (
|
|
"帮我看看沪深300指数基金最近三个月的走势、同类排名和费率结构,"
|
|
"再解释一下它跟踪误差是怎么算出来的好吗?"
|
|
)
|
|
assert not MemoryService.should_extract_memory(conversation_content=question, role="user")
|
|
assert not MemoryService.should_extract_memory(
|
|
conversation_content="我想买基金", role="user")
|
|
|
|
|
|
def test_reply_and_unknown_event_do_not_trigger() -> None:
|
|
"""助手回复、以及非持久事实类事件(如运行完成)都不触发。"""
|
|
assert not MemoryService.should_extract_memory(
|
|
conversation_content="已为您记录该偏好,还需要什么帮助?", role="assistant")
|
|
assert not MemoryService.should_extract_memory(
|
|
conversation_content="agent.run_completed", role="system",
|
|
event_type="agent.run_completed")
|
|
|
|
|
|
def test_explicit_signal_and_tool_result_trigger() -> None:
|
|
"""调用点显式传入的受控信号、以及工具产出的权威事实同样触发。"""
|
|
assert MemoryService.should_extract_memory(
|
|
conversation_content="嗯", role="user", signals=("profile:family",))
|
|
assert MemoryService.should_extract_memory(
|
|
conversation_content="suitability check passed", role="system", tool_result=True)
|
|
|
|
|
|
def test_detect_memory_signals_returns_controlled_keys() -> None:
|
|
assert MemoryService.detect_memory_signals("我从事教师工作,已婚有两个孩子") == (
|
|
"profile:occupation", "profile:family",
|
|
)
|
|
assert MemoryService.detect_memory_signals("帮我查一下今天的净值") == ()
|