fix(agent): reuse collected vehicle counts and avoid repeated questions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""20261020 工作流的提示词移植与模型决策回归。"""
|
||||
"""工作流提示词同步、运行时上下文与模型决策回归。"""
|
||||
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
@@ -10,7 +10,7 @@ from src.agent.collect import CollectReplyError, run_collect
|
||||
from src.agent.llm import FakeLLMService
|
||||
from src.agent.prompts import COLLECTION, load_prompt, render_prompt
|
||||
|
||||
WORKFLOW = Path(__file__).resolve().parents[2] / "workflow/20261022/事故信息采集2025118.json"
|
||||
WORKFLOW = Path(__file__).resolve().parents[2] / "workflow/20261027/事故信息采集2025118.json"
|
||||
NODES = {
|
||||
"collection": "事故信息收集",
|
||||
"single_photo": "单车拍照",
|
||||
@@ -52,13 +52,30 @@ def test_user_message_carries_turn_context():
|
||||
from src.agent.collect import _build_user_message
|
||||
from datetime import datetime, timezone
|
||||
now = datetime(2026, 10, 22, 8, 0, tzinfo=timezone.utc)
|
||||
message = _build_user_message({"input_text": "两辆"}, now=now)
|
||||
form = {"vehicle_count": 0, "has_injury": False, "is_on_scene": False}
|
||||
message = _build_user_message({"input_text": "两辆", "accident_fields": form}, now=now)
|
||||
assert "<turn_context>" in message
|
||||
form_line = next(line for line in message.splitlines() if line.startswith("form:"))
|
||||
assert json.loads(form_line.removeprefix("form:")) == form
|
||||
unfilled_line = next(line for line in message.splitlines() if line.startswith("form_unfilled_fields:"))
|
||||
assert json.loads(unfilled_line.removeprefix("form_unfilled_fields:")) == [
|
||||
"accident_cause", "has_non_motor_vehicle_hit", "accident_time",
|
||||
]
|
||||
empty_message = _build_user_message({"input_text": "两辆"}, now=now)
|
||||
assert "form_unfilled_fields" not in empty_message
|
||||
assert "本轮参考时间:2026-10-22 08:00:00 +0000" in message
|
||||
assert "<user_input>" in message
|
||||
assert "两辆" in message
|
||||
|
||||
|
||||
def test_workflow_collection_receives_form_in_user_context():
|
||||
workflow = json.loads(WORKFLOW.read_text(encoding="utf-8-sig"))
|
||||
node = next(n for n in workflow["nodes"] if n["name"] == "事故信息收集")
|
||||
message = next(i["value"] for i in node["inputs"] if i["key"] == "userChatInput")
|
||||
context = message.split("</turn_context>", 1)[0]
|
||||
assert "form:{{$VARIABLE_NODE_ID.bNJkeXot$}}" in context
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_short_answer_does_not_override_model_routing():
|
||||
# “在”可能是明确回答;运行时不得按字数一律拒绝分流。
|
||||
|
||||
Reference in New Issue
Block a user