diff --git a/config.example.json b/config.example.json index 229ac91..928b1f6 100644 --- a/config.example.json +++ b/config.example.json @@ -5,7 +5,7 @@ "creation_approval": false, "timezone": "", "navigation": { - "_comment": "Navigation is two-stage at BOTH levels and the guards are the create doors (no threshold gate). Category: the softmax offers each existing category WITH its description (bare names carried no signal) plus create_category; confirm_category_fit then confirms the winner's scope (phase navigate:category_scope, P(covers) >= category_tau) and a rejected winner authors a new category. The `response` catchall and create_category share a boundary arbitrated by the actionability guard confirm_non_action (phase navigate:actionability, P(non_action) >= action_tau): the closed response tree is reached ONLY when the input is not a request, so a request no skill covers (e.g. \"what is 255 * 12?\") authors instead of getting a canned reply. Leaf: the softmax offers only existing skills; confirm_skill_fit then compares the winner's action to the request (phase navigate:intent, P(same) >= intent_tau) and a mismatch authors a new leaf. All three taus are separate from the top-level tau so tuning reuse-vs-create or actionability does not move run assessment/fidelity. The category check is deliberately permissive: with real descriptions in-scope requests score 0.9-1.0, so a borderline over-cover routes into a plausible category and the leaf guard catches it. A softmax winner at or above `softmax_bypass_tau` (default 0.5) skips its confirm guard — the winner is already decisive and each skipped guard is one fewer SemIf call on the hot path (traced `category_scope_bypassed` / `intent_bypass`); below it the two-stage confirm runs unchanged.", + "_comment": "Navigation is two-stage at BOTH levels and the guards are the create doors (no threshold gate). Category: the softmax offers each existing category WITH its description (bare names carried no signal) plus create_category; confirm_category_fit then confirms the winner's scope (phase navigate:category_scope, P(covers) >= category_tau) and a rejected winner authors a new category. The `response` catchall and create_category share a boundary arbitrated by the actionability guard confirm_non_action (phase navigate:actionability, P(non_action) >= action_tau): the closed response tree is reached ONLY when the input is not a request, so a request no skill covers (e.g. \"what is 255 * 12?\") authors instead of getting a canned reply. Leaf: the softmax offers only existing skills; confirm_skill_fit then compares the winner's action to the request (phase navigate:intent, P(same) >= intent_tau) and a mismatch authors a new leaf. All three taus are separate from the top-level tau so tuning reuse-vs-create or actionability does not move run assessment/fidelity. The category check is deliberately permissive: with real descriptions in-scope requests score 0.9-1.0, so a borderline over-cover routes into a plausible category and the leaf guard catches it. A **category** softmax winner at or above `softmax_bypass_tau` (default 0.5) skips the scope confirm (traced `category_scope_bypassed`) — `create_category` is one of its options, so a confident winner really did beat authoring a category. The **leaf** intent guard is never bypassed: the leaf softmax offers only existing skills, so a confident winner is \"best of the wrong lot\", not a match, and the guard is the only leaf-level create door.", "intent_tau": 0.6, "category_tau": 0.75, "action_tau": 0.5, diff --git a/docs/flow.md b/docs/flow.md index 4a4cc30..3e9d848 100644 --- a/docs/flow.md +++ b/docs/flow.md @@ -58,15 +58,13 @@ flowchart TD HASSKILLS -- "none" --> CREATESKILL["CreateSkill"] HASSKILLS -- "one" --> SOLE["sole skill
softmax skipped"] HASSKILLS -- "many" --> LEAF["SemIf choice
phase 'navigate:leaf'
options = existing skills only"] - LEAF --> PICK["picked skill
+ leaf_softmax_prob"] + LEAF --> PICK["picked skill"] SOLE --> PICK %% ---------- reuse vs create ---------- PICK --> HARD{"hard-locked category?
(housekeeping)"} HARD -- "yes" --> RUN - HARD -- "no" --> INTENTBYP{"winner prob >=
softmax_bypass_tau?"} - INTENTBYP -- "yes (decisive)" --> RUN - INTENTBYP -- "no (unsure)" --> INTENT["SemIf choice
phase 'navigate:intent'
P same >= intent_tau?"] + HARD -- "no" --> INTENT["SemIf choice
phase 'navigate:intent'
P same >= intent_tau?"] INTENT -- "same" --> RUN INTENT -- "different" --> CREATESKILL @@ -196,7 +194,7 @@ flowchart TD | Category scope | does it cover? | `navigate:category_scope` | descend / create (skipped when decisive) | | Canned | which reply | `navigate:response` | canned line | | Leaf | which skill | `navigate:leaf` | skill | -| Intent guard | same action? | `navigate:intent` | run / create (skipped when decisive) | +| Intent guard | same action? | `navigate:intent` | run / create (never bypassed) | | Config record | record or ask? | `config:record` | persisted / per-fire | | Outcome | did it succeed? | `assess:outcome` | ok / failed | | Requeue | complete or retry? | `assess:requeue` | done / requeue | @@ -214,9 +212,11 @@ first and decides whether the input is an actionable request at all; only non-action input reaches the closed `response` tree, so a request is never canned. The category softmax then offers the real categories (never `response`) plus `create_category`, and the leaf softmax offers only the existing skills — -the reuse-vs-create decision is the intent guard. A softmax winner at or above -`softmax_bypass_tau` (default 0.5) is already decisive, so its confirm guard -(scope/intent) is skipped; below it the guard runs and can reject into create. +the reuse-vs-create decision is the intent guard. A **category** softmax winner +at or above `softmax_bypass_tau` (default 0.5) is already decisive, so its scope +confirm is skipped; the **leaf** intent guard is never bypassed (the leaf softmax +has no create option, so a confident winner is only the closest existing skill, +never a match) — it always runs and can reject into create. New-skill creation is also gated deterministically by the per-category `locks.new_skill` (the `housekeeping` and `response` categories are hard-locked in code). diff --git a/semif_agent/scheduler.py b/semif_agent/scheduler.py index 459bdfe..5cf8594 100644 --- a/semif_agent/scheduler.py +++ b/semif_agent/scheduler.py @@ -248,9 +248,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. + #: A **category** softmax winner at or above this probability skips the + #: category scope confirm — the winner is already decisive. The leaf + #: intent guard is never bypassed (the leaf softmax has no create + #: option, so its confidence carries no match signal). self.bypass_tau = float(nav_cfg.get("softmax_bypass_tau", 0.5)) self.max_reentries = max_reentries self.codegen = codegen @@ -456,10 +457,6 @@ 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 @@ -501,17 +498,12 @@ 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) + # The leaf softmax offers only existing skills (create_skill is + # deliberately not an option), so its winner is "the closest existing + # skill", never a statement that the skill matches. The intent guard is + # therefore the sole leaf-level create door and is never bypassed: a + # confident softmax winner among only-wrong options must still be + # checked, or codegen can never be reached for an unmatched request. if not confirm_skill_fit( self.engine, self.log, self.trace, request, navigation, self.intent_tau ): diff --git a/semif_agent/skills.py b/semif_agent/skills.py index 82bf692..80b6b39 100644 --- a/semif_agent/skills.py +++ b/semif_agent/skills.py @@ -1171,17 +1171,22 @@ def navigate( ) -> 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. + **A confident category winner skips the scope confirm; the leaf intent + guard always runs.** 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`). That + is sound because `create_category` is one of the category softmax options, so + a confident winner genuinely beat "author a new category"; below the threshold + the guard runs and can reject the winner into create. The leaf softmax has + **no** create option (`create_skill` is deliberately absent), so its + probabilities are renormalized over only the existing skills and a confident + winner means "best of the wrong lot", not a match. The leaf intent guard + (`confirm_skill_fit`) is therefore **never** bypassed: it is the sole + leaf-level create door, and skipping it would make codegen unreachable for an + unmatched request. (Regression: with Winnow as the engine, "send a message to + pepper on SimpleX" picked `connect_link` at 0.86 / `next_message` at 0.995, + skipped the guard, and ran a read skill instead of authoring + `simplex.send_message`.) The **actionability guard** (`confirm_non_action`, phase `navigate:actionability`, keyed by `navigation.action_tau`) runs at the **top** @@ -1333,9 +1338,6 @@ 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]) diff --git a/semif_agent/winnow.py b/semif_agent/winnow.py index 6fa8f09..d7e3054 100644 --- a/semif_agent/winnow.py +++ b/semif_agent/winnow.py @@ -9,7 +9,7 @@ and the question becomes its ``instructions``; the server returns a probability over exactly those keys. Winnow runs as its own process (``winnow-server``); see ``local/ENVIRONMENT.md`` -for the guppy deployment. The engine is real: any network, HTTP, or distribution +for this deployment. The engine is real: any network, HTTP, or distribution failure raises `EngineUnavailable`, which the scheduler treats as fatal — there is no fallback model and no fabricated reply. """ diff --git a/tests/test_skills.py b/tests/test_skills.py index 34f200c..4a814b1 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -1015,7 +1015,8 @@ def test_dispatch_intent_tau_controls_reuse_vs_create(tmp_path): { "top-level category": {"simplex": 1.0}, "Does the scope": {"covers": 1.0}, - # Below softmax_bypass_tau (0.5), so the intent guard runs. + # The leaf softmax offers only existing skills, so the intent + # guard always runs (it is the create door). "skill performs": {"next_message": 0.45, "connect_link": 0.3}, "same action": {"same": 0.8, "different": 0.2}, } @@ -1127,10 +1128,15 @@ def test_dispatch_intent_match_runs_skill(tmp_path): assert result.skill == "next_message" -def test_dispatch_confident_leaf_winner_skips_intent_guard(tmp_path): - """A leaf softmax winner at/above `softmax_bypass_tau` skips the intent - confirm: the guard would reject here (same action = different), but a - decisive softmax runs the skill instead.""" +def test_dispatch_confident_leaf_winner_still_runs_intent_guard(tmp_path): + """A leaf softmax winner at/above `softmax_bypass_tau` does NOT skip the + intent confirm: the leaf softmax offers only existing skills (no create + option), so a confident winner is "best of the wrong lot", never a match. + The guard runs and, here, rejects the winner into create_skill. + + Regression: with Winnow as the engine a send request picked `connect_link` + at 0.86 / `next_message` at 0.995, the old `intent_bypass` ran a read skill, + and codegen was never reached.""" engine = _ProbEngine( { "top-level category": {"simplex": 1.0}, @@ -1165,12 +1171,16 @@ def test_dispatch_confident_leaf_winner_skips_intent_guard(tmp_path): Skill(name="connect_link", category="simplex", description="Show the contact link."), ] } - result = scheduler._dispatch(Request("read the next simplex message")) - assert result.kind == "ran" - assert result.skill == "next_message" - assert any(e["kind"] == "intent_bypass" for e in scheduler.trace.read()) + queued: list = [] + scheduler._queue_draft = lambda request, category, kind: queued.append( + (category, kind) + ) + result = scheduler._dispatch(Request("send a simplex message to pepper")) + assert result.kind == "create_skill" + assert queued == [("simplex", "skill")] + assert not any(e["kind"] == "intent_bypass" for e in scheduler.trace.read()) phases = [r["extra"].get("phase") for r in scheduler.log.read()] - assert "navigate:intent" not in phases + assert "navigate:intent" in phases