feat(voice_worker): a short voice prompt and one judgement before each v2 answer
- compact_prompt: the v2 persona in a tenth of v1's words, answers as short as possible, the full tool guidance only on turns with a data tool. A greeting's reply prompt went from about 4,500 to 1,400 tokens on Strata. - intent_judge: the tool router judges whether the turn needs tools; the planner runs only when it does. prepare_intent runs the pick ahead on a partial transcript (worker message prepare), and the reply reuses it. - Without stream_browser the screen-share tools are not offered. - The time context carries the 12-hour form (10:37 was read as pm). - A <tool_call> block written as the reply is parsed as a call, not spoken. Evals (Qwen3.6 on Strata, EVAL_COMPACT_PROMPT=1 EVAL_INTENT_JUDGE=1): 221 passed, 4 failed (known failures); new evals/test_voice_reply_length.py (v2 answers 234 chars against v1's 416) and test_reply_language_default.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -176,6 +176,9 @@ class Session:
|
||||
# Spoken replies whose speech was cancelled while the brain was still answering.
|
||||
self.cancelled_replies: set[str] = set()
|
||||
self.thinking_replies: set[str] = set()
|
||||
# user -> the newest call text waiting for that user's running prepare to finish (or None).
|
||||
self.preparing: dict[str, str | None] = {}
|
||||
self.last_prepared: dict[str, str] = {} # user -> the text of their last prepare
|
||||
# Answers sent but not yet known to have reached the person: id -> (user, turn, timer).
|
||||
self.deliveries: dict[str, tuple[str, int, asyncio.TimerHandle | None]] = {}
|
||||
self._handed_over: dict[str, bool] = {} # replies whose end is counted by _delivered
|
||||
@@ -316,7 +319,8 @@ class Session:
|
||||
"chat_delete": self._on_chat_delete, "reply": self._on_reply,
|
||||
"addressed": self._on_addressed, "rank": self._on_rank,
|
||||
"chat_channels": self._on_chat_channels, "chat_action_result": self._on_chat_action_result,
|
||||
"memory_config": self._on_memory_config, "reply_delivered": self._on_reply_delivered}.get(kind)
|
||||
"memory_config": self._on_memory_config, "reply_delivered": self._on_reply_delivered,
|
||||
"prepare": self._on_prepare}.get(kind)
|
||||
if handler is None:
|
||||
self.error("bad_message", f"unknown type: {kind!r}")
|
||||
return
|
||||
@@ -507,11 +511,47 @@ class Session:
|
||||
return
|
||||
if speak:
|
||||
self.thinking_replies.add(rid)
|
||||
if user in self.preparing:
|
||||
self.preparing[user] = None # the call was answered: no newer text to prepare
|
||||
self.last_prepared.pop(user, None)
|
||||
waiting = self.worker.replies_unanswered
|
||||
early = waiting.get(user, 0) > 0 # sent before their previous answer: not a reply to it
|
||||
waiting[user] = waiting.get(user, 0) + 1
|
||||
asyncio.get_running_loop().create_task(self._reply(rid, user, text, via, speak, early))
|
||||
|
||||
def _on_prepare(self, msg: dict) -> None:
|
||||
"""A call still being said: the brain gets ready for it. One prepare per user runs at a time;
|
||||
while it runs only the newest text waits, and one about the same as the last one prepared
|
||||
(or being prepared) is dropped. Nothing is sent back."""
|
||||
from .brain import similar
|
||||
got = self._strings(msg, "user", "text")
|
||||
if got is None:
|
||||
return
|
||||
user, text = got
|
||||
if self.worker.brain is None or not hasattr(self.worker.brain, "prepare"):
|
||||
return
|
||||
if user in self.last_prepared and similar(self.last_prepared[user], text):
|
||||
return
|
||||
if user in self.preparing:
|
||||
self.preparing[user] = text
|
||||
return
|
||||
self.preparing[user] = None
|
||||
asyncio.get_running_loop().create_task(self._prepare(user, text))
|
||||
|
||||
async def _prepare(self, user: str, text: str | None) -> None:
|
||||
from .brain import similar
|
||||
try:
|
||||
while text is not None and not self.closed:
|
||||
self.last_prepared[user] = text
|
||||
try:
|
||||
await asyncio.to_thread(self.worker.brain.prepare, user, text, bool(self.chat_channels))
|
||||
except Exception as e: # the brain must never take the session down
|
||||
debug_log(f"brain prepare failed: {type(e).__name__}", "voice_worker")
|
||||
newer, self.preparing[user] = self.preparing[user], None
|
||||
text = newer if newer is not None and not similar(newer, self.last_prepared.get(user, "")) else None
|
||||
finally:
|
||||
self.preparing.pop(user, None)
|
||||
|
||||
def _on_addressed(self, msg: dict) -> None:
|
||||
got = self._strings(msg, "id", "user", "text")
|
||||
if got is None:
|
||||
|
||||
Reference in New Issue
Block a user