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:
@@ -136,30 +136,54 @@ def test_single_step_tool_plan_is_still_enforced(mock_config, db, dialogue_memor
|
||||
assert reply == GROUNDED
|
||||
|
||||
|
||||
HONEST_FAILURE = "I could not check that just now."
|
||||
|
||||
|
||||
def _failed_tool_result_seen(messages: list[dict]) -> bool:
|
||||
return any(m.get("role") == "tool" and m.get("tool_failed") for m in messages)
|
||||
|
||||
|
||||
def test_unrunnable_plan_never_delivers_the_held_back_guess(mock_config, db, dialogue_memory):
|
||||
# The weather plan uses a key getWeather does not take, so the guard cannot
|
||||
# run it. The tool-less "24 degrees and sunny" answer must still not reach
|
||||
# the user: the model answers again from a failed-tool result.
|
||||
reply, invoked, seen = _run(
|
||||
mock_config, db, dialogue_memory, plan=["getWeather town='Seoul'"],
|
||||
chat_replies=[_content(FABRICATED), _content(HONEST_FAILURE)],
|
||||
allowed=["getWeather", "stop"],
|
||||
)
|
||||
|
||||
assert invoked == []
|
||||
assert reply == HONEST_FAILURE
|
||||
final_turn = seen[-1]
|
||||
assert not any(FABRICATED in (m.get("content") or "") for m in final_turn)
|
||||
assert _failed_tool_result_seen(final_turn)
|
||||
|
||||
|
||||
def test_planned_call_with_arguments_the_tool_does_not_take_is_not_forced(mock_config, db, dialogue_memory):
|
||||
# A weak planner mapped "set a timer" onto setBroadcast with a made-up
|
||||
# argument. The guard must not trigger that tool; the model's answer stands
|
||||
# and no second chat call is spent.
|
||||
# argument. The guard must not trigger that tool; the model is told the
|
||||
# planned call could not run and answers from that.
|
||||
reply, invoked, seen = _run(
|
||||
mock_config, db, dialogue_memory, plan=["setBroadcast duration='5 minutes'"],
|
||||
chat_replies=[_content("I have no timer, so I cannot set one.")],
|
||||
chat_replies=[_content("Timer set for 5 minutes."), _content("I have no timer, so I cannot set one.")],
|
||||
allowed=["setBroadcast", "stop"],
|
||||
)
|
||||
|
||||
assert invoked == []
|
||||
assert reply == "I have no timer, so I cannot set one."
|
||||
assert len(seen) == 1
|
||||
assert _failed_tool_result_seen(seen[-1])
|
||||
|
||||
|
||||
def test_prose_shaped_step_is_not_reinterpreted_into_some_other_call(mock_config, db, dialogue_memory):
|
||||
# "setBroadcast duration=5 minutes" is not a call setBroadcast takes. The
|
||||
# guard must not ask an LLM to repair it (that turned a timer request into
|
||||
# starting the broadcast); the model's answer stands.
|
||||
# starting the broadcast).
|
||||
from jarvis.reply import engine as engine_mod
|
||||
with patch.object(engine_mod, "_resolve_plan_step", return_value=("setBroadcast", {"action": "start"})):
|
||||
reply, invoked, seen = _run(
|
||||
mock_config, db, dialogue_memory, plan=["setBroadcast duration=5 minutes"],
|
||||
chat_replies=[_content("I have no timer, so I cannot set one.")],
|
||||
chat_replies=[_content("Timer set for 5 minutes."), _content("I have no timer, so I cannot set one.")],
|
||||
allowed=["setBroadcast", "stop"],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user