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:
@@ -1126,14 +1126,20 @@ def _jarvis_brain(tmp_path, monkeypatch, plans):
|
||||
seen["judged"].append((text, chat_available))
|
||||
return plans.get(text)
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, prepared_tools=None, intent_judge=False, **kw):
|
||||
def fake_engine(db, cfg, tts, text, mem, prepared_tools=None, intent_judge=False, prepared_done=None, **kw):
|
||||
seen["prepared"].append(prepared_tools)
|
||||
seen["intent_judge"] = intent_judge
|
||||
seen.setdefault("done", []).append(prepared_done() if prepared_done is not None else "not passed")
|
||||
mem.add_message("user", text)
|
||||
mem.add_message("assistant", "ok")
|
||||
return "ok"
|
||||
|
||||
def fake_done(cfg, text, mem):
|
||||
seen.setdefault("done_asked", []).append(text)
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(engine, "prepare_intent", fake_prepare)
|
||||
monkeypatch.setattr(engine, "prepare_done_by_user", fake_done)
|
||||
monkeypatch.setattr(engine, "run_reply_engine", fake_engine)
|
||||
return brain_mod.JarvisBrain(), seen
|
||||
|
||||
@@ -1170,6 +1176,55 @@ def test_a_prepared_pick_is_not_used_for_other_words_another_person_or_a_changed
|
||||
assert seen["prepared"][-1] is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_reply_uses_the_done_by_user_judgement_prepared_for_its_text(tmp_path, monkeypatch):
|
||||
"""The done-by-user guard's first question is asked while the user still speaks, so a follow-up
|
||||
turn does not wait for it after the answer (reply.spec.md, "Earlier answers after the user did it")."""
|
||||
from jarvis.memory.history import HistoryContext
|
||||
|
||||
b, seen = _jarvis_brain(tmp_path, monkeypatch, {"자비스 속도 조절했으니 말해 봐": []})
|
||||
b.prepare("100", "자비스 속도 조절했으니 말해 봐", False)
|
||||
assert seen["done_asked"] == ["자비스 속도 조절했으니 말해 봐"]
|
||||
b.reply("100", "자비스, 속도 조절했으니 말해 봐", HistoryContext())
|
||||
assert seen["done"] == [True]
|
||||
# Not prepared: the guard asks for itself.
|
||||
b.reply("100", "자비스, 속도 조절했으니 말해 봐", HistoryContext())
|
||||
assert seen["done"][-1] == "not passed"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_slow_done_judgement_does_not_hold_up_the_prepared_pick(tmp_path, monkeypatch):
|
||||
"""The reply starts with the prepared tools at once; only the guard waits for the judgement."""
|
||||
import threading
|
||||
import time as _time
|
||||
from jarvis.memory.history import HistoryContext
|
||||
import jarvis.reply.engine as engine
|
||||
|
||||
b, seen = _jarvis_brain(tmp_path, monkeypatch, {"자비스 날씨 어때": ["getWeather"]})
|
||||
release = threading.Event()
|
||||
|
||||
def slow_done(cfg, text, mem):
|
||||
release.wait(5)
|
||||
return False
|
||||
monkeypatch.setattr(engine, "prepare_done_by_user", slow_done)
|
||||
started = {}
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, prepared_tools=None, prepared_done=None, **kw):
|
||||
started["tools"] = prepared_tools
|
||||
release.set() # the answer is being made while the judgement finishes
|
||||
started["done"] = prepared_done()
|
||||
return "ok"
|
||||
monkeypatch.setattr(engine, "run_reply_engine", fake_engine)
|
||||
t = threading.Thread(target=b.prepare, args=("100", "자비스 날씨 어때", False))
|
||||
t.start()
|
||||
_time.sleep(0.1)
|
||||
t0 = _time.monotonic()
|
||||
b.reply("100", "자비스 날씨 어때?", HistoryContext())
|
||||
t.join()
|
||||
assert started == {"tools": ["getWeather"], "done": False}
|
||||
assert _time.monotonic() - t0 < 2
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_reply_waits_for_a_pick_still_being_prepared_for_its_text(tmp_path, monkeypatch):
|
||||
import threading
|
||||
|
||||
Reference in New Issue
Block a user