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
+210
-88
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
|
||||
skills.py tree + registry (hardcoded built-ins: the closed `response` canned
|
||||
tree only), navigation = SemIf choices per level (logged;
|
||||
the actionability guard arbitrates the response/create
|
||||
boundary), create_category
|
||||
the actionability guard runs first, at the top of navigation,
|
||||
to arbitrate the response/create boundary), create_category
|
||||
and create_skill author + register stubs via the small `llm`
|
||||
provider (separate from codegen); SkillStore persists one folder per skill
|
||||
(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`
|
||||
0.585–0.803 on requests a seed skill clearly matched). The reuse-vs-create
|
||||
decision is the **intent guard** (`confirm_skill_fit`, phase
|
||||
`navigate:intent`) at `navigation.intent_tau`. The `response` catchall and
|
||||
`create_category` share a third guard, the **actionability guard**
|
||||
`navigate:intent`) at `navigation.intent_tau`. The **actionability guard**
|
||||
(`confirm_non_action`, phase `navigate:actionability`) at
|
||||
`navigation.action_tau` (default 0.5): it arbitrates that boundary whichever
|
||||
side the softmax proposed, so the closed `response` tree is reached **only**
|
||||
when the input is not a request. A request no skill covers (e.g.
|
||||
"what is 255 * 12?") authors instead of getting a canned reply, while a stray
|
||||
statement the reworded scope pushes toward create (e.g. "1+1=2") still gets
|
||||
one. A single category description cannot draw that line — both read as math
|
||||
to the softmax — which is why the guard exists. 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.
|
||||
`navigation.action_tau` (default 0.5) runs at the **top** of navigation,
|
||||
before category selection: it decides whether the input is an actionable
|
||||
request at all, so the closed `response` tree is reached **only** for
|
||||
non-action input (chit-chat, a statement, or a fragment too vague/incomplete
|
||||
to act on, e.g. "what") and a request can never be canned. Non-action goes
|
||||
straight to the `response` tree and never reaches the category softmax — a
|
||||
vague fragment lands on the catchall `response.clarify`; a request proceeds to
|
||||
the category softmax, which now offers only the **real** categories (the
|
||||
canned `response` tree is never an option) plus `create_category`. Deciding
|
||||
this first — rather than only when the softmax happens to propose
|
||||
`response`/`create_category` — is what keeps a non-request out of a real
|
||||
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**
|
||||
(Sep 2026; actionability guard Oct 2026): the top-level `_contains_request`
|
||||
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
|
||||
**request** is never answered from here, even one no skill covers: the
|
||||
actionability guard (`confirm_non_action`, phase `navigate:actionability`)
|
||||
arbitrates the `response`/`create_category` boundary and sends a request to
|
||||
authoring (this is what keeps "what is 255 * 12?" out of the tree; the old
|
||||
runs at the top of navigation and sends a request to authoring (this is what
|
||||
keeps "what is 255 * 12?" out of the tree; the old
|
||||
`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
|
||||
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
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
"""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
|
||||
plus `create_category`; `confirm_category_fit` confirms the winner's scope.
|
||||
`navigation.category_tau` is that guard's P(covers) floor.
|
||||
- **Category**: the softmax offers every existing (real) category WITH its
|
||||
description plus `create_category`; `confirm_category_fit` confirms the
|
||||
winner's scope. `navigation.category_tau` is that guard's P(covers) floor.
|
||||
- **Leaf**: the softmax offers only existing skills; `confirm_skill_fit`
|
||||
compares the winner's action to the request. `navigation.intent_tau` is that
|
||||
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"),
|
||||
("hello there", "response"),
|
||||
("thanks!", "response"),
|
||||
("what", "response"),
|
||||
("book a flight to japan", "create"),
|
||||
("what is the weather in paris", "create"),
|
||||
("order me a pizza", "create"),
|
||||
|
||||
@@ -40,7 +40,6 @@ from .skill import SkillRunner
|
||||
from .timers import TimerService
|
||||
from .skills import (
|
||||
CANNED_CATEGORIES,
|
||||
RESPONSE_FALLBACK,
|
||||
ActionContext,
|
||||
CategoryRegistry,
|
||||
CreateCategory,
|
||||
@@ -467,16 +466,6 @@ class Scheduler:
|
||||
if isinstance(navigation, CreateCategory):
|
||||
return self._dispatch_create_category(request, weight)
|
||||
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)
|
||||
if navigation.category in CANNED_CATEGORIES:
|
||||
return self._run_skill(navigation, request)
|
||||
@@ -492,14 +481,6 @@ class Scheduler:
|
||||
return self._dispatch_skill(request, navigation.category, weight)
|
||||
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(
|
||||
self, request: Request, weight: float = 0.0
|
||||
) -> DispatchResult:
|
||||
|
||||
+78
-45
@@ -690,32 +690,67 @@ def navigate(
|
||||
) -> Skill | CreateCategory | CreateSkill:
|
||||
"""Descend the tree one SemIf choice per level. Every choice is logged.
|
||||
|
||||
The category level is **two-stage** (mirroring the leaf). The softmax offers
|
||||
every existing category **with its description** plus a `create_category`
|
||||
branch; the winner is then confirmed by `confirm_category_fit`, a name-anchored
|
||||
scope check. A confirmed winner is descended into; a winner that does not
|
||||
cover the request authors a new category. Bare category names carry no signal
|
||||
— real runs sent "book a flight to japan" to the `simplex` bucket (0.49 vs
|
||||
create_category 0.12) until the descriptions were added — so the descriptions
|
||||
are load-bearing. A level with nothing to choose from (an empty tree)
|
||||
short-circuits straight to create: SemIf decisions need at least two options.
|
||||
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
|
||||
is reached **only** when the input is not a request (a greeting, thanks,
|
||||
acknowledgement, small talk, or a stray statement). A request — even one no
|
||||
skill covers, e.g. "what is 255 * 12?" — authors a skill instead, never a
|
||||
canned reply. Deciding this first (rather than only when the category softmax
|
||||
happens to propose `response`/`create_category`) is what keeps a non-request
|
||||
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
|
||||
`confirm_non_action`, the **actionability guard** (`navigate:actionability`,
|
||||
keyed by `navigation.action_tau`): the closed `response` tree is reached
|
||||
**only** when the input is not a request (a greeting, thanks, acknowledgement,
|
||||
small talk, or a stray statement). A request — even one no skill covers, e.g.
|
||||
"what is 255 * 12?" — authors a skill instead, never a canned reply. This
|
||||
runs whichever side of the boundary the softmax proposed, because a
|
||||
description alone cannot draw the line: "1+1=2" (a statement) and
|
||||
"what is 255 * 12?" (a request) both look like math to the category softmax.
|
||||
Only once the guard says the input is a request does the category softmax
|
||||
run, over the **real** categories (the canned `response` tree is never an
|
||||
option) plus `create_category`. The winner is then confirmed by
|
||||
`confirm_category_fit`, a name-anchored scope check: a rejected winner (or a
|
||||
`create_category` win) authors a new category. Descriptions are load-bearing —
|
||||
with bare names the model sent "book a flight to japan" to the `simplex`
|
||||
bucket (0.49 vs create_category 0.12); with descriptions it picks
|
||||
`create_category` 0.87. An empty tree short-circuits straight to create: SemIf
|
||||
decisions need at least two options.
|
||||
|
||||
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
|
||||
reuse-vs-create decision is the intent guard in dispatch
|
||||
(`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)
|
||||
create_category = Option(
|
||||
"create_category",
|
||||
@@ -742,7 +777,7 @@ def navigate(
|
||||
top_result = engine.call(top)
|
||||
log.append(top, top_result, extra={"phase": "navigate:category", "run_id": request.id})
|
||||
category = top_result.selected
|
||||
if category != "create_category" and category not in CANNED_CATEGORIES:
|
||||
if category != "create_category":
|
||||
if not confirm_category_fit(
|
||||
engine, log, trace, request, category, descriptions.get(category, ""),
|
||||
category_tau,
|
||||
@@ -754,13 +789,7 @@ def navigate(
|
||||
probs=top_result.probs,
|
||||
)
|
||||
category = "create_category"
|
||||
if category == "create_category" or category in CANNED_CATEGORIES:
|
||||
# The actionability guard is the create door for the catchall: only
|
||||
# non-request input gets a canned reply, so a request that merely fell
|
||||
# through the softmax (or was pushed out by the reworded scope) authors.
|
||||
if not confirm_non_action(engine, log, trace, request, action_tau) or not tree.get(
|
||||
"response"
|
||||
):
|
||||
if category == "create_category":
|
||||
trace.append(
|
||||
"create_category",
|
||||
request.id,
|
||||
@@ -771,7 +800,6 @@ def navigate(
|
||||
probs=top_result.probs,
|
||||
)
|
||||
return CreateCategory()
|
||||
return _navigate_canned(engine, log, trace, request, "response", tree["response"])
|
||||
skills = tree[category]
|
||||
if not skills:
|
||||
trace.append(
|
||||
@@ -878,36 +906,41 @@ def confirm_non_action(
|
||||
request: Request,
|
||||
tau: float = 0.5,
|
||||
) -> 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
|
||||
and `create_category`: it arbitrates whichever of the two the category softmax
|
||||
proposed. A request — even one no skill covers — must author a skill; only
|
||||
input that asks for nothing gets a canned reply. This is what keeps
|
||||
"what is 255 * 12?" (a request) out of the closed `response` tree while
|
||||
"1+1=2" (a statement) stays in it — a line no single category description can
|
||||
draw, because both read as math to the softmax. Returns True when the input is
|
||||
non-action (route to `response`); the threshold is `navigation.action_tau`
|
||||
(default 0.5, deliberately separate from the other taus so tuning
|
||||
actionability moves nothing else).
|
||||
The actionability guard, run at the top of `navigate` before any category is
|
||||
considered. 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
|
||||
statements ("1+1=2") **and** fragments too vague/incomplete to act on
|
||||
("what"), which reach `response.clarify` ("Could you try being more
|
||||
specific?"). This is what keeps "what is 255 * 12?" (a specific request) out
|
||||
of the closed `response` tree while "what" (nothing to act on) stays in it —
|
||||
a line no single category description can draw, because both read as
|
||||
questions to the softmax. Returns True when the input is non-action (route to
|
||||
`response`); the threshold is `navigation.action_tau` (default 0.5,
|
||||
deliberately separate from the other taus so tuning actionability moves
|
||||
nothing else).
|
||||
"""
|
||||
decision = DecisionRequest(
|
||||
state=request.text,
|
||||
question=(
|
||||
"Is this input a request to the agent (it asks for an answer, result, "
|
||||
"or task), or is it non-request input (a greeting, thanks, "
|
||||
"acknowledgement, small talk, or a statement)?"
|
||||
"Is this input a request to the agent (it asks for a specific answer, "
|
||||
"result, or task), or is it non-request input (a greeting, thanks, "
|
||||
"acknowledgement, small talk, a statement, or a fragment too "
|
||||
"vague/incomplete to act on)?"
|
||||
),
|
||||
options=[
|
||||
Option(
|
||||
"action",
|
||||
"It is a request: the user asks the agent for an answer, a result, "
|
||||
"or an action (including one the agent has no skill for yet).",
|
||||
"It is a request: the user asks the agent for a specific answer, a "
|
||||
"result, or an action (including one the agent has no skill for "
|
||||
"yet).",
|
||||
),
|
||||
Option(
|
||||
"non_action",
|
||||
"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}"
|
||||
|
||||
|
||||
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):
|
||||
"""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
|
||||
|
||||
+70
-1
@@ -625,7 +625,12 @@ def test_navigate_leaf_picks_among_existing_skills_only(tmp_path):
|
||||
|
||||
self.request = request
|
||||
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()
|
||||
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):
|
||||
"""navigation.action_tau is the catchall create door, separate from the other
|
||||
taus: a borderline non-action verdict flips on it."""
|
||||
|
||||
Reference in new issue
Block a user