diff --git a/AGENTS.md b/AGENTS.md index 5e7151d..d5e021a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,8 +40,9 @@ Guessing, inventing data, or shipping a toy is always the wrong answer. A local desktop CLI agent whose entire control flow is a single decision model (SemIf). Inputs are scored for urgency, queued, and dispatched through a skill tree. Nothing is gated out up front: every input is dispatched and inputs -that are not tasks fall through navigation into the closed `response` tree of -canned replies. Every SemIf decision is logged as a labeled training row; the +that are not requests fall through navigation into the closed `response` tree of +canned replies (a request no skill covers authors a skill instead — the +actionability guard). Every SemIf decision is logged as a labeled training row; the `dream` pass computes the prediction-vs-observation cost (cross-entropy / NLL + ECE) that later drives fine-tuning. See "Product premise" above for what the agent is for; this section is the machinery. @@ -90,8 +91,9 @@ scheduler.py no up-front gate: every input is dispatched (retry/repair_skill/ask_user/no_repair) surfaced to the user 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), - create_category + tree only), navigation = SemIf choices per level (logged; + the actionability guard arbitrates 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 @@ -302,24 +304,39 @@ 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`. Both taus are separate from the - top-level `tau`, so tuning reuse-vs-create 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 catchall** (Sep 2026): - the top-level `_contains_request` handle/ignore gate is gone. Every input is - scored and dispatched; inputs that are not tasks fall through navigation into - the closed `response` category, a hardcoded tree of canned replies - (`response.greeting`, `response.thanks`, `response.acknowledge`, - `response.farewell`, `response.affirm`, `response.unable`, and the catchall - `response.clarify` — "Could you try being more specific?"). `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 to assess. The leaf choice logs phase - `navigate:response` and traces `response_selected`. `response.reject` (a stub - that never ran) is gone. + `navigate:intent`) at `navigation.intent_tau`. The `response` catchall and + `create_category` share a third guard, 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. +- **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 + is not a request falls through navigation into the closed `response` category, + a hardcoded tree of canned replies (`response.greeting`, `response.thanks`, + `response.acknowledge`, `response.farewell`, `response.affirm`, and the + 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 + `response.unable` canned refusal is gone — an unsupported request authors a + skill, it is not refused). `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 + to assess. The leaf choice logs phase `navigate:response` and traces + `response_selected`. `response.reject` (a stub that never ran) is gone. - **Optional human approval on creation** (Oct 2026): `creation_approval` (top-level, default `false`) is a single boolean. When on, the single-slot `llm` draft worker blocks after it authors a proposal and before anything is diff --git a/README.md b/README.md index d353b42..fd574e7 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,12 @@ model entirely: - **Simulated Agile patterns.** A skill is a real integration into the active tool chain for end user satisfaction. It takes existing mail protocols, SimpleX, CalDAV/WebDAV, configured local CLIs, HTTP APIs and your supplied data to produce actions that best fit your query. In the absence of a an existing skill, the skill generation process is activated. Skill generation has four major phases - definition, refinement, coding, testing (unit and integration). Each step in this process has deterministic and probabilistic handling optimized to achieve the stated goal of the user in the context of the platform's core mission. - **Nothing is gated out up front.** Every input is dispatched and scored. - Inputs that are not tasks fall through navigation into the closed `response` + Inputs that are not requests fall through navigation into the closed `response` category — a hardcoded tree of canned replies (`greeting`, `thanks`, - `acknowledge`, `farewell`, `affirm`, `unable`, and the catchall `clarify`). + `acknowledge`, `farewell`, `affirm`, and the catchall `clarify`). A request no + skill covers is **not** a canned reply: the actionability guard + (`navigate:actionability`) sends it to skill authoring instead, so + `response` is reached only when the input asks for nothing. `response` never goes through codegen and its runs are never assessed (a canned line has no side effect to succeed or fail). It never offers generated text. By design, you will never be having a "conversation" with an LLM through this platform. - **Everything is a training row.** Every SemIf decision is logged as a labeled diff --git a/config.example.json b/config.example.json index 8308dc0..5898b04 100644 --- a/config.example.json +++ b/config.example.json @@ -4,9 +4,10 @@ "max_reentries": 3, "creation_approval": false, "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. 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. Both taus are separate from the top-level tau so tuning reuse-vs-create does not move run assessment/fidelity. The 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.", + "_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.", "intent_tau": 0.6, - "category_tau": 0.75 + "category_tau": 0.75, + "action_tau": 0.5 }, "queue": {"max_size": 100, "age_rate": 0.01}, "engine": { diff --git a/semif_agent/scheduler.py b/semif_agent/scheduler.py index 3bb9a79..0e32429 100644 --- a/semif_agent/scheduler.py +++ b/semif_agent/scheduler.py @@ -225,6 +225,7 @@ class Scheduler: nav_cfg = config.get("navigation", {}) or {} 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)) self.max_reentries = max_reentries self.codegen = codegen self.degeneration_check_factory = degeneration_check_factory @@ -461,6 +462,7 @@ class Scheduler: request, self.tree, category_tau=self.category_tau, + action_tau=self.action_tau, ) if isinstance(navigation, CreateCategory): return self._dispatch_create_category(request, weight) diff --git a/semif_agent/skills.py b/semif_agent/skills.py index c545ab9..d7beab2 100644 --- a/semif_agent/skills.py +++ b/semif_agent/skills.py @@ -521,11 +521,6 @@ _CANNED_RESPONSES = [ "The user is agreeing or confirming (yes, ok, sure, sounds good).", "Okay!", ), - ( - "unable", - "A request the agent understands but has no way to perform.", - "I'm not able to do that yet.", - ), ( "clarify", "The input is too vague to act on; ask the user to be more specific.", @@ -543,8 +538,8 @@ _RESPONSE_MESSAGES = {f"response.{name}": message for name, _, message in _CANNE # the fallback for a legacy entry with no description. CATEGORY_DESCRIPTIONS: dict[str, str] = { "response": ( - "Anything that is not a request to perform an action: greetings, thanks, " - "chit-chat, off-topic statements, and inputs the agent cannot act on." + "Anything that is not a request to perform an action or produce a result: " + "greetings, thanks, acknowledgements, chit-chat, and off-topic statements." ), "calendar": ( "Calendar and scheduling: reading or changing the user's calendar " @@ -691,6 +686,7 @@ def navigate( request: Request, tree: dict[str, list[Skill]], category_tau: float = 0.75, + action_tau: float = 0.5, ) -> Skill | CreateCategory | CreateSkill: """Descend the tree one SemIf choice per level. Every choice is logged. @@ -698,13 +694,21 @@ def navigate( 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 (or a `create_category` win) 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, and the confirm guard is - the create door (there is no threshold gate any more). A level with nothing - to choose from (an empty tree) short-circuits straight to create: SemIf - decisions need at least two options. + 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 `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. 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 @@ -738,31 +742,37 @@ 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 not confirm_category_fit( - engine, log, trace, request, category, descriptions.get(category, ""), - category_tau, - ): - trace.append( - "category_scope_rejected", - request.id, - category=category, - probs=top_result.probs, - ) - category = "create_category" - if category == "create_category": - trace.append( - "create_category", - request.id, - state=top.state, - question=top.question, - options=[o.id for o in top.options], - selected=top_result.selected, - probs=top_result.probs, - ) - return CreateCategory() + if category != "create_category" and category not in CANNED_CATEGORIES: + if not confirm_category_fit( + engine, log, trace, request, category, descriptions.get(category, ""), + category_tau, + ): + trace.append( + "category_scope_rejected", + request.id, + category=category, + 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" + ): + trace.append( + "create_category", + request.id, + state=top.state, + 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] - if category in CANNED_CATEGORIES: - return _navigate_canned(engine, log, trace, request, category, skills) if not skills: trace.append( "skill_needed", @@ -861,6 +871,63 @@ def confirm_category_fit( return fits +def confirm_non_action( + engine: SemIfEngine, + log: DecisionLog, + trace: TraceLog, + request: Request, + tau: float = 0.5, +) -> bool: + """Is this input non-request (chit-chat/statement) rather than a 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). + """ + 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)?" + ), + 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).", + ), + Option( + "non_action", + "It is not a request: a greeting, thanks, acknowledgement, small " + "talk, or a statement.", + ), + ], + ) + result = engine.call(decision) + log.append( + decision, + result, + extra={"phase": "navigate:actionability", "run_id": request.id}, + ) + non_action = result.prob("non_action") >= tau + trace.append( + "actionability", + request.id, + selected=result.selected, + probs=result.probs, + non_action=non_action, + ) + return non_action + + def confirm_skill_fit( engine: SemIfEngine, log: DecisionLog, diff --git a/tests/integration/test_pipeline.py b/tests/integration/test_pipeline.py index 2d67aa8..b8ccba6 100644 --- a/tests/integration/test_pipeline.py +++ b/tests/integration/test_pipeline.py @@ -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 diff --git a/tests/test_skills.py b/tests/test_skills.py index 3065d05..bf28982 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -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