route only non-request input into the response tree
The response category scope claimed to cover "inputs the agent cannot act on", so an actionable request like "what is 255 * 12?" scored as in-scope and landed in the response.unable canned refusal. Add the actionability guard (confirm_non_action, phase navigate:actionability, navigation.action_tau) which arbitrates the response/create_category boundary whichever side the softmax proposed: the closed response tree is now reached only when the input is not a request, so a request no skill covers authors a skill instead. Reword the response scope, drop the response.unable reply, and update tests/docs.
This commit is contained in:
1 parent
9a135f53ab
commit
80518dcdda
7 files changed
+298
-81
No files matched your search
@@ -32,6 +32,7 @@ from semif_agent.scheduler import SkillWrite
|
||||
from semif_agent.skills import (
|
||||
ActionResult,
|
||||
CategoryDraft,
|
||||
CreateCategory,
|
||||
Skill,
|
||||
SkillDraft,
|
||||
SkillStore,
|
||||
@@ -171,6 +172,37 @@ 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_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
|
||||
only. Regression: "what is 255 * 12?" landed in `response.unable` because the
|
||||
response scope said it covered "inputs the agent cannot act on"."""
|
||||
config = load_config()
|
||||
require_real(config)
|
||||
_isolate_runtime(config, tmp_path)
|
||||
scheduler, config = build_scheduler(config)
|
||||
|
||||
requests = [
|
||||
"what is 255 * 12?",
|
||||
"what is the capital of France?",
|
||||
"convert 10 km to miles",
|
||||
"tell me a joke",
|
||||
]
|
||||
for text in requests:
|
||||
result = navigate(
|
||||
scheduler.engine,
|
||||
scheduler.log,
|
||||
scheduler.trace,
|
||||
Request(text),
|
||||
scheduler.tree,
|
||||
action_tau=scheduler.action_tau,
|
||||
)
|
||||
print(f"[request] {text!r} -> {result!r}")
|
||||
assert isinstance(result, CreateCategory), (
|
||||
f"request did not author a skill: {text!r} -> {result!r}"
|
||||
)
|
||||
|
||||
|
||||
def test_navigate_routes_unmatched_action_to_create_skill(tmp_path):
|
||||
"""Two-stage leaf: navigation picks the closest existing skill, then the
|
||||
intent guard decides reuse-vs-create. A send request must reach create_skill
|
||||
|
||||
+112
-17
@@ -44,6 +44,7 @@ from semif_agent.skills import (
|
||||
build_skills,
|
||||
build_tree,
|
||||
confirm_category_fit,
|
||||
confirm_non_action,
|
||||
confirm_skill_fit,
|
||||
category_descriptions,
|
||||
CATEGORY_DESCRIPTIONS,
|
||||
@@ -557,29 +558,20 @@ def test_navigate_empty_tree_short_circuits(tmp_path):
|
||||
|
||||
def test_navigate_canned_category_never_offers_create(tmp_path):
|
||||
"""The `response` tree is closed: its leaf choice has no create_skill option
|
||||
and never authors, regardless of how weak the match is."""
|
||||
and never authors, regardless of how weak the match is. The actionability
|
||||
guard is what routes a non-request input into it."""
|
||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
|
||||
class Recording:
|
||||
def __init__(self):
|
||||
self.request = None
|
||||
|
||||
def call(self, request):
|
||||
from semif_agent.decisions import DecisionResult
|
||||
|
||||
self.request = request
|
||||
ids = [o.id for o in request.options]
|
||||
return DecisionResult(request=request, option_ids=ids, probabilities=[1.0] * len(ids))
|
||||
|
||||
engine = Recording()
|
||||
engine = ScriptedEngine(choices={"non-request input": "non_action"})
|
||||
result = navigate(engine, log, trace, Request("hello there"), tree)
|
||||
assert isinstance(result, Skill)
|
||||
assert result.category == "response"
|
||||
assert all(o.id != "create_skill" for o in engine.request.options)
|
||||
assert "create_skill" not in [o.id for o in engine.request.options]
|
||||
assert result.name in [o.id for o in engine.request.options]
|
||||
leaf = next(c for c in engine.calls if "canned response" in c.question)
|
||||
assert all(o.id != "create_skill" for o in leaf.options)
|
||||
assert "create_skill" not in [o.id for o in leaf.options]
|
||||
assert result.name in [o.id for o in leaf.options]
|
||||
|
||||
|
||||
def test_navigate_canned_category_points_at_the_catchall(tmp_path):
|
||||
@@ -588,7 +580,12 @@ def test_navigate_canned_category_points_at_the_catchall(tmp_path):
|
||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
engine = _ProbEngine({"canned response": {"response.clarify": 1.0}})
|
||||
engine = _ProbEngine(
|
||||
{
|
||||
"non-request input": {"non_action": 1.0},
|
||||
"canned response": {"response.clarify": 1.0},
|
||||
}
|
||||
)
|
||||
result = navigate(engine, log, trace, Request("do the thing"), tree)
|
||||
assert result.name == "response.clarify"
|
||||
leaf = engine.calls[-1]
|
||||
@@ -820,6 +817,104 @@ def test_confirm_category_fit_threshold(tmp_path):
|
||||
)
|
||||
|
||||
|
||||
def test_confirm_non_action_threshold(tmp_path):
|
||||
"""The actionability guard returns True for non-request input and False for a
|
||||
request, logging phase `navigate:actionability`."""
|
||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||
engine = ScriptedEngine(choices={"non-request input": "non_action"})
|
||||
assert (
|
||||
confirm_non_action(engine, log, trace, Request("hello there"), tau=0.5) is True
|
||||
)
|
||||
assert log.read()[-1]["extra"]["phase"] == "navigate:actionability"
|
||||
|
||||
engine = ScriptedEngine(choices={"non-request input": "action"})
|
||||
assert (
|
||||
confirm_non_action(engine, log, trace, Request("what is 255 * 12?"), tau=0.5)
|
||||
is False
|
||||
)
|
||||
assert any(
|
||||
e["kind"] == "actionability" and e["non_action"] is False for e in trace.read()
|
||||
)
|
||||
|
||||
|
||||
def test_navigate_actionability_sends_a_request_to_create(tmp_path):
|
||||
"""A request the softmax dumps in the catchall must author, not get a canned
|
||||
reply: the actionability guard is the create door ("what is 255 * 12?")."""
|
||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
engine = _ProbEngine(
|
||||
{
|
||||
"top-level category": {"response": 1.0},
|
||||
"non-request input": {"action": 1.0},
|
||||
}
|
||||
)
|
||||
result = navigate(engine, log, trace, Request("what is 255 * 12?"), tree)
|
||||
assert isinstance(result, CreateCategory)
|
||||
assert any(
|
||||
e["kind"] == "actionability" and e["non_action"] is False for e in trace.read()
|
||||
)
|
||||
assert any(e["kind"] == "create_category" for e in trace.read())
|
||||
|
||||
|
||||
def test_navigate_actionability_keeps_a_statement_in_response(tmp_path):
|
||||
"""The mirror: a statement the reworded scope pushes to create_category must
|
||||
still get a canned reply ("1+1=2"), not author a category."""
|
||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||
trace = TraceLog(str(tmp_path / "runs.jsonl"))
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
engine = _ProbEngine(
|
||||
{
|
||||
"top-level category": {"create_category": 1.0},
|
||||
"non-request input": {"non_action": 1.0},
|
||||
}
|
||||
)
|
||||
result = navigate(engine, log, trace, Request("1+1=2"), tree)
|
||||
assert isinstance(result, Skill)
|
||||
assert result.category == "response"
|
||||
assert any(
|
||||
e["kind"] == "actionability" and e["non_action"] is True for e in trace.read()
|
||||
)
|
||||
|
||||
|
||||
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."""
|
||||
def build(action_tau: float):
|
||||
scheduler = Scheduler(
|
||||
engine=_ProbEngine(
|
||||
{
|
||||
"top-level category": {"response": 1.0},
|
||||
"non-request input": {"non_action": 0.6, "action": 0.4},
|
||||
}
|
||||
),
|
||||
llm=LLMClient(base_url="http://localhost:1/v1", model="test"),
|
||||
log=DecisionLog(str(tmp_path / "decisions.jsonl")),
|
||||
config={
|
||||
"skills": {},
|
||||
"navigation": {"action_tau": action_tau},
|
||||
"category_registry": str(tmp_path / "categories.json"),
|
||||
"skill_bodies": str(tmp_path / "skills"),
|
||||
"skill_seeds": str(tmp_path / "seeds"),
|
||||
},
|
||||
trace=TraceLog(str(tmp_path / "runs.jsonl")),
|
||||
)
|
||||
scheduler.tree = build_tree(build_skills({"skills": {}}))
|
||||
scheduler._queue_draft = lambda *a, **k: None
|
||||
return scheduler
|
||||
|
||||
low = build(0.5)
|
||||
assert low.action_tau == 0.5
|
||||
ran = low._dispatch(Request("hmm"))
|
||||
assert ran.kind == "ran", "non_action 0.6 clears action_tau 0.5: canned reply"
|
||||
|
||||
high = build(0.7)
|
||||
assert high.action_tau == 0.7
|
||||
created = high._dispatch(Request("hmm"))
|
||||
assert created.kind == "create_category", "non_action 0.6 fails action_tau 0.7: author"
|
||||
|
||||
|
||||
|
||||
def test_dispatch_intent_tau_controls_reuse_vs_create(tmp_path):
|
||||
"""The leaf reuse-vs-create knob is navigation.intent_tau, separate from the
|
||||
|
||||
Reference in new issue
Block a user