perf(voice): ask the done-by-user question while the user still speaks
The done-by-user guard asked its first yes/no question after every follow-up answer was made, adding a short LLM call (~0.4 s) before Jarvis spoke. The question depends only on the user's words, so the voice worker's prepare now asks it on the partial transcript after the tool pick (prepare_done_by_user, follow-up turns only) and the guard uses that judgement (prepared_done), asking only whether the answer refuses when the user said they did it. Without a prepared judgement, or when it failed, the guard asks for itself as before. The reply does not wait for the judgement, only the guard does. Measured on Qwen3.6 through the game PC's Strata, 12 pairs of short follow-up questions in alternating order: brain time median 1.06 s before, 0.69 s after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,7 +29,7 @@ def _content(text: str) -> dict:
|
||||
|
||||
|
||||
def _run(mock_config, db, dialogue_memory, *, text, chat_replies, done="yes", earlier=True, tool_first=False,
|
||||
tool_text="ok", others=()):
|
||||
tool_text="ok", others=(), prepared_done=None):
|
||||
"""``done``: the judge's word for "the user says they did it"; a reply is judged a refusal when
|
||||
it is one of REFUSALS. ``tool_text``: what the tool returns; ``others``: history lines of other
|
||||
people, after Jarvis's answer."""
|
||||
@@ -71,7 +71,7 @@ def _run(mock_config, db, dialogue_memory, *, text, chat_replies, done="yes", ea
|
||||
patch("jarvis.reply.done_guard.call_llm_direct", side_effect=fake_judge):
|
||||
reply = engine_mod.run_reply_engine(
|
||||
db=db, cfg=mock_config, tts=None, text=text, dialogue_memory=dialogue_memory,
|
||||
history=history, legacy_memory=False, intent_judge=True)
|
||||
history=history, legacy_memory=False, intent_judge=True, prepared_done=prepared_done)
|
||||
return reply, seen, judged
|
||||
|
||||
|
||||
@@ -170,3 +170,43 @@ def test_only_jarvis_lines_leave_the_history(mock_config, db, dialogue_memory):
|
||||
assert reply == SPOKEN
|
||||
assert quoted in _said(seen[1])
|
||||
assert "자비스: " + REFUSAL not in _said(seen[1])
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.parametrize("said, expected", [(True, SPOKEN), (False, REFUSAL)], ids=["did it", "did not"])
|
||||
def test_a_judgement_made_ahead_is_not_asked_again(mock_config, db, dialogue_memory, said, expected):
|
||||
"""The prepare stage judged the words while the user was still speaking (latency, reply.spec.md):
|
||||
the guard uses that judgement and asks only whether the answer refuses."""
|
||||
reply, seen, judged = _run(mock_config, db, dialogue_memory, text=DID_IT,
|
||||
chat_replies=[_content(REFUSAL), _content(SPOKEN)], done="no" if said else "yes",
|
||||
prepared_done=lambda: said)
|
||||
assert reply == expected
|
||||
assert not [j for j in judged if j.startswith("<utterance>")]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_no_judgement_made_ahead_asks_for_itself(mock_config, db, dialogue_memory):
|
||||
reply, seen, judged = _run(mock_config, db, dialogue_memory, text=DID_IT,
|
||||
chat_replies=[_content(REFUSAL), _content(SPOKEN)], prepared_done=lambda: None)
|
||||
assert reply == SPOKEN
|
||||
assert DID_IT in judged[0]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_said_done_ahead_judges_only_a_follow_up(mock_config, dialogue_memory):
|
||||
"""No earlier answer: no guard would run, so nothing is asked ahead either."""
|
||||
from jarvis.reply import engine as engine_mod
|
||||
|
||||
asked = []
|
||||
|
||||
def fake_judge(base_url, model, system, user_content, **kwargs):
|
||||
asked.append(user_content)
|
||||
return "yes"
|
||||
|
||||
with patch("jarvis.reply.done_guard.call_llm_direct", side_effect=fake_judge):
|
||||
assert engine_mod.prepare_done_by_user(mock_config, DID_IT, dialogue_memory) is None
|
||||
assert asked == []
|
||||
dialogue_memory.add_message("user", QUESTION)
|
||||
dialogue_memory.add_message("assistant", REFUSAL)
|
||||
assert engine_mod.prepare_done_by_user(mock_config, DID_IT, dialogue_memory) is True
|
||||
assert len(asked) == 1 and DID_IT in asked[0]
|
||||
|
||||
Reference in New Issue
Block a user