Assistant confirms a command from the values it set, without a second round

run_turn takes answer_tools: false ends the turn once the tools have
answered. The assistant node uses it and says what was set ("Kitchen light
off, living room light off."), which saves one model round, about 1.1 s on
the P100. A turn without a call still streams the model's own words.

rebuild-frontend keeps the running stack's FRONTEND_HOST, so the token
issuer no longer flips between the LAN address and app.localhost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ljdk7nDaguh9Uhi3zhcSjn
This commit is contained in:
Melvin Strobl
2026-10-20 08:26:14 +02:00
co-authored by Claude Opus 5.5
parent 75e257d9e4
commit 5235ac59c2
5 changed files with 59 additions and 28 deletions
+27 -12
View File
@@ -6,8 +6,10 @@ offered as one tool named after its port and typed by its message, so the
wiring is the allowlist, as for wren: the MCP authoring tools are never
offered. Every other input is read as context ("outside_temperature: 7.5").
The answer goes out on ``reply`` a sentence at a time while the model writes
it, so a ``tts`` node speaks the first before the last is written.
An answer goes out on ``reply`` a sentence at a time while the model writes
it, so a ``tts`` node speaks the first before the last is written. A change is
confirmed from the values set ("Kitchen light off."), without asking the model
a second time.
"""
from __future__ import annotations
@@ -43,14 +45,12 @@ LISTENING = "listening"
#: Said when there is no provider, or it does not answer.
UNAVAILABLE = "The assistant isn't available right now."
#: Said when the model ends a turn without a word.
DONE, CANT = "Done.", "Sorry, I can't do that."
#: Said when the model ends a turn without a word or a change.
CANT = "Sorry, I can't do that."
#: A server that is not there is given up on after a few seconds, while a
#: model that has to be loaded first takes about ten.
TIMEOUT = httpx.Timeout(15.0, connect=3.0)
#: Rounds of tool calls one request may take.
ROUNDS = 3
#: A target's type, as its tool's parameter.
_SCHEMAS: dict[DType, dict[str, str]] = {
@@ -63,8 +63,8 @@ _SCHEMAS: dict[DType, dict[str, str]] = {
_SYSTEM = """You are the voice of a home: someone spoke to a panel on the wall, \
and you answer out loud.
- To change something, call its tool. The tools are all you can change.
- After a change, say what you did in one short sentence.
- To change something, call its tool without a word: the change is confirmed \
for you. The tools are all you can change.
- If no tool can do what was asked, or you did not understand it, say so in a \
few words, such as "Sorry, I can't do that."
- Answer questions from the readings below.
@@ -74,6 +74,16 @@ few words, such as "Sorry, I can't do that."
_END = re.compile(r"(?<=[.!?])\s+")
def phrase(port: str, value: Any) -> str:
"""A value set, as the reply says it: "kitchen light off"."""
label = port.replace("_", " ")
if isinstance(value, bool):
return f"{label} {'on' if value else 'off'}"
return (
f"{label} to {value:g}" if isinstance(value, float) else f"{label} to {value}"
)
def cut(text: str) -> tuple[list[str], str]:
"""The sentences ``text`` has finished, and the one still being written."""
*done, rest = _END.split(text)
@@ -212,9 +222,7 @@ class AssistantNode(Node):
config = ai_config.load()
if config is None or not config.ready:
return None
return dataclasses.replace(
config, model=self.cfg.model or config.model, max_rounds=ROUNDS
)
return dataclasses.replace(config, model=self.cfg.model or config.model)
def _call(self, work: Coroutine[Any, Any, Any]) -> Future[Any]:
"""Run on the engine's loop, where the provider's connection is kept."""
@@ -298,6 +306,7 @@ class AssistantNode(Node):
call_tool=self._caller(actions),
extra=self.cfg.extra_body,
timeout=TIMEOUT,
answer_tools=False,
):
if event["type"] == "delta":
done, rest = cut(rest + event["content"])
@@ -313,9 +322,15 @@ class AssistantNode(Node):
if problem:
logger.warning("'%s' got no answer: %s", self.id, problem)
if not said:
await say(UNAVAILABLE if problem else DONE if actions else CANT)
await say(UNAVAILABLE if problem else self._confirm(actions) or CANT)
return problem
def _confirm(self, actions: list[dict[str, Any]]) -> str:
"""The values set, as one sentence: "Kitchen light off, setpoint to 22."."""
ports = {spec.name: spec.port for spec in self._targets()}
text = ", ".join(phrase(ports[a["message"]], a["value"]) for a in actions)
return text[:1].upper() + text[1:] + "." if text else ""
def _caller(self, actions: list[dict[str, Any]]) -> agent.ToolCaller:
"""Set the target a call names, and record it in ``actions``."""
specs = {spec.port: spec for spec in self._targets()}