fix(reply): known user location reaches getWeather; retries are not blocked by the previous reply
- Drop the engine's deterministic Korean weather shortcut. It bypassed the chat model and the tool runner, so a location the user had stated could never be used. The tool already returns one clean Korean sentence. - getWeather and the tool-argument prompts pass the place the user has said they are (conversation or memory) and leave the argument empty otherwise, so the detected location is not copied into it. - getWeather retries a "district, city, country" name with its leading parts dropped when the geocoder finds nothing. - The planner gets the live time/location line and plans searchMemory topic='where the user lives' only when the location is unknown or disabled. - The per-reply repeat guard counts only this reply's tool messages, so calls carried over from the previous reply no longer block a retry the user asks for. - Memory extractor: the context block sits after the examples and the no-location example uses a different query, so a location already in context is not asked for again. New counterpart eval checks that it is still asked for when the context has none. - Tool retry eval fails every call in turn 1, so a model that retries by itself inside turn 1 still exercises the user's "try again". - Specs (planner, reply), docs/llm_contexts.md and the roadmap updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -225,3 +225,53 @@ def test_tool_carryover_text_tool_mode(
|
||||
assert any(
|
||||
"Paris" in (m.get("content") or "") for m in tool_like
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@patch("src.jarvis.reply.engine.plan_query", return_value=[])
|
||||
@patch("src.jarvis.reply.engine.extract_search_params_for_memory", return_value={})
|
||||
@patch("src.jarvis.reply.engine.run_tool_with_retries")
|
||||
@patch("src.jarvis.reply.engine.extract_text_from_response")
|
||||
@patch("src.jarvis.reply.engine.chat_with_messages")
|
||||
def test_retry_asked_in_next_reply_runs_despite_prior_reply_calls(
|
||||
mock_chat, mock_extract, mock_tool, _mock_extract, _mock_plan
|
||||
):
|
||||
"""Calls carried over from the previous reply do not count against the
|
||||
per-reply repeat guard: when reply 1 tried a tool twice and the user
|
||||
then asks to try again, reply 2 runs it."""
|
||||
def _call(cid, place):
|
||||
return {"message": {"content": "", "tool_calls": [{
|
||||
"id": cid, "type": "function",
|
||||
"function": {"name": "getWeather", "arguments": {"location": place}},
|
||||
}]}}
|
||||
|
||||
mock_tool.side_effect = [
|
||||
Mock(success=False, reply_text="", error_message="Could not find location."),
|
||||
Mock(success=False, reply_text="", error_message="Could not find location."),
|
||||
Mock(success=True, reply_text="Kazbegi: 2.5C, partly cloudy.", error_message=None),
|
||||
]
|
||||
mock_chat.side_effect = [
|
||||
_call("c1", "Kazbegi"),
|
||||
_call("c2", "Stepantsminda"),
|
||||
{"message": {"content": "I could not find that place."}},
|
||||
_call("c3", "Kazbegi, Georgia"),
|
||||
{"message": {"content": "It is 2.5C and partly cloudy in Kazbegi."}},
|
||||
]
|
||||
mock_extract.side_effect = [
|
||||
"", "", "I could not find that place.",
|
||||
"", "It is 2.5C and partly cloudy in Kazbegi.",
|
||||
]
|
||||
|
||||
db = Mock()
|
||||
cfg = _mock_cfg()
|
||||
dm = DialogueMemory()
|
||||
|
||||
run_reply_engine(db=db, cfg=cfg, tts=None,
|
||||
text="how's the weather in Kazbegi today?",
|
||||
dialogue_memory=dm)
|
||||
reply = run_reply_engine(db=db, cfg=cfg, tts=None,
|
||||
text="just try checking the weather one more time",
|
||||
dialogue_memory=dm)
|
||||
|
||||
assert mock_tool.call_count == 3
|
||||
assert "2.5" in (reply or "")
|
||||
|
||||
Reference in New Issue
Block a user