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:
@@ -151,6 +151,12 @@ class _Prepared:
|
||||
at: float
|
||||
done: threading.Event = dataclasses.field(default_factory=threading.Event)
|
||||
tools: Optional[list] = None # the intent judge's pick; None: none made
|
||||
# The done-by-user guard's first judgement, made after the pick; None: none made.
|
||||
said_ready: threading.Event = dataclasses.field(default_factory=threading.Event)
|
||||
said: Optional[bool] = None
|
||||
|
||||
def said_done(self) -> Optional[bool]:
|
||||
return self.said if self.said_ready.wait(PREPARED_WAIT_S) else None
|
||||
|
||||
|
||||
# The app passes the MCP servers' environment values (API keys, kept in its encrypted secrets)
|
||||
@@ -266,7 +272,7 @@ class JarvisBrain:
|
||||
return len(mem.get_recent_messages()) if mem.has_recent_messages() else 0
|
||||
|
||||
def prepare(self, user: str, text: str, chat: bool) -> None:
|
||||
from jarvis.reply.engine import prepare_intent
|
||||
from jarvis.reply.engine import prepare_done_by_user, prepare_intent
|
||||
|
||||
mem = self._memory(user)
|
||||
p = _Prepared(text=text, turns=self._turns(mem), at=time.monotonic())
|
||||
@@ -278,18 +284,23 @@ class JarvisBrain:
|
||||
notes_available=True, screen_available=True)
|
||||
finally:
|
||||
p.done.set()
|
||||
debug_log(f"brain prepare user={user} picked={p.tools is not None} "
|
||||
f"ms={(time.perf_counter() - t0) * 1000:.0f}", "llm")
|
||||
t1 = time.perf_counter()
|
||||
try:
|
||||
p.said = Muted.run(prepare_done_by_user, self.cfg, text, mem)
|
||||
finally:
|
||||
p.said_ready.set()
|
||||
debug_log(f"brain prepare user={user} picked={p.tools is not None} said={p.said} "
|
||||
f"ms={(t1 - t0) * 1000:.0f}+{(time.perf_counter() - t1) * 1000:.0f}", "llm")
|
||||
|
||||
def _prepared_tools(self, user: str, text: str) -> Optional[list]:
|
||||
"""The pick prepared for about this text, waiting for one still being made; None if none fits."""
|
||||
def _take_prepared(self, user: str, text: str) -> Optional[_Prepared]:
|
||||
"""What was prepared for about this text, waiting for a pick still being made; None if none fits."""
|
||||
with self._lock:
|
||||
p = self._prepared.pop(user, None)
|
||||
if p is None or not similar(p.text, text) or time.monotonic() - p.at > PREPARED_MAX_AGE_S:
|
||||
return None
|
||||
if not p.done.wait(PREPARED_WAIT_S) or p.turns != self._turns(self._memory(user)):
|
||||
return None
|
||||
return p.tools
|
||||
return p
|
||||
|
||||
def _task_cfg(self):
|
||||
from jarvis.tools.registry import BUILTIN_TOOLS
|
||||
@@ -306,7 +317,8 @@ class JarvisBrain:
|
||||
|
||||
t0 = time.perf_counter()
|
||||
# A task has its own short-term memory: it is not a turn of the person's conversation.
|
||||
prepared = None if task else self._prepared_tools(user, text)
|
||||
p = None if task else self._take_prepared(user, text)
|
||||
prepared = p.tools if p is not None else None
|
||||
cfg = self._task_cfg() if task else self.cfg
|
||||
memory = DialogueMemory(inactivity_timeout=self.cfg.dialogue_memory_timeout, max_interactions=20) \
|
||||
if task else self._memory(user)
|
||||
@@ -326,7 +338,8 @@ class JarvisBrain:
|
||||
language=self.language, history=history, legacy_memory=False,
|
||||
default_language=self.reply_language, compact_prompt=True,
|
||||
intent_judge=True, prepared_tools=prepared,
|
||||
person_notes=notes or None)
|
||||
person_notes=notes or None,
|
||||
prepared_done=p.said_done if p is not None else None)
|
||||
finally:
|
||||
turn_state.reset()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user