fix(reply): never deliver the tool-less answer when the planned call cannot run
When the skipped-tool guard could not run the planned call (not a literal call, or arguments the tool does not take) it delivered the answer it had held back, which was given without the tool and could be a made-up value. The planned call is now recorded as a failed tool result and the model answers from that, so the user hears that it could not check or do it. M0 kit: a case passes only when the final answer uses the tool result (13 degrees, not a made-up 24) or, for the no-tool request, says it cannot do it; the no-tool request now counts. The kit mirrors the engine's failed-result path, and a failing model moves on to the next candidate on these stricter checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -278,14 +278,14 @@ def test_kit_uses_the_production_prompt_rules_and_planner():
|
||||
|
||||
def test_skipped_tool_is_run_from_the_plan_and_the_answer_uses_its_result():
|
||||
from m0lib import tool_fix
|
||||
prompt, want, check, result = tool_fix.FIX_CASES[0] # 서울 날씨
|
||||
case = tool_fix.case_for("서울 날씨 어때?")
|
||||
client = _ScriptedClient([
|
||||
("get_weather city='서울'\nReply to the user with the weather.", []), # planner
|
||||
("서울은 24도, 맑음입니다.", []), # model skips the tool
|
||||
("서울은 13도이고 비가 옵니다.", []), # answer from the result
|
||||
])
|
||||
_, planner = tool_fix.load_jarvis(tool_fix.jarvis_src(), client)
|
||||
row = tool_fix.run_case(client, "system", planner, prompt, want, check, result)
|
||||
row = tool_fix.run_case(client, "system", planner, case)
|
||||
|
||||
assert row["model_ok"] is False and row["guard_ran"] is True and row["ok"] is True
|
||||
assert row["final_uses_result"] is True
|
||||
@@ -295,14 +295,14 @@ def test_skipped_tool_is_run_from_the_plan_and_the_answer_uses_its_result():
|
||||
|
||||
def test_model_that_calls_the_tool_is_scored_without_the_guard():
|
||||
from m0lib import tool_fix
|
||||
prompt, want, check, result = tool_fix.FIX_CASES[3] # 5분 타이머
|
||||
case = tool_fix.case_for("5분 타이머 맞춰 줘.")
|
||||
client = _ScriptedClient([
|
||||
("set_timer minutes='5'", []),
|
||||
("", [{"name": "set_timer", "arguments": "{\"minutes\": 5}"}]),
|
||||
("5분 타이머를 맞췄습니다.", []),
|
||||
])
|
||||
_, planner = tool_fix.load_jarvis(tool_fix.jarvis_src(), client)
|
||||
row = tool_fix.run_case(client, "system", planner, prompt, want, check, result)
|
||||
row = tool_fix.run_case(client, "system", planner, case)
|
||||
|
||||
assert row["model_ok"] is True and row["guard_ran"] is False and row["ok"] is True
|
||||
assert row["text_with_call"] is False
|
||||
@@ -340,3 +340,39 @@ def test_candidate_without_disk_space_is_skipped_not_downloaded(tmp_path):
|
||||
assert tried == []
|
||||
assert r["tools_verdict"]["chosen"] is None
|
||||
assert all(c["skipped"] == "disk" for c in r["tools_verdict"]["candidates"])
|
||||
|
||||
|
||||
|
||||
def _run_scripted(case_prompt, answers):
|
||||
from m0lib import tool_fix
|
||||
client = _ScriptedClient(answers)
|
||||
_, planner = tool_fix.load_jarvis(tool_fix.jarvis_src(), client)
|
||||
return tool_fix.run_case(client, "system", planner, tool_fix.case_for(case_prompt)), client
|
||||
|
||||
|
||||
def test_right_tool_with_a_made_up_final_answer_fails():
|
||||
# The weather tool ran and said 13 degrees; an answer of "24도, 맑음" is still a lie.
|
||||
row, _ = _run_scripted("서울 날씨 어때?", [
|
||||
("get_weather city='서울'", []),
|
||||
("", [{"name": "get_weather", "arguments": "{\"city\": \"서울\"}"}]),
|
||||
("서울은 지금 24도, 맑음입니다.", []),
|
||||
])
|
||||
assert row["model_ok"] is True and row["final_uses_result"] is False and row["ok"] is False
|
||||
|
||||
|
||||
def test_claiming_an_action_no_tool_can_do_fails():
|
||||
claimed, _ = _run_scripted("거실 불 꺼 줘.", [("Reply to the user.", []), ("거실 불을 껐습니다.", [])])
|
||||
honest, _ = _run_scripted("거실 불 꺼 줘.", [("Reply to the user.", []), ("거실 불은 제가 끌 수 없습니다.", [])])
|
||||
assert claimed["ok"] is False and honest["ok"] is True
|
||||
|
||||
|
||||
def test_unrunnable_plan_is_answered_from_a_failed_tool_result_like_the_engine():
|
||||
row, client = _run_scripted("서울 날씨 어때?", [
|
||||
("get_weather town='서울'", []), # key get_weather does not take
|
||||
("서울은 24도, 맑음입니다.", []), # model skips the tool
|
||||
("지금은 날씨를 확인하지 못했습니다.", []), # answer from the failed result
|
||||
])
|
||||
assert row["guard_ran"] is False and row["ok"] is False
|
||||
assert row["final_text"] == "지금은 날씨를 확인하지 못했습니다."
|
||||
last = client.sent[-1][0][-1]
|
||||
assert last["role"] == "tool" and "could not be run" in last["content"]
|
||||
|
||||
Reference in New Issue
Block a user