navigation: skip confirms on a confident softmax; per-skill humanize; 500ms VAD

Four latency/ergonomics changes from the voice-gateway diagnosis:

1. Per-skill humanize override. A skill's own recorded config
   (data/skills/<cat>/<name>/config.json -> {"humanize": bool}) now wins over
   the per-platform and global defaults, so an already-speakable result
   (time.now) can skip the rewrite. The gateway resolves the skill ref from the
   result summary; `_finish_run` now emits `category.name: ok — …` (matching the
   assessment summary) so the ref is available. Missing store/config/key and
   test doubles degrade to the existing platform/global behavior.

2. Example voice endpointing: vad.silence_ms 1000 -> 500 (config.example.json).

3. Confident softmax winners skip their confirm guard. New
   navigation.softmax_bypass_tau (default 0.5): a category winner at/above it
   skips confirm_category_fit (trace `category_scope_bypassed`); a leaf winner
   at/above it is handed to dispatch and skips confirm_skill_fit (trace
   `intent_bypass`). Below the threshold the two-stage confirm is unchanged.
   Assumption tested first on the decision log: 28/28 category and 28/28 leaf
   winners >= 0.5 agreed with their guard.

4. Engine-throughput investigation saved to AGENTS.md "Later / open questions"
   (routing/assessment compute dominates; profile the engine, not the audio).

Tests updated for the bypass threshold and added for the skill-level humanize
override and bypass paths. Full suite: 486 passed, 1 skipped.
This commit is contained in:
gabby committed 2026-10-06 22:33:38 +00:00
1 parent 5bb0e9d21d
commit d0c1dccffd
7 files changed
+256 -16

No files matched your search

+46 -5
View File
@@ -31,6 +31,13 @@ from .humanize import Humanizer
_LEADING_RUN_ID = re.compile(r"^\[[0-9a-f]{6,}\]\s*")
#: A result summary starts with the skill ref (`category.name:`), optionally
#: preceded by a `[resumed]` marker. Used to look up a skill's own config
#: (`data/skills/<cat>/<name>/config.json`) for a per-skill humanize override.
_SKILL_REF = re.compile(
r"^(?:\[resumed\]\s*)?([A-Za-z0-9_][A-Za-z0-9_-]*\.[A-Za-z0-9_][A-Za-z0-9_-]*):\s"
)
#: The scheduler's run summary wraps the real result as
#: `"<skill>: <ok|failed> — <detail>"`. A result-only platform (the voice
#: gateway) speaks just `<detail>`.
@@ -66,6 +73,12 @@ def _strip_run_id(text: str) -> str:
return _LEADING_RUN_ID.sub("", text or "")
def _skill_ref(text: str) -> str | None:
"""The `category.name` a result summary belongs to, or None."""
match = _SKILL_REF.match(text or "")
return match.group(1) if match else None
def _leading_run_id(text: str) -> str:
match = _LEADING_RUN_ID.match(text or "")
return match.group(0)[1:-2] if match else ""
@@ -202,14 +215,19 @@ class GatewayService:
max_chars=int(cfg.get("max_chars", 600)),
)
def _humanize_enabled(self, platform: str) -> bool:
"""Whether this platform cleans up its result line.
def _humanize_enabled(self, platform: str, skill_ref: str | None = None) -> bool:
"""Whether this result is cleaned up.
A per-platform `humanize` bool (or `{enabled: bool}`) overrides the
global `gateway.humanize.enabled`. Default is off.
Precedence: the **skill's own config** (`data/skills/<category>/<name>/
config.json` -> `{"humanize": bool}`) wins; otherwise the per-platform
override (`gateway.<platform>.humanize`), otherwise the global default
(`gateway.humanize.enabled`). A missing `llm` client disables it.
"""
if self.humanizer is None:
return False
skill_override = self._skill_humanize_override(skill_ref)
if skill_override is not None:
return skill_override
override = self._platform_cfg.get(platform, {}).get("humanize")
if isinstance(override, bool):
return override
@@ -217,6 +235,28 @@ class GatewayService:
return bool(override["enabled"])
return self._humanize_default
def _skill_humanize_override(self, skill_ref: str | None) -> bool | None:
"""The skill's own `humanize` config value, or None when unset.
A skill opts in/out of result cleanup regardless of the platform default
via its recorded config: `data/skills/<category>/<name>/config.json` ->
`{"humanize": false}`. Read from the scheduler's skill store; a missing
store/config/key (or an unparseable ref) means no override.
"""
if not skill_ref or "." not in skill_ref:
return None
store = getattr(self.scheduler, "body_store", None)
if store is None:
return None
category, name = skill_ref.split(".", 1)
try:
config = store.read_config(category, name) or {}
except Exception:
return None
if "humanize" in config:
return bool(config["humanize"])
return None
def _fallback_target(self) -> Target | None:
for platform in self.platforms:
home = self._home_channel(platform)
@@ -438,7 +478,8 @@ class GatewayService:
) -> None:
text = _strip_run_id(text)
result_only = self._result_only(platform)
humanize = kind == "result" and self._humanize_enabled(platform)
skill_ref = _skill_ref(text) if kind == "result" else None
humanize = kind == "result" and self._humanize_enabled(platform, skill_ref)
if result_only:
# A spoken front end says the skill's result, not the scheduler's
# bookkeeping: drop queue/urgency chatter.
+22 -1
View File
@@ -225,6 +225,10 @@ class Scheduler:
self.intent_tau = float(nav_cfg.get("intent_tau", 0.6))
self.category_tau = float(nav_cfg.get("category_tau", 0.75))
self.action_tau = float(nav_cfg.get("action_tau", 0.5))
#: A softmax winner at or above this probability skips its confirm guard
#: (scope/intent) — the winner is already decisive. Below it the guard
#: runs and can reject into create.
self.bypass_tau = float(nav_cfg.get("softmax_bypass_tau", 0.5))
self.max_reentries = max_reentries
self.codegen = codegen
self.degeneration_check_factory = degeneration_check_factory
@@ -416,6 +420,10 @@ class Scheduler:
# ---- dispatch ----
def _dispatch(self, request: Request) -> DispatchResult:
# Clear any confidence a prior dispatch left on the request (meta is
# copied across a requeue); navigation sets it fresh when a leaf softmax
# runs.
request.meta.pop("leaf_softmax_prob", None)
# Explicit housekeeping commands are deterministic: they route straight
# to the meta skill, bypassing the generic guards (which misread a
# task-like skill name as the task). Natural-language phrasings still go
@@ -443,6 +451,7 @@ class Scheduler:
self.tree,
category_tau=self.category_tau,
action_tau=self.action_tau,
bypass_tau=self.bypass_tau,
)
if isinstance(navigation, CreateCategory):
return self._dispatch_create_category(request)
@@ -456,6 +465,17 @@ class Scheduler:
# navigation's pick directly (the meta skill asks for any missing
# target as an input variable).
return self._run_skill(navigation, request)
leaf_prob = request.meta.pop("leaf_softmax_prob", None)
if leaf_prob is not None and leaf_prob >= self.bypass_tau:
# A decisive leaf softmax winner skips the intent confirm.
self.trace.append(
"intent_bypass",
request.id,
category=navigation.category,
skill=navigation.name,
prob=leaf_prob,
)
return self._run_skill(navigation, request)
if not confirm_skill_fit(
self.engine, self.log, self.trace, request, navigation, self.intent_tau
):
@@ -653,7 +673,8 @@ class Scheduler:
return DispatchResult(
kind="ran",
summary=(
f"{skill.name}: {'ok' if outcome.success else 'failed'} — "
f"{skill.category}.{skill.name}: "
f"{'ok' if outcome.success else 'failed'} — "
f"{outcome.action_log or outcome.summary}"
),
skill=skill.name,
+26 -1
View File
@@ -1167,9 +1167,22 @@ def navigate(
tree: dict[str, list[Skill]],
category_tau: float = 0.75,
action_tau: float = 0.5,
bypass_tau: float = 0.5,
) -> Skill | CreateCategory | CreateSkill:
"""Descend the tree one SemIf choice per level. Every choice is logged.
**Confident softmax winners skip their confirm guard.** When the category
softmax winner's probability is >= `bypass_tau` (default 0.5) the scope
confirm (`confirm_category_fit`) is skipped — the winner is taken as-is
(traced `category_scope_bypassed`); below it the guard runs and can reject
the winner into create. The leaf softmax winner's probability is handed to
dispatch (`request.meta["leaf_softmax_prob"]`) so `confirm_skill_fit` is
likewise skipped above the threshold (traced `intent_bypass`). The guards
exist to catch an unsure softmax; a winner at 0.5+ is already decisive, and
each skipped guard is one fewer SemIf call on the hot path. Below the
threshold the two-stage behavior is unchanged. The recorded data agrees:
every logged winner >= 0.5 also passed its guard.
The **actionability guard** (`confirm_non_action`, phase
`navigate:actionability`, keyed by `navigation.action_tau`) runs at the **top**
of navigation, before any category is considered: the closed `response` tree
@@ -1258,7 +1271,16 @@ def navigate(
log.append(top, top_result, extra={"phase": "navigate:category", "run_id": request.id})
category = top_result.selected
if category != "create_category":
if not confirm_category_fit(
winner_prob = float(top_result.probs.get(category, 0.0))
if winner_prob >= bypass_tau:
# Confident winner: skip the scope confirm (one fewer SemIf call).
trace.append(
"category_scope_bypassed",
request.id,
category=category,
prob=winner_prob,
)
elif not confirm_category_fit(
engine, log, trace, request, category, descriptions.get(category, ""),
category_tau,
):
@@ -1311,6 +1333,9 @@ def navigate(
leaf_result = engine.call(leaf)
log.append(leaf, leaf_result, extra={"phase": "navigate:leaf", "run_id": request.id})
pick = leaf_result.selected
# Hand the winner's confidence to dispatch so it can skip the intent guard
# when the softmax is already decisive (see `navigate` docstring).
request.meta["leaf_softmax_prob"] = float(leaf_result.probs.get(pick, 0.0))
return next((s for s in skills if s.name == pick), skills[0])