check actionability at the top of navigation
Move the actionability guard (confirm_non_action) to the top of navigate,
before category selection, instead of only firing when the category softmax
proposed response/create_category. A non-request now goes straight to the
closed response tree and never reaches the category softmax, and the category
softmax offers only real categories (the canned response tree is excluded), so
a request can never be canned and a non-request can never be routed into a
real category.
Reword the guard so vague/incomplete fragments ("what") count as non-action:
they previously matched none of the non_action cases and split the decision
(action 0.513 / non_action 0.487), so "what" authored a redundant
"unclear"/"clarify_intent" category. It now lands on the catchall
response.clarify.
Remove the now-dead CreateSkill-for-canned fallback and _canned_fallback.
Update AGENTS.md, the navigation unit tests, the tune_navigation eval set, and
add an integration test for the vague-fragment route.
This commit is contained in:
1 parent
80518dcdda
commit
1d9730bfcb
6 files changed
+220
-98
No files matched your search
@@ -92,8 +92,8 @@ scheduler.py no up-front gate: every input is dispatched
|
|||||||
queue.py urgency max-heap (desc weight, FIFO seq), age pulls toward 1.0
|
queue.py urgency max-heap (desc weight, FIFO seq), age pulls toward 1.0
|
||||||
skills.py tree + registry (hardcoded built-ins: the closed `response` canned
|
skills.py tree + registry (hardcoded built-ins: the closed `response` canned
|
||||||
tree only), navigation = SemIf choices per level (logged;
|
tree only), navigation = SemIf choices per level (logged;
|
||||||
the actionability guard arbitrates the response/create
|
the actionability guard runs first, at the top of navigation,
|
||||||
boundary), create_category
|
to arbitrate the response/create boundary), create_category
|
||||||
and create_skill author + register stubs via the small `llm`
|
and create_skill author + register stubs via the small `llm`
|
||||||
provider (separate from codegen); SkillStore persists one folder per skill
|
provider (separate from codegen); SkillStore persists one folder per skill
|
||||||
(skill.py, skill.test.py, contract.json, config.json) and
|
(skill.py, skill.test.py, contract.json, config.json) and
|
||||||
@@ -304,21 +304,30 @@ CLI, unit tests (24) + integration tests (2).
|
|||||||
drift into create on a weak plurality (real runs scored `create_skill`
|
drift into create on a weak plurality (real runs scored `create_skill`
|
||||||
0.585–0.803 on requests a seed skill clearly matched). The reuse-vs-create
|
0.585–0.803 on requests a seed skill clearly matched). The reuse-vs-create
|
||||||
decision is the **intent guard** (`confirm_skill_fit`, phase
|
decision is the **intent guard** (`confirm_skill_fit`, phase
|
||||||
`navigate:intent`) at `navigation.intent_tau`. The `response` catchall and
|
`navigate:intent`) at `navigation.intent_tau`. The **actionability guard**
|
||||||
`create_category` share a third guard, the **actionability guard**
|
|
||||||
(`confirm_non_action`, phase `navigate:actionability`) at
|
(`confirm_non_action`, phase `navigate:actionability`) at
|
||||||
`navigation.action_tau` (default 0.5): it arbitrates that boundary whichever
|
`navigation.action_tau` (default 0.5) runs at the **top** of navigation,
|
||||||
side the softmax proposed, so the closed `response` tree is reached **only**
|
before category selection: it decides whether the input is an actionable
|
||||||
when the input is not a request. A request no skill covers (e.g.
|
request at all, so the closed `response` tree is reached **only** for
|
||||||
"what is 255 * 12?") authors instead of getting a canned reply, while a stray
|
non-action input (chit-chat, a statement, or a fragment too vague/incomplete
|
||||||
statement the reworded scope pushes toward create (e.g. "1+1=2") still gets
|
to act on, e.g. "what") and a request can never be canned. Non-action goes
|
||||||
one. A single category description cannot draw that line — both read as math
|
straight to the `response` tree and never reaches the category softmax — a
|
||||||
to the softmax — which is why the guard exists. All three taus are separate
|
vague fragment lands on the catchall `response.clarify`; a request proceeds to
|
||||||
from the top-level `tau`, so tuning reuse-vs-create or actionability does not
|
the category softmax, which now offers only the **real** categories (the
|
||||||
move assessment/fidelity. The guards are deliberately permissive (in-scope
|
canned `response` tree is never an option) plus `create_category`. Deciding
|
||||||
scores 0.9–1.0): a borderline over-cover routes into a plausible category and
|
this first — rather than only when the softmax happens to propose
|
||||||
the leaf guard catches it. Empty and single-skill categories skip their
|
`response`/`create_category` — is what keeps a non-request out of a real
|
||||||
softmax.
|
category: a single category description cannot draw that line ("1+1=2" a
|
||||||
|
statement and "what is 255 * 12?" a request both read as math to the
|
||||||
|
softmax), and the scope guard is deliberately permissive. A request no skill
|
||||||
|
covers (e.g. "what is 255 * 12?") authors instead of getting a canned reply,
|
||||||
|
while a stray statement (e.g. "1+1=2") or a vague fragment (e.g. "what") still
|
||||||
|
gets one. All three taus are
|
||||||
|
separate from the top-level `tau`, so tuning reuse-vs-create or actionability
|
||||||
|
does not move assessment/fidelity. The guards are deliberately permissive
|
||||||
|
(in-scope scores 0.9–1.0): a borderline over-cover routes into a plausible
|
||||||
|
category and the leaf guard catches it. Empty and single-skill categories
|
||||||
|
skip their softmax.
|
||||||
- **No handle/ignore gate; the `response` tree is the non-request catchall**
|
- **No handle/ignore gate; the `response` tree is the non-request catchall**
|
||||||
(Sep 2026; actionability guard Oct 2026): the top-level `_contains_request`
|
(Sep 2026; actionability guard Oct 2026): the top-level `_contains_request`
|
||||||
handle/ignore gate is gone. Every input is scored and dispatched; input that
|
handle/ignore gate is gone. Every input is scored and dispatched; input that
|
||||||
@@ -328,10 +337,12 @@ CLI, unit tests (24) + integration tests (2).
|
|||||||
catchall `response.clarify` — "Could you try being more specific?"). A
|
catchall `response.clarify` — "Could you try being more specific?"). A
|
||||||
**request** is never answered from here, even one no skill covers: the
|
**request** is never answered from here, even one no skill covers: the
|
||||||
actionability guard (`confirm_non_action`, phase `navigate:actionability`)
|
actionability guard (`confirm_non_action`, phase `navigate:actionability`)
|
||||||
arbitrates the `response`/`create_category` boundary and sends a request to
|
runs at the top of navigation and sends a request to authoring (this is what
|
||||||
authoring (this is what keeps "what is 255 * 12?" out of the tree; the old
|
keeps "what is 255 * 12?" out of the tree; the old
|
||||||
`response.unable` canned refusal is gone — an unsupported request authors a
|
`response.unable` canned refusal is gone — an unsupported request authors a
|
||||||
skill, it is not refused). `response` is a `CANNED_CATEGORIES` member:
|
skill, it is not refused). A fragment too vague/incomplete to act on (e.g.
|
||||||
|
"what") is non-action, so it lands on the catchall `response.clarify` rather
|
||||||
|
than authoring a redundant clarify skill. `response` is a `CANNED_CATEGORIES` member:
|
||||||
`navigate` never offers `create_skill` there (the intent guard is skipped
|
`navigate` never offers `create_skill` there (the intent guard is skipped
|
||||||
too), `Scheduler._dispatch_skill`/`restart_skill` refuse to author it, and the
|
too), `Scheduler._dispatch_skill`/`restart_skill` refuse to author it, and the
|
||||||
runner skips `assess:outcome`/repair for it — a canned line has no side effect
|
runner skips `assess:outcome`/repair for it — a canned line has no side effect
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Tune the two-stage navigation guards.
|
"""Tune the two-stage navigation guards.
|
||||||
|
|
||||||
Navigation is two-stage at both levels, and the guards are the create doors:
|
Navigation is two-stage at both levels, and the guards are the create doors.
|
||||||
|
Before either stage, the **actionability guard** (`confirm_non_action`) decides
|
||||||
|
whether the input is a request at all: a non-request goes straight to the closed
|
||||||
|
`response` tree and never reaches the category softmax, so a category-level
|
||||||
|
measurement of a non-request is reported as `response` with no guard
|
||||||
|
probability.
|
||||||
|
|
||||||
- **Category**: the softmax offers every existing category WITH its description
|
- **Category**: the softmax offers every existing (real) category WITH its
|
||||||
plus `create_category`; `confirm_category_fit` confirms the winner's scope.
|
description plus `create_category`; `confirm_category_fit` confirms the
|
||||||
`navigation.category_tau` is that guard's P(covers) floor.
|
winner's scope. `navigation.category_tau` is that guard's P(covers) floor.
|
||||||
- **Leaf**: the softmax offers only existing skills; `confirm_skill_fit`
|
- **Leaf**: the softmax offers only existing skills; `confirm_skill_fit`
|
||||||
compares the winner's action to the request. `navigation.intent_tau` is that
|
compares the winner's action to the request. `navigation.intent_tau` is that
|
||||||
guard's P(same) floor.
|
guard's P(same) floor.
|
||||||
@@ -71,6 +76,7 @@ CATEGORY_EVAL: list[tuple[str, str]] = [
|
|||||||
("tell me the next event in my nextcloud calendar", "calendar"),
|
("tell me the next event in my nextcloud calendar", "calendar"),
|
||||||
("hello there", "response"),
|
("hello there", "response"),
|
||||||
("thanks!", "response"),
|
("thanks!", "response"),
|
||||||
|
("what", "response"),
|
||||||
("book a flight to japan", "create"),
|
("book a flight to japan", "create"),
|
||||||
("what is the weather in paris", "create"),
|
("what is the weather in paris", "create"),
|
||||||
("order me a pizza", "create"),
|
("order me a pizza", "create"),
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ from .skill import SkillRunner
|
|||||||
from .timers import TimerService
|
from .timers import TimerService
|
||||||
from .skills import (
|
from .skills import (
|
||||||
CANNED_CATEGORIES,
|
CANNED_CATEGORIES,
|
||||||
RESPONSE_FALLBACK,
|
|
||||||
ActionContext,
|
ActionContext,
|
||||||
CategoryRegistry,
|
CategoryRegistry,
|
||||||
CreateCategory,
|
CreateCategory,
|
||||||
@@ -467,16 +466,6 @@ class Scheduler:
|
|||||||
if isinstance(navigation, CreateCategory):
|
if isinstance(navigation, CreateCategory):
|
||||||
return self._dispatch_create_category(request, weight)
|
return self._dispatch_create_category(request, weight)
|
||||||
if isinstance(navigation, CreateSkill):
|
if isinstance(navigation, CreateSkill):
|
||||||
if navigation.category in CANNED_CATEGORIES:
|
|
||||||
fallback = self._canned_fallback(navigation.category)
|
|
||||||
if fallback is not None:
|
|
||||||
self.trace.append(
|
|
||||||
"canned_fallback",
|
|
||||||
request.id,
|
|
||||||
category=navigation.category,
|
|
||||||
fallback=fallback.name,
|
|
||||||
)
|
|
||||||
return self._run_skill(fallback, request)
|
|
||||||
return self._dispatch_skill(request, navigation.category, weight)
|
return self._dispatch_skill(request, navigation.category, weight)
|
||||||
if navigation.category in CANNED_CATEGORIES:
|
if navigation.category in CANNED_CATEGORIES:
|
||||||
return self._run_skill(navigation, request)
|
return self._run_skill(navigation, request)
|
||||||
@@ -492,14 +481,6 @@ class Scheduler:
|
|||||||
return self._dispatch_skill(request, navigation.category, weight)
|
return self._dispatch_skill(request, navigation.category, weight)
|
||||||
return self._run_skill(navigation, request)
|
return self._run_skill(navigation, request)
|
||||||
|
|
||||||
def _canned_fallback(self, category: str) -> Skill | None:
|
|
||||||
"""The catchall canned reply for a closed category, else its first leaf."""
|
|
||||||
skills = self.tree.get(category, [])
|
|
||||||
for skill in skills:
|
|
||||||
if skill.name == RESPONSE_FALLBACK:
|
|
||||||
return skill
|
|
||||||
return skills[0] if skills else None
|
|
||||||
|
|
||||||
def _dispatch_create_category(
|
def _dispatch_create_category(
|
||||||
self, request: Request, weight: float = 0.0
|
self, request: Request, weight: float = 0.0
|
||||||
) -> DispatchResult:
|
) -> DispatchResult:
|
||||||
|
|||||||
+88
-55
@@ -690,32 +690,67 @@ def navigate(
|
|||||||
) -> Skill | CreateCategory | CreateSkill:
|
) -> Skill | CreateCategory | CreateSkill:
|
||||||
"""Descend the tree one SemIf choice per level. Every choice is logged.
|
"""Descend the tree one SemIf choice per level. Every choice is logged.
|
||||||
|
|
||||||
The category level is **two-stage** (mirroring the leaf). The softmax offers
|
The **actionability guard** (`confirm_non_action`, phase
|
||||||
every existing category **with its description** plus a `create_category`
|
`navigate:actionability`, keyed by `navigation.action_tau`) runs at the **top**
|
||||||
branch; the winner is then confirmed by `confirm_category_fit`, a name-anchored
|
of navigation, before any category is considered: the closed `response` tree
|
||||||
scope check. A confirmed winner is descended into; a winner that does not
|
is reached **only** when the input is not a request (a greeting, thanks,
|
||||||
cover the request authors a new category. Bare category names carry no signal
|
acknowledgement, small talk, or a stray statement). A request — even one no
|
||||||
— real runs sent "book a flight to japan" to the `simplex` bucket (0.49 vs
|
skill covers, e.g. "what is 255 * 12?" — authors a skill instead, never a
|
||||||
create_category 0.12) until the descriptions were added — so the descriptions
|
canned reply. Deciding this first (rather than only when the category softmax
|
||||||
are load-bearing. A level with nothing to choose from (an empty tree)
|
happens to propose `response`/`create_category`) is what keeps a non-request
|
||||||
short-circuits straight to create: SemIf decisions need at least two options.
|
out of a real category: a description alone cannot draw the line — "1+1=2" (a
|
||||||
|
statement) and "what is 255 * 12?" (a request) both read as math to the
|
||||||
|
category softmax — and `confirm_category_fit` is deliberately permissive.
|
||||||
|
|
||||||
The `response` catchall and `create_category` share a boundary arbitrated by
|
Only once the guard says the input is a request does the category softmax
|
||||||
`confirm_non_action`, the **actionability guard** (`navigate:actionability`,
|
run, over the **real** categories (the canned `response` tree is never an
|
||||||
keyed by `navigation.action_tau`): the closed `response` tree is reached
|
option) plus `create_category`. The winner is then confirmed by
|
||||||
**only** when the input is not a request (a greeting, thanks, acknowledgement,
|
`confirm_category_fit`, a name-anchored scope check: a rejected winner (or a
|
||||||
small talk, or a stray statement). A request — even one no skill covers, e.g.
|
`create_category` win) authors a new category. Descriptions are load-bearing —
|
||||||
"what is 255 * 12?" — authors a skill instead, never a canned reply. This
|
with bare names the model sent "book a flight to japan" to the `simplex`
|
||||||
runs whichever side of the boundary the softmax proposed, because a
|
bucket (0.49 vs create_category 0.12); with descriptions it picks
|
||||||
description alone cannot draw the line: "1+1=2" (a statement) and
|
`create_category` 0.87. An empty tree short-circuits straight to create: SemIf
|
||||||
"what is 255 * 12?" (a request) both look like math to the category softmax.
|
decisions need at least two options.
|
||||||
|
|
||||||
The leaf level is two-stage too: navigation only ever picks among the
|
The leaf level is two-stage too: navigation only ever picks among the
|
||||||
existing skills (`create_skill` is deliberately NOT in the softmax), and the
|
existing skills (`create_skill` is deliberately NOT in the softmax), and the
|
||||||
reuse-vs-create decision is the intent guard in dispatch
|
reuse-vs-create decision is the intent guard in dispatch
|
||||||
(`confirm_skill_fit`), keyed by `navigation.intent_tau`.
|
(`confirm_skill_fit`), keyed by `navigation.intent_tau`.
|
||||||
"""
|
"""
|
||||||
categories = sorted(tree.keys())
|
if not tree:
|
||||||
|
trace.append(
|
||||||
|
"create_category",
|
||||||
|
request.id,
|
||||||
|
state=compose_state(request),
|
||||||
|
question="Which top-level category handles this request?",
|
||||||
|
options=[],
|
||||||
|
selected="create_category",
|
||||||
|
probs={},
|
||||||
|
)
|
||||||
|
return CreateCategory()
|
||||||
|
|
||||||
|
# Actionability first: is this input a request at all? A non-request goes to
|
||||||
|
# the closed `response` tree (a canned reply) and never reaches the category
|
||||||
|
# softmax; a request always proceeds to category selection, so it can never
|
||||||
|
# be canned.
|
||||||
|
if confirm_non_action(engine, log, trace, request, action_tau):
|
||||||
|
response_skills = tree.get("response")
|
||||||
|
if response_skills:
|
||||||
|
return _navigate_canned(
|
||||||
|
engine, log, trace, request, "response", response_skills
|
||||||
|
)
|
||||||
|
trace.append(
|
||||||
|
"create_category",
|
||||||
|
request.id,
|
||||||
|
state=compose_state(request),
|
||||||
|
question="Which top-level category handles this request?",
|
||||||
|
options=[],
|
||||||
|
selected="create_category",
|
||||||
|
probs={},
|
||||||
|
)
|
||||||
|
return CreateCategory()
|
||||||
|
|
||||||
|
categories = [c for c in sorted(tree.keys()) if c not in CANNED_CATEGORIES]
|
||||||
descriptions = category_descriptions(tree)
|
descriptions = category_descriptions(tree)
|
||||||
create_category = Option(
|
create_category = Option(
|
||||||
"create_category",
|
"create_category",
|
||||||
@@ -742,7 +777,7 @@ def navigate(
|
|||||||
top_result = engine.call(top)
|
top_result = engine.call(top)
|
||||||
log.append(top, top_result, extra={"phase": "navigate:category", "run_id": request.id})
|
log.append(top, top_result, extra={"phase": "navigate:category", "run_id": request.id})
|
||||||
category = top_result.selected
|
category = top_result.selected
|
||||||
if category != "create_category" and category not in CANNED_CATEGORIES:
|
if category != "create_category":
|
||||||
if not confirm_category_fit(
|
if not confirm_category_fit(
|
||||||
engine, log, trace, request, category, descriptions.get(category, ""),
|
engine, log, trace, request, category, descriptions.get(category, ""),
|
||||||
category_tau,
|
category_tau,
|
||||||
@@ -754,24 +789,17 @@ def navigate(
|
|||||||
probs=top_result.probs,
|
probs=top_result.probs,
|
||||||
)
|
)
|
||||||
category = "create_category"
|
category = "create_category"
|
||||||
if category == "create_category" or category in CANNED_CATEGORIES:
|
if category == "create_category":
|
||||||
# The actionability guard is the create door for the catchall: only
|
trace.append(
|
||||||
# non-request input gets a canned reply, so a request that merely fell
|
"create_category",
|
||||||
# through the softmax (or was pushed out by the reworded scope) authors.
|
request.id,
|
||||||
if not confirm_non_action(engine, log, trace, request, action_tau) or not tree.get(
|
state=top.state,
|
||||||
"response"
|
question=top.question,
|
||||||
):
|
options=[o.id for o in top.options],
|
||||||
trace.append(
|
selected=top_result.selected,
|
||||||
"create_category",
|
probs=top_result.probs,
|
||||||
request.id,
|
)
|
||||||
state=top.state,
|
return CreateCategory()
|
||||||
question=top.question,
|
|
||||||
options=[o.id for o in top.options],
|
|
||||||
selected=top_result.selected,
|
|
||||||
probs=top_result.probs,
|
|
||||||
)
|
|
||||||
return CreateCategory()
|
|
||||||
return _navigate_canned(engine, log, trace, request, "response", tree["response"])
|
|
||||||
skills = tree[category]
|
skills = tree[category]
|
||||||
if not skills:
|
if not skills:
|
||||||
trace.append(
|
trace.append(
|
||||||
@@ -878,36 +906,41 @@ def confirm_non_action(
|
|||||||
request: Request,
|
request: Request,
|
||||||
tau: float = 0.5,
|
tau: float = 0.5,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Is this input non-request (chit-chat/statement) rather than a request?
|
"""Is this input non-action (not a request) rather than an actionable request?
|
||||||
|
|
||||||
The actionability guard and the create door shared by the `response` catchall
|
The actionability guard, run at the top of `navigate` before any category is
|
||||||
and `create_category`: it arbitrates whichever of the two the category softmax
|
considered. A request — even one no skill covers — must author a skill; only
|
||||||
proposed. A request — even one no skill covers — must author a skill; only
|
non-action input gets a canned reply. Non-action covers chit-chat and
|
||||||
input that asks for nothing gets a canned reply. This is what keeps
|
statements ("1+1=2") **and** fragments too vague/incomplete to act on
|
||||||
"what is 255 * 12?" (a request) out of the closed `response` tree while
|
("what"), which reach `response.clarify` ("Could you try being more
|
||||||
"1+1=2" (a statement) stays in it — a line no single category description can
|
specific?"). This is what keeps "what is 255 * 12?" (a specific request) out
|
||||||
draw, because both read as math to the softmax. Returns True when the input is
|
of the closed `response` tree while "what" (nothing to act on) stays in it —
|
||||||
non-action (route to `response`); the threshold is `navigation.action_tau`
|
a line no single category description can draw, because both read as
|
||||||
(default 0.5, deliberately separate from the other taus so tuning
|
questions to the softmax. Returns True when the input is non-action (route to
|
||||||
actionability moves nothing else).
|
`response`); the threshold is `navigation.action_tau` (default 0.5,
|
||||||
|
deliberately separate from the other taus so tuning actionability moves
|
||||||
|
nothing else).
|
||||||
"""
|
"""
|
||||||
decision = DecisionRequest(
|
decision = DecisionRequest(
|
||||||
state=request.text,
|
state=request.text,
|
||||||
question=(
|
question=(
|
||||||
"Is this input a request to the agent (it asks for an answer, result, "
|
"Is this input a request to the agent (it asks for a specific answer, "
|
||||||
"or task), or is it non-request input (a greeting, thanks, "
|
"result, or task), or is it non-request input (a greeting, thanks, "
|
||||||
"acknowledgement, small talk, or a statement)?"
|
"acknowledgement, small talk, a statement, or a fragment too "
|
||||||
|
"vague/incomplete to act on)?"
|
||||||
),
|
),
|
||||||
options=[
|
options=[
|
||||||
Option(
|
Option(
|
||||||
"action",
|
"action",
|
||||||
"It is a request: the user asks the agent for an answer, a result, "
|
"It is a request: the user asks the agent for a specific answer, a "
|
||||||
"or an action (including one the agent has no skill for yet).",
|
"result, or an action (including one the agent has no skill for "
|
||||||
|
"yet).",
|
||||||
),
|
),
|
||||||
Option(
|
Option(
|
||||||
"non_action",
|
"non_action",
|
||||||
"It is not a request: a greeting, thanks, acknowledgement, small "
|
"It is not a request: a greeting, thanks, acknowledgement, small "
|
||||||
"talk, or a statement.",
|
"talk, a statement, or an incomplete fragment that names nothing to "
|
||||||
|
"act on (e.g. 'what', 'hmm', 'and?').",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -172,6 +172,28 @@ def test_navigation_routes_noise_into_the_response_tree(tmp_path):
|
|||||||
assert getattr(result, "category", None) == "response", f"noise left the response tree: {text!r}"
|
assert getattr(result, "category", None) == "response", f"noise left the response tree: {text!r}"
|
||||||
|
|
||||||
|
|
||||||
|
def test_navigation_routes_vague_fragment_to_clarify(tmp_path):
|
||||||
|
"""A fragment too vague to act on ("what") is non-action: it lands on the
|
||||||
|
catchall `response.clarify` rather than authoring a redundant clarify skill.
|
||||||
|
Regression: "what" scored action 0.513 / non_action 0.487 and authored an
|
||||||
|
"unclear"/"clarify_intent" category."""
|
||||||
|
config = load_config()
|
||||||
|
require_real(config)
|
||||||
|
_isolate_runtime(config, tmp_path)
|
||||||
|
scheduler, config = build_scheduler(config)
|
||||||
|
|
||||||
|
result = navigate(
|
||||||
|
scheduler.engine,
|
||||||
|
scheduler.log,
|
||||||
|
scheduler.trace,
|
||||||
|
Request("what"),
|
||||||
|
scheduler.tree,
|
||||||
|
)
|
||||||
|
print(f"[vague] 'what' -> {result!r}")
|
||||||
|
assert getattr(result, "category", None) == "response", result
|
||||||
|
assert getattr(result, "name", None) == "response.clarify", result
|
||||||
|
|
||||||
|
|
||||||
def test_navigation_routes_uncovered_requests_to_create(tmp_path):
|
def test_navigation_routes_uncovered_requests_to_create(tmp_path):
|
||||||
"""A request no skill covers must author a skill, not get a canned reply: the
|
"""A request no skill covers must author a skill, not get a canned reply: the
|
||||||
actionability guard keeps the closed `response` tree for non-request input
|
actionability guard keeps the closed `response` tree for non-request input
|
||||||
|
|||||||
+70
-1
@@ -625,7 +625,12 @@ def test_navigate_leaf_picks_among_existing_skills_only(tmp_path):
|
|||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
ids = [o.id for o in request.options]
|
ids = [o.id for o in request.options]
|
||||||
return DecisionResult(request=request, option_ids=ids, probabilities=[1.0] * len(ids))
|
if "non_action" in ids:
|
||||||
|
# the top-level actionability guard: this input is a request
|
||||||
|
probs = [1.0 if o == "action" else 0.0 for o in ids]
|
||||||
|
else:
|
||||||
|
probs = [1.0] * len(ids)
|
||||||
|
return DecisionResult(request=request, option_ids=ids, probabilities=probs)
|
||||||
|
|
||||||
engine = Recording()
|
engine = Recording()
|
||||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||||
@@ -878,6 +883,70 @@ def test_navigate_actionability_keeps_a_statement_in_response(tmp_path):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_navigate_actionability_gate_precedes_category_selection(tmp_path):
|
||||||
|
"""The actionability guard runs at the top: a non-request never reaches the
|
||||||
|
category softmax, so it cannot be routed into a real category even when the
|
||||||
|
softmax would have picked one."""
|
||||||
|
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||||
|
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||||
|
tree = build_tree(build_skills({"skills": {}}))
|
||||||
|
tree["simplex"] = [
|
||||||
|
Skill(
|
||||||
|
name="next_message",
|
||||||
|
category="simplex",
|
||||||
|
description="Read the next SimpleX message.",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
engine = _ProbEngine(
|
||||||
|
{
|
||||||
|
"non-request input": {"non_action": 1.0},
|
||||||
|
# If the category softmax ran it would route to simplex, not response.
|
||||||
|
"top-level category": {"simplex": 1.0},
|
||||||
|
"canned response": {"response.greeting": 1.0},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
result = navigate(engine, log, trace, Request("the sky is blue"), tree)
|
||||||
|
assert getattr(result, "category", None) == "response"
|
||||||
|
assert all(
|
||||||
|
"top-level category" not in c.question for c in engine.calls
|
||||||
|
), "the category softmax must not run for non-request input"
|
||||||
|
phases = [r["extra"]["phase"] for r in log.read()]
|
||||||
|
assert "navigate:actionability" in phases
|
||||||
|
assert "navigate:category" not in phases
|
||||||
|
assert phases.index("navigate:actionability") < phases.index("navigate:response")
|
||||||
|
|
||||||
|
|
||||||
|
def test_navigate_category_softmax_excludes_the_canned_response_tree(tmp_path):
|
||||||
|
"""Once actionability is decided at the top, `response` is never offered in
|
||||||
|
the category softmax — a request cannot be routed to a canned reply — and
|
||||||
|
actionability is logged before category selection."""
|
||||||
|
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||||
|
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||||
|
tree = build_tree(build_skills({"skills": {}}))
|
||||||
|
tree["simplex"] = [
|
||||||
|
Skill(
|
||||||
|
name="next_message",
|
||||||
|
category="simplex",
|
||||||
|
description="Read the next SimpleX message.",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
engine = _ProbEngine(
|
||||||
|
{
|
||||||
|
"top-level category": {"simplex": 1.0},
|
||||||
|
"Does the scope": {"covers": 1.0},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
navigate(engine, log, trace, Request("read the next simplex message"), tree)
|
||||||
|
cat_decision = next(
|
||||||
|
c for c in engine.calls if "top-level category" in c.question
|
||||||
|
)
|
||||||
|
ids = [o.id for o in cat_decision.options]
|
||||||
|
assert "response" not in ids
|
||||||
|
assert "simplex" in ids and "create_category" in ids
|
||||||
|
phases = [r["extra"]["phase"] for r in log.read()]
|
||||||
|
assert phases.index("navigate:actionability") < phases.index("navigate:category")
|
||||||
|
|
||||||
|
|
||||||
def test_dispatch_action_tau_controls_catchall_routing(tmp_path):
|
def test_dispatch_action_tau_controls_catchall_routing(tmp_path):
|
||||||
"""navigation.action_tau is the catchall create door, separate from the other
|
"""navigation.action_tau is the catchall create door, separate from the other
|
||||||
taus: a borderline non-action verdict flips on it."""
|
taus: a borderline non-action verdict flips on it."""
|
||||||
|
|||||||
Reference in new issue
Block a user